Skip to content

Commit 1a848c8

Browse files
committed
test: add testing cases
1 parent af89746 commit 1a848c8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/compute/__tests__/variance.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Point } from '../../geometry';
12
import { variance } from '../variance';
23

34
test('1x1 RGB image', () => {
@@ -34,3 +35,25 @@ test('variance from points', () => {
3435

3536
expect(result).toStrictEqual([125]);
3637
});
38+
test('must throw if array is empty', () => {
39+
const image = testUtils.createRgbaImage([
40+
[1, 2, 2, 2],
41+
[1, 2, 3, 2],
42+
]);
43+
const points: Point[] = [];
44+
expect(() => {
45+
const result = image.median({ points });
46+
return result;
47+
}).toThrow('Array of coordinates is empty.');
48+
});
49+
test("must throw if point's coordinates are invalid", () => {
50+
const image = testUtils.createGreyImage([
51+
[1, 2, 2, 2],
52+
[1, 2, 3, 2],
53+
]);
54+
const points: Point[] = [{ column: 0, row: 2 }];
55+
expect(() => {
56+
const result = image.median({ points });
57+
return result;
58+
}).toThrow('Invalid coordinate: {column: 0, row: 2}');
59+
});

0 commit comments

Comments
 (0)