var assert = require("assert");
var pHash = require('../index');
require("should");

var examples = [
    { path: "./examples/a.jpg", hash: "2816561582497829945" },
    { path: "./examples/b.png", hash: "54086765383280" },
    { path: "./examples/c.png", hash: "15433968795834791622" },
    { path: "./examples/d.jpg", hash: "12040987020241900649" }
];
describe("pHash", function() {
    describe("sync test", function() {
		examples.forEach(function(i) {
			it(i.path, function() {
				var hash = pHash.imageHashSync(i.path);
                assert.equal(i.hash, hash);
			});
        });

        it("should fail", function() {
            var hashF = pHash.imageHashSync("./examples/f.png");
            hashF.should.equal('0');
        });
    });

    describe("async test", function() {
        var test = examples[0];
        examples.forEach(function(i) {
            it(i.path, function(done) {
                pHash.imageHash(i.path, function(err, hash) { 
                    if (err) { 
                        done(err); 
                    }

                    assert.equal(i.hash, hash);
                    done();
                });
            });
        });

        it("should fail", function(done) { 
            pHash.imageHash("./examples/f.png", function(err, hash) {
                assert(err);
                done();
            });
        });

        it("should throw", function() {
            assert.throws(function() {
                pHash.imageHash("not enough arguments");
            });
        })
    });

    describe("legacy test", function() {
        it("should match", function() {
            examples.forEach(function(i) {
                var hash = pHash.getImageHash(i.path);
                assert.equal(i.hash, hash);
            });
        });

        it("should fail", function() {
            var hashF = pHash.getImageHash("./examples/f.png");
            hashF.should.equal('0');
        });
    });

    describe('hammingDistance()', function() {
        it('should be done', function() {
            //var hammingAB = pHash.hammingDistance(examples[0].hash,examples[1].hash);
            var hammingAC = pHash.hammingDistance(examples[0].hash,examples[2].hash);
            var hammingBC = pHash.hammingDistance(examples[1].hash,examples[2].hash);
            var hammingAD = pHash.hammingDistance(examples[0].hash,examples[3].hash);
            //hammingAB.should.equal(0);
            hammingAC.should.equal(38);
            //hammingBC.should.equal(38);
            hammingAD.should.equal(12);
        }); 
    });
});

@@ -186,12 +186,12 @@
 les/
-b.pn
+a.jp
 g%22, 
@@ -201,22 +201,27 @@
 h: %22
-54086765383280
+2816561582497829945
 %22 %7D,
@@ -2063,18 +2063,16 @@
         
-//
 var hamm
@@ -2403,26 +2403,24 @@
             
-//
 hammingAB.sh
@@ -2490,10 +2490,8 @@
     
-//
 hamm

remove test on b.png, as it's different depending on machine