Skip to content

Commit

Permalink
test: add testing cases
Browse files Browse the repository at this point in the history
  • Loading branch information
EscapedGibbon committed Jun 12, 2024
1 parent af89746 commit 1a848c8
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/compute/__tests__/variance.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Point } from '../../geometry';
import { variance } from '../variance';

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

expect(result).toStrictEqual([125]);
});
test('must throw if array is empty', () => {
const image = testUtils.createRgbaImage([
[1, 2, 2, 2],
[1, 2, 3, 2],
]);
const points: Point[] = [];
expect(() => {
const result = image.median({ points });
return result;
}).toThrow('Array of coordinates is empty.');
});
test("must throw if point's coordinates are invalid", () => {
const image = testUtils.createGreyImage([
[1, 2, 2, 2],
[1, 2, 3, 2],
]);
const points: Point[] = [{ column: 0, row: 2 }];
expect(() => {
const result = image.median({ points });
return result;
}).toThrow('Invalid coordinate: {column: 0, row: 2}');
});

0 comments on commit 1a848c8

Please sign in to comment.