1- const colorDelta = require ( " ../colorDelta" ) ;
2- const { colorDeltaChannels } = require ( " ../colorDelta" ) ;
1+ const colorDelta = require ( ' ../colorDelta' ) ;
2+ const { colorDeltaChannels } = require ( ' ../colorDelta' ) ;
33
4- describe ( " colorDelta" , ( ) => {
5- it ( " produces the same results as colorDeltaChannels" , ( ) => {
4+ describe ( ' colorDelta' , ( ) => {
5+ it ( ' produces the same results as colorDeltaChannels' , ( ) => {
66 const pixels = [
77 [ 0 , 0 , 0 , 255 ] ,
88 [ 255 , 255 , 255 , 255 ] ,
@@ -23,54 +23,66 @@ describe("colorDelta", () => {
2323 pixels [ j ] [ 0 ] ,
2424 pixels [ j ] [ 1 ] ,
2525 pixels [ j ] [ 2 ] ,
26- pixels [ j ] [ 3 ]
27- )
26+ pixels [ j ] [ 3 ] ,
27+ ) ,
2828 ) ;
2929 }
3030 }
3131 } ) ;
3232} ) ;
3333
34- it ( " is large when comparing black and white" , ( ) => {
34+ it ( ' is large when comparing black and white' , ( ) => {
3535 expect ( colorDeltaChannels ( 0 , 0 , 0 , 255 , 255 , 255 , 255 , 255 ) ) . toBeGreaterThan (
36- 0.92
36+ 0.92 ,
3737 ) ;
3838} ) ;
3939
40- it ( " is small when comparing black and very dark grey" , ( ) => {
40+ it ( ' is small when comparing black and very dark grey' , ( ) => {
4141 expect ( colorDeltaChannels ( 0 , 0 , 0 , 255 , 10 , 10 , 10 , 255 ) ) . toBeLessThan ( 0.02 ) ;
4242} ) ;
4343
44- it ( " is medium when comparing black and medium grey" , ( ) => {
44+ it ( ' is medium when comparing black and medium grey' , ( ) => {
4545 const delta = colorDeltaChannels ( 0 , 0 , 0 , 255 , 127 , 127 , 127 , 255 ) ;
4646 expect ( delta ) . toBeGreaterThan ( 0.21 ) ;
4747 expect ( delta ) . toBeLessThan ( 0.24 ) ;
4848} ) ;
4949
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 ) ) ;
5252 expect ( delta ) . toBeGreaterThan ( 0.5 ) ;
5353 expect ( delta ) . toBeLessThan ( 0.51 ) ;
5454} ) ;
5555
56- it ( " is one when comparing filler pixel and white" , ( ) => {
56+ it ( ' is one when comparing filler pixel and white' , ( ) => {
5757 expect ( colorDeltaChannels ( 1 , 1 , 1 , 1 , 255 , 255 , 255 , 255 ) ) . toEqual ( 1 ) ;
5858} ) ;
5959
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 ) ;
6264} ) ;
6365
64- it ( " is large when comparing white and filler pixel" , ( ) => {
66+ it ( ' is large when comparing white and filler pixel' , ( ) => {
6567 expect ( colorDeltaChannels ( 255 , 255 , 255 , 255 , 1 , 1 , 1 , 1 ) ) . toBeGreaterThan (
66- 0.92
68+ 0.92 ,
6769 ) ;
6870} ) ;
6971
70- it ( " is one when comparing filler pixel and some other color" , ( ) => {
72+ it ( ' is one when comparing filler pixel and some other color' , ( ) => {
7173 expect ( colorDeltaChannels ( 1 , 1 , 1 , 1 , 33 , 33 , 33 , 10 ) ) . toEqual ( 1 ) ;
7274} ) ;
7375
74- it ( " is small when comparing transparent and similar color" , ( ) => {
76+ it ( ' is small when comparing transparent and similar color' , ( ) => {
7577 expect ( colorDeltaChannels ( 1 , 46 , 250 , 0 , 1 , 42 , 250 , 4 ) ) . toBeLessThan ( 0.05 ) ;
7678} ) ;
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