@@ -6,41 +6,51 @@ module.exports = function (t, Cstr, {
66 options,
77 inputPoints,
88 outputPoints,
9+ expectImg,
910 backend = backends . getDefault ( )
1011} ) {
1112 const inst = new Cstr ( options ) ;
1213 const img = backend . readImage ( input ) ;
1314 const res = inst . runOnce ( { img} ) ;
1415
15- return Promise . resolve ( ) . then ( ( ) => {
16- if ( ! output ) {
17- t . pass ( )
16+ return Promise . resolve ( )
17+ . then ( ( ) => {
18+ if ( ! output ) {
19+ t . pass ( )
20+ return Promise . resolve ( )
21+ }
22+ const expected = backend . readImage ( output ) ;
23+
24+ const data2 = backend . imageToBuffer ( expected ) ;
25+ t . true ( backend . imageToBuffer ( res . img ) . equals ( data2 ) ) ;
1826 return Promise . resolve ( )
19- }
20- const expected = backend . readImage ( output ) ;
21-
22- const data2 = backend . imageToBuffer ( expected ) ;
23- t . true ( backend . imageToBuffer ( res . img ) . equals ( data2 ) ) ;
24- return Promise . resolve ( )
25- } ) . then ( ( ) => {
26- if ( ! inputPoints && ! outputPoints ) {
27- t . pass ( )
28- return Promise . resolve ( )
29- }
30- const width = img . cols ;
31- const height = img . rows ;
32- const toSize = ( [ x , y ] ) => ( [ x * width , y * height ] )
33- const res = inst . runOnce ( { img, points : inputPoints . map ( toSize ) } ) ;
34-
35- const expected = outputPoints . map ( toSize ) . map ( a => backend . point ( ...a ) ) ;
36- const tolerance = 1e-6 * ( width + height ) / 2 ;
37- res . points . forEach ( ( p , index ) => {
38- //console.log({actual: p.x, expected: expected[index].x, res: Math.abs(p.x - expected[index].x) < tolerance})
39- t . true ( Math . abs ( p . x - expected [ index ] . x ) < tolerance )
40- t . true ( Math . abs ( p . y - expected [ index ] . y ) < tolerance )
41- } ) ;
42-
43- } )
27+ } )
28+ . then ( ( ) => {
29+ if ( ! expectImg ) {
30+ t . pass ( )
31+ return Promise . resolve ( )
32+ }
33+ expectImg ( t , img , res . img , backend )
34+ } )
35+ . then ( ( ) => {
36+ if ( ! inputPoints && ! outputPoints ) {
37+ t . pass ( )
38+ return Promise . resolve ( )
39+ }
40+ const width = img . cols ;
41+ const height = img . rows ;
42+ const toSize = ( [ x , y ] ) => ( [ x * width , y * height ] )
43+ const res = inst . runOnce ( { img, points : inputPoints . map ( toSize ) } ) ;
44+
45+ const expected = outputPoints . map ( toSize ) . map ( a => backend . point ( ...a ) ) ;
46+ const tolerance = 1e-6 * ( width + height ) / 2 ;
47+ res . points . forEach ( ( p , index ) => {
48+ //console.log({actual: p.x, expected: expected[index].x, res: Math.abs(p.x - expected[index].x) < tolerance})
49+ t . true ( Math . abs ( p . x - expected [ index ] . x ) < tolerance )
50+ t . true ( Math . abs ( p . y - expected [ index ] . y ) < tolerance )
51+ } ) ;
52+
53+ } )
4454
4555
4656} ;
0 commit comments