@@ -10,38 +10,42 @@ describe("Template-matching finder", () => {
10
10
// GIVEN
11
11
const imageLoader = new ImageReader ( ) ;
12
12
const SUT = new TemplateMatchingFinder ( ) ;
13
- const imagePath = path . resolve ( __dirname , "./__mocks__/mouse.png" ) ;
14
- const needle = await imageLoader . load ( imagePath ) ;
13
+ const haystackPath = path . resolve ( __dirname , "./__mocks__/mouse.png" ) ;
14
+ const needlePath = path . resolve ( __dirname , "./__mocks__/needle.png" ) ;
15
+ const haystack = await imageLoader . load ( haystackPath ) ;
16
+ const needle = await imageLoader . load ( needlePath ) ;
15
17
const minConfidence = 0.99 ;
16
- const searchRegion = new Region ( 0 , 0 , needle . width , needle . height ) ;
17
- const haystack = new Image ( needle . width , needle . height , needle . data , 3 ) ;
18
- const matchRequest = new MatchRequest ( haystack , imagePath , searchRegion , minConfidence ) ;
18
+ const searchRegion = new Region ( 0 , 0 , haystack . width , haystack . height ) ;
19
+ const matchRequest = new MatchRequest ( haystack , needlePath , searchRegion , minConfidence ) ;
20
+ const expectedResult = new Region ( 16 , 31 , needle . width , needle . height ) ;
19
21
20
22
// WHEN
21
23
const result = await SUT . findMatch ( matchRequest ) ;
22
24
23
25
// THEN
24
26
expect ( result . confidence ) . toBeGreaterThanOrEqual ( minConfidence ) ;
25
- expect ( result . location ) . toEqual ( searchRegion ) ;
27
+ expect ( result . location ) . toEqual ( expectedResult ) ;
26
28
} ) ;
27
29
28
30
it ( "findMatch should return a match within a search region when present in image" , async ( ) => {
29
31
// GIVEN
30
32
const imageLoader = new ImageReader ( ) ;
31
33
const SUT = new TemplateMatchingFinder ( ) ;
32
- const imagePath = path . resolve ( __dirname , "./__mocks__/mouse.png" ) ;
33
- const needle = await imageLoader . load ( imagePath ) ;
34
+ const haystackPath = path . resolve ( __dirname , "./__mocks__/mouse.png" ) ;
35
+ const needlePath = path . resolve ( __dirname , "./__mocks__/needle.png" ) ;
36
+ const haystack = await imageLoader . load ( haystackPath ) ;
37
+ const needle = await imageLoader . load ( needlePath ) ;
34
38
const minConfidence = 0.99 ;
35
- const searchRegion = new Region ( 10 , 20 , 100 , 100 ) ;
36
- const haystack = new Image ( needle . width , needle . height , needle . data , 3 ) ;
37
- const matchRequest = new MatchRequest ( haystack , imagePath , searchRegion , minConfidence ) ;
39
+ const searchRegion = new Region ( 10 , 20 , 140 , 100 ) ;
40
+ const matchRequest = new MatchRequest ( haystack , needlePath , searchRegion , minConfidence ) ;
41
+ const expectedResult = new Region ( 6 , 11 , needle . width , needle . height ) ;
38
42
39
43
// WHEN
40
44
const result = await SUT . findMatch ( matchRequest ) ;
41
45
42
46
// THEN
43
47
expect ( result . confidence ) . toBeGreaterThanOrEqual ( minConfidence ) ;
44
- expect ( result . location ) . toEqual ( searchRegion ) ;
48
+ expect ( result . location ) . toEqual ( expectedResult ) ;
45
49
} ) ;
46
50
47
51
it ( "findMatch should throw on invalid image paths" , async ( ) => {
0 commit comments