-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.js
74 lines (56 loc) · 1.92 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict'
const { test } = require('ava')
const path = require('path')
const pHashGIF = require('.')
const fixturesPath = path.join(__dirname, `media`)
const EPSILON = 10
const fixtures = [
'bubbles',
'ippo',
'kitten'
]
fixtures.forEach((fixture) => {
const input = path.join(fixturesPath, fixture + '.gif')
const input200 = path.join(fixturesPath, fixture + '-200.gif')
const inputGifski = path.join(fixturesPath, fixture + '-gifski.gif')
test(`${fixture} compute`, async (t) => {
const hash = await pHashGIF.compute(input)
t.truthy(Array.isArray(hash))
t.is(hash.length, 42 * 3)
hash.forEach((item) => {
t.is(typeof item, 'number')
})
})
test(`${fixture} => downsize`, async (t) => {
const hash1 = await pHashGIF.compute(input)
const hash2 = await pHashGIF.compute(input200)
const value = await pHashGIF.compare(hash1, hash2)
t.truthy(value < EPSILON)
})
test(`${fixture} => gifski`, async (t) => {
const hash1 = await pHashGIF.compute(input)
const hash2 = await pHashGIF.compute(inputGifski)
const value = await pHashGIF.compare(hash1, hash2)
t.truthy(value < EPSILON)
})
test(`${fixture} => downsize => gifski`, async (t) => {
const hash1 = await pHashGIF.compute(input200)
const hash2 = await pHashGIF.compute(inputGifski)
const value = await pHashGIF.compare(hash1, hash2)
t.truthy(value < EPSILON)
})
})
for (let i = 0; i < fixtures.length; ++i) {
const fixtureI = fixtures[i]
const inputI = path.join(fixturesPath, fixtureI + '.gif')
for (let j = i + 1; j < fixtures.length; ++j) {
const fixtureJ = fixtures[j]
const inputJ = path.join(fixturesPath, fixtureJ + '.gif')
test(`${fixtureI} != ${fixtureJ}`, async (t) => {
const hash1 = await pHashGIF.compute(inputI)
const hash2 = await pHashGIF.compute(inputJ)
const value = await pHashGIF.compare(hash1, hash2)
t.truthy(value > 0.15)
})
}
}