|
1 |
| -const colorDelta = require('../colorDelta'); |
| 1 | +const colorDelta = require("../colorDelta"); |
| 2 | +const { colorDeltaChannels } = require("../colorDelta"); |
2 | 3 |
|
3 |
| -it('is large when comparing black and white', () => { |
4 |
| - expect(colorDelta([0, 0, 0, 255], [255, 255, 255, 255])).toBeGreaterThan( |
5 |
| - 0.92, |
| 4 | +describe("colorDelta", () => { |
| 5 | + it("produces the same results as colorDeltaChannels", () => { |
| 6 | + const pixels = [ |
| 7 | + [0, 0, 0, 255], |
| 8 | + [255, 255, 255, 255], |
| 9 | + [0, 0, 0, 0], |
| 10 | + [1, 1, 1, 1], |
| 11 | + [1, 46, 250, 0], |
| 12 | + [1, 42, 250, 4], |
| 13 | + ]; |
| 14 | + |
| 15 | + for (let i = 0; i < pixels.length; i++) { |
| 16 | + for (let j = 0; j < pixels.length; j++) { |
| 17 | + expect(colorDelta(pixels[i], pixels[j])).toEqual( |
| 18 | + colorDeltaChannels( |
| 19 | + pixels[i][0], |
| 20 | + pixels[i][1], |
| 21 | + pixels[i][2], |
| 22 | + pixels[i][3], |
| 23 | + pixels[j][0], |
| 24 | + pixels[j][1], |
| 25 | + pixels[j][2], |
| 26 | + pixels[j][3] |
| 27 | + ) |
| 28 | + ); |
| 29 | + } |
| 30 | + } |
| 31 | + }); |
| 32 | +}); |
| 33 | + |
| 34 | +it("is large when comparing black and white", () => { |
| 35 | + expect(colorDeltaChannels(0, 0, 0, 255, 255, 255, 255, 255)).toBeGreaterThan( |
| 36 | + 0.92 |
6 | 37 | );
|
7 | 38 | });
|
8 | 39 |
|
9 |
| -it('is small when comparing black and very dark grey', () => { |
10 |
| - expect(colorDelta([0, 0, 0, 255], [10, 10, 10, 255])).toBeLessThan(0.02); |
| 40 | +it("is small when comparing black and very dark grey", () => { |
| 41 | + expect(colorDeltaChannels(0, 0, 0, 255, 10, 10, 10, 255)).toBeLessThan(0.02); |
11 | 42 | });
|
12 | 43 |
|
13 |
| -it('is medium when comparing black and medium grey', () => { |
14 |
| - const delta = colorDelta([0, 0, 0, 255], [127, 127, 127, 255]); |
| 44 | +it("is medium when comparing black and medium grey", () => { |
| 45 | + const delta = colorDeltaChannels(0, 0, 0, 255, 127, 127, 127, 255); |
15 | 46 | expect(delta).toBeGreaterThan(0.21);
|
16 | 47 | expect(delta).toBeLessThan(0.24);
|
17 | 48 | });
|
18 | 49 |
|
19 |
| -it('is medium when comparing red and blue', () => { |
20 |
| - const delta = colorDelta([255, 0, 0, 255], [0, 0, 255, 255]); |
| 50 | +it("is medium when comparing red and blue", () => { |
| 51 | + const delta = colorDeltaChannels(255, 0, 0, 255, 0, 0, 255, 255); |
21 | 52 | expect(delta).toBeGreaterThan(0.5);
|
22 | 53 | expect(delta).toBeLessThan(0.51);
|
23 | 54 | });
|
24 | 55 |
|
25 |
| -it('is one when comparing filler pixel and white', () => { |
26 |
| - expect(colorDelta([1, 1, 1, 1], [255, 255, 255, 255])).toEqual(1); |
| 56 | +it("is one when comparing filler pixel and white", () => { |
| 57 | + expect(colorDeltaChannels(1, 1, 1, 1, 255, 255, 255, 255)).toEqual(1); |
27 | 58 | });
|
28 | 59 |
|
29 |
| -it('is large when comparing transparent and black', () => { |
30 |
| - expect(colorDelta([0, 0, 0, 0], [0, 0, 0, 255])).toBeGreaterThan(0.92); |
| 60 | +it("is large when comparing transparent and black", () => { |
| 61 | + expect(colorDeltaChannels(0, 0, 0, 0, 0, 0, 0, 255)).toBeGreaterThan(0.92); |
31 | 62 | });
|
32 | 63 |
|
33 |
| -it('is large when comparing white and filler pixel', () => { |
34 |
| - expect(colorDelta([255, 255, 255, 255], [1, 1, 1, 1])).toBeGreaterThan(0.92); |
| 64 | +it("is large when comparing white and filler pixel", () => { |
| 65 | + expect(colorDeltaChannels(255, 255, 255, 255, 1, 1, 1, 1)).toBeGreaterThan( |
| 66 | + 0.92 |
| 67 | + ); |
35 | 68 | });
|
36 | 69 |
|
37 |
| -it('is one when comparing filler pixel and some other color', () => { |
38 |
| - expect(colorDelta([1, 1, 1, 1], [33, 33, 33, 10])).toEqual(1); |
| 70 | +it("is one when comparing filler pixel and some other color", () => { |
| 71 | + expect(colorDeltaChannels(1, 1, 1, 1, 33, 33, 33, 10)).toEqual(1); |
39 | 72 | });
|
40 | 73 |
|
41 |
| -it('is small when comparing transparent and similar color', () => { |
42 |
| - expect(colorDelta([1, 46, 250, 0], [1, 42, 250, 4])).toBeLessThan(0.05); |
| 74 | +it("is small when comparing transparent and similar color", () => { |
| 75 | + expect(colorDeltaChannels(1, 46, 250, 0, 1, 42, 250, 4)).toBeLessThan(0.05); |
43 | 76 | });
|
0 commit comments