1
- const colorDelta = require ( " ../colorDelta" ) ;
2
- const { colorDeltaChannels } = require ( " ../colorDelta" ) ;
1
+ const colorDelta = require ( ' ../colorDelta' ) ;
2
+ const { colorDeltaChannels } = require ( ' ../colorDelta' ) ;
3
3
4
- describe ( " colorDelta" , ( ) => {
5
- it ( " produces the same results as colorDeltaChannels" , ( ) => {
4
+ describe ( ' colorDelta' , ( ) => {
5
+ it ( ' produces the same results as colorDeltaChannels' , ( ) => {
6
6
const pixels = [
7
7
[ 0 , 0 , 0 , 255 ] ,
8
8
[ 255 , 255 , 255 , 255 ] ,
@@ -23,54 +23,66 @@ describe("colorDelta", () => {
23
23
pixels [ j ] [ 0 ] ,
24
24
pixels [ j ] [ 1 ] ,
25
25
pixels [ j ] [ 2 ] ,
26
- pixels [ j ] [ 3 ]
27
- )
26
+ pixels [ j ] [ 3 ] ,
27
+ ) ,
28
28
) ;
29
29
}
30
30
}
31
31
} ) ;
32
32
} ) ;
33
33
34
- it ( " is large when comparing black and white" , ( ) => {
34
+ it ( ' is large when comparing black and white' , ( ) => {
35
35
expect ( colorDeltaChannels ( 0 , 0 , 0 , 255 , 255 , 255 , 255 , 255 ) ) . toBeGreaterThan (
36
- 0.92
36
+ 0.92 ,
37
37
) ;
38
38
} ) ;
39
39
40
- it ( " is small when comparing black and very dark grey" , ( ) => {
40
+ it ( ' is small when comparing black and very dark grey' , ( ) => {
41
41
expect ( colorDeltaChannels ( 0 , 0 , 0 , 255 , 10 , 10 , 10 , 255 ) ) . toBeLessThan ( 0.02 ) ;
42
42
} ) ;
43
43
44
- it ( " is medium when comparing black and medium grey" , ( ) => {
44
+ it ( ' is medium when comparing black and medium grey' , ( ) => {
45
45
const delta = colorDeltaChannels ( 0 , 0 , 0 , 255 , 127 , 127 , 127 , 255 ) ;
46
46
expect ( delta ) . toBeGreaterThan ( 0.21 ) ;
47
47
expect ( delta ) . toBeLessThan ( 0.24 ) ;
48
48
} ) ;
49
49
50
- it ( " is medium when comparing red and blue" , ( ) => {
51
- const delta = colorDeltaChannels ( 255 , 0 , 0 , 255 , 0 , 0 , 255 , 255 ) ;
50
+ it ( ' is medium when comparing red and blue' , ( ) => {
51
+ const delta = Math . abs ( colorDeltaChannels ( 255 , 0 , 0 , 255 , 0 , 0 , 255 , 255 ) ) ;
52
52
expect ( delta ) . toBeGreaterThan ( 0.5 ) ;
53
53
expect ( delta ) . toBeLessThan ( 0.51 ) ;
54
54
} ) ;
55
55
56
- it ( " is one when comparing filler pixel and white" , ( ) => {
56
+ it ( ' is one when comparing filler pixel and white' , ( ) => {
57
57
expect ( colorDeltaChannels ( 1 , 1 , 1 , 1 , 255 , 255 , 255 , 255 ) ) . toEqual ( 1 ) ;
58
58
} ) ;
59
59
60
- it ( "is large when comparing transparent and black" , ( ) => {
61
- expect ( colorDeltaChannels ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255 ) ) . toBeGreaterThan ( 0.92 ) ;
60
+ it ( 'is large when comparing transparent and black' , ( ) => {
61
+ expect (
62
+ Math . abs ( colorDeltaChannels ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255 ) ) ,
63
+ ) . toBeGreaterThan ( 0.92 ) ;
62
64
} ) ;
63
65
64
- it ( " is large when comparing white and filler pixel" , ( ) => {
66
+ it ( ' is large when comparing white and filler pixel' , ( ) => {
65
67
expect ( colorDeltaChannels ( 255 , 255 , 255 , 255 , 1 , 1 , 1 , 1 ) ) . toBeGreaterThan (
66
- 0.92
68
+ 0.92 ,
67
69
) ;
68
70
} ) ;
69
71
70
- it ( " is one when comparing filler pixel and some other color" , ( ) => {
72
+ it ( ' is one when comparing filler pixel and some other color' , ( ) => {
71
73
expect ( colorDeltaChannels ( 1 , 1 , 1 , 1 , 33 , 33 , 33 , 10 ) ) . toEqual ( 1 ) ;
72
74
} ) ;
73
75
74
- it ( " is small when comparing transparent and similar color" , ( ) => {
76
+ it ( ' is small when comparing transparent and similar color' , ( ) => {
75
77
expect ( colorDeltaChannels ( 1 , 46 , 250 , 0 , 1 , 42 , 250 , 4 ) ) . toBeLessThan ( 0.05 ) ;
76
78
} ) ;
79
+
80
+ it ( 'is negative when comparing white and black' , ( ) => {
81
+ expect ( colorDeltaChannels ( 255 , 255 , 255 , 255 , 0 , 0 , 0 , 255 ) ) . toBeLessThan ( 0 ) ;
82
+ } ) ;
83
+
84
+ it ( 'is positive when comparing black and white' , ( ) => {
85
+ expect ( colorDeltaChannels ( 0 , 0 , 0 , 255 , 255 , 255 , 255 , 255 ) ) . toBeGreaterThan (
86
+ 0 ,
87
+ ) ;
88
+ } ) ;
0 commit comments