Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

Commit 9e09e6b

Browse files
committed
refactor: move tests to better location
1 parent bbfa94d commit 9e09e6b

5 files changed

+76
-111
lines changed
Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,7 @@
11
import { ImageColorModel, Image, ImageCoordinates } from '../../../Image';
22
import { getOrientedFastKeypoints } from '../../keypoints/getOrientedFastKeypoints';
3-
import { getHammingDistance } from '../../matching/getHammingDistance';
4-
import { drawKeypoints } from '../../visualize/drawKeypoints';
53
import { getBriefDescriptors } from '../getBriefDescriptors';
64

7-
test('alphabet image, maxNbFeatures = 10', () => {
8-
const image = testUtils.load('various/alphabet.jpg');
9-
const grey = image.convertColor(ImageColorModel.GREY);
10-
11-
const keypoints = getOrientedFastKeypoints(grey, { maxNbFeatures: 10 });
12-
expect(keypoints).toHaveLength(10);
13-
14-
let imageWithKeypoints = drawKeypoints(image, keypoints);
15-
16-
expect(imageWithKeypoints).toMatchImageSnapshot();
17-
18-
const result = getBriefDescriptors(grey, keypoints);
19-
20-
expect(result.descriptors).toMatchSnapshot();
21-
expect(result.descriptors.length).toBe(keypoints.length);
22-
});
23-
24-
test('should work with small patch size', () => {
25-
const image = testUtils.load('various/alphabet.jpg');
26-
const grey = image.convertColor(ImageColorModel.GREY);
27-
28-
const keypoints = getOrientedFastKeypoints(grey, { maxNbFeatures: 10 });
29-
expect(keypoints).toHaveLength(10);
30-
31-
const keypoint = keypoints.slice(0, 1);
32-
33-
let imageWithKeypoints = drawKeypoints(image, keypoints);
34-
expect(imageWithKeypoints).toMatchImageSnapshot();
35-
36-
const descriptor = getBriefDescriptors(grey, keypoint, {
37-
patchSize: 5,
38-
}).descriptors;
39-
40-
expect(descriptor).toMatchSnapshot();
41-
});
42-
435
test('count occurences of 1 and 0 with default options', () => {
446
const image = testUtils.load('various/alphabet.jpg');
457
const grey = image.convertColor(ImageColorModel.GREY);
@@ -112,76 +74,3 @@ test('verify descriptor is correct (descriptorLength = 10)', () => {
11274
new Uint8Array([0, 0, 0, 0, 0, 0, 1, 0, 1, 0]),
11375
);
11476
});
115-
116-
test.each([
117-
{
118-
message: 'windowSize = 7',
119-
windowSize: 7,
120-
expected: [
121-
{ srcIndex: 0, dstIndex: 0, distance: 15 },
122-
{ srcIndex: 0, dstIndex: 1, distance: 73 },
123-
{ srcIndex: 1, dstIndex: 0, distance: 77 },
124-
{ srcIndex: 1, dstIndex: 1, distance: 11 },
125-
],
126-
},
127-
{
128-
message: 'windowSize = 15',
129-
windowSize: 15,
130-
expected: [
131-
{ srcIndex: 0, dstIndex: 0, distance: 13 },
132-
{ srcIndex: 0, dstIndex: 1, distance: 11 },
133-
{ srcIndex: 1, dstIndex: 0, distance: 23 },
134-
{ srcIndex: 1, dstIndex: 1, distance: 7 },
135-
],
136-
},
137-
{
138-
message: 'windowSize = 31',
139-
windowSize: 31,
140-
expected: [
141-
{ srcIndex: 0, dstIndex: 0, distance: 11 },
142-
{ srcIndex: 0, dstIndex: 1, distance: 14 },
143-
{ srcIndex: 1, dstIndex: 0, distance: 20 },
144-
{ srcIndex: 1, dstIndex: 1, distance: 9 },
145-
],
146-
},
147-
])('check distance for each keypoint pair ($message)', (data) => {
148-
const source = testUtils
149-
.load('featureMatching/polygons/scaleneTriangle.png')
150-
.convertColor(ImageColorModel.GREY);
151-
const sourceKeypoints = getOrientedFastKeypoints(source, {
152-
windowSize: data.windowSize,
153-
});
154-
const sourceBrief = getBriefDescriptors(source, sourceKeypoints);
155-
const destination = testUtils
156-
.load('featureMatching/polygons/scaleneTriangle10.png')
157-
.convertColor(ImageColorModel.GREY);
158-
const destinationKeypoints = getOrientedFastKeypoints(destination, {
159-
windowSize: data.windowSize,
160-
});
161-
const destinationBrief = getBriefDescriptors(
162-
destination,
163-
destinationKeypoints,
164-
);
165-
let result = [];
166-
167-
for (
168-
let srcIndex = 0;
169-
srcIndex < sourceBrief.descriptors.length;
170-
srcIndex++
171-
) {
172-
for (
173-
let dstIndex = 0;
174-
dstIndex < destinationBrief.descriptors.length;
175-
dstIndex++
176-
) {
177-
const distance = getHammingDistance(
178-
sourceBrief.descriptors[srcIndex],
179-
destinationBrief.descriptors[dstIndex],
180-
);
181-
result.push({ srcIndex, dstIndex, distance });
182-
}
183-
}
184-
185-
// 0-0 and 1-1 are the correct matches
186-
expect(result).toStrictEqual(data.expected);
187-
});
Loading
Loading

src/featureMatching/matching/__tests__/getHammingDistance.test.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { ImageColorModel } from '../../../Image';
2+
import { getBriefDescriptors } from '../../descriptors/getBriefDescriptors';
3+
import { getOrientedFastKeypoints } from '../../keypoints/getOrientedFastKeypoints';
14
import { getHammingDistance } from '../getHammingDistance';
25

36
test('distance should be 0', () => {
@@ -18,3 +21,76 @@ test('two random arrays', () => {
1821

1922
expect(getHammingDistance(a, b)).toBe(2);
2023
});
24+
25+
test.each([
26+
{
27+
message: 'windowSize = 7',
28+
windowSize: 7,
29+
expected: [
30+
{ srcIndex: 0, dstIndex: 0, distance: 15 },
31+
{ srcIndex: 0, dstIndex: 1, distance: 73 },
32+
{ srcIndex: 1, dstIndex: 0, distance: 77 },
33+
{ srcIndex: 1, dstIndex: 1, distance: 11 },
34+
],
35+
},
36+
{
37+
message: 'windowSize = 15',
38+
windowSize: 15,
39+
expected: [
40+
{ srcIndex: 0, dstIndex: 0, distance: 13 },
41+
{ srcIndex: 0, dstIndex: 1, distance: 11 },
42+
{ srcIndex: 1, dstIndex: 0, distance: 23 },
43+
{ srcIndex: 1, dstIndex: 1, distance: 7 },
44+
],
45+
},
46+
{
47+
message: 'windowSize = 31',
48+
windowSize: 31,
49+
expected: [
50+
{ srcIndex: 0, dstIndex: 0, distance: 11 },
51+
{ srcIndex: 0, dstIndex: 1, distance: 14 },
52+
{ srcIndex: 1, dstIndex: 0, distance: 20 },
53+
{ srcIndex: 1, dstIndex: 1, distance: 9 },
54+
],
55+
},
56+
])('check distance for each keypoint pair ($message)', (data) => {
57+
const source = testUtils
58+
.load('featureMatching/polygons/scaleneTriangle.png')
59+
.convertColor(ImageColorModel.GREY);
60+
const sourceKeypoints = getOrientedFastKeypoints(source, {
61+
windowSize: data.windowSize,
62+
});
63+
const sourceBrief = getBriefDescriptors(source, sourceKeypoints);
64+
const destination = testUtils
65+
.load('featureMatching/polygons/scaleneTriangle10.png')
66+
.convertColor(ImageColorModel.GREY);
67+
const destinationKeypoints = getOrientedFastKeypoints(destination, {
68+
windowSize: data.windowSize,
69+
});
70+
const destinationBrief = getBriefDescriptors(
71+
destination,
72+
destinationKeypoints,
73+
);
74+
let result = [];
75+
76+
for (
77+
let srcIndex = 0;
78+
srcIndex < sourceBrief.descriptors.length;
79+
srcIndex++
80+
) {
81+
for (
82+
let dstIndex = 0;
83+
dstIndex < destinationBrief.descriptors.length;
84+
dstIndex++
85+
) {
86+
const distance = getHammingDistance(
87+
sourceBrief.descriptors[srcIndex],
88+
destinationBrief.descriptors[dstIndex],
89+
);
90+
result.push({ srcIndex, dstIndex, distance });
91+
}
92+
}
93+
94+
// 0-0 and 1-1 are the correct matches
95+
expect(result).toStrictEqual(data.expected);
96+
});

0 commit comments

Comments
 (0)