Skip to content

Commit

Permalink
test: Improving tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor-pelykh committed Feb 3, 2024
1 parent 195f331 commit 8e8ca90
Show file tree
Hide file tree
Showing 21 changed files with 312 additions and 312 deletions.
2 changes: 1 addition & 1 deletion test/_utils/image-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export abstract class ImageTestUtils {
return;
}

expect(ArrayUtils.equals(imageData, image2Data)).toBe(true);
expect(ArrayUtils.equals(imageData, image2Data)).toBeTruthy();
}

public static dumpData(data: Uint8Array, fileName: string): void {
Expand Down
8 changes: 4 additions & 4 deletions test/color/color.uint8.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ describe('Color', () => {
test('ColorUint8.equality', () => {
const ca = ColorUint8.rgba(5, 10, 123, 40);
const cb = ColorUint8.rgba(3, 10, 123, 40);
expect(ca.equals(cb)).toBe(false);
expect(!ca.equals(cb)).toBe(true);
expect(ca.equals(cb)).toBeFalsy();
expect(!ca.equals(cb)).toBeTruthy();

cb.r = 5;
expect(ca.equals(cb)).toBe(true);
expect(!ca.equals(cb)).toBe(false);
expect(ca.equals(cb)).toBeTruthy();
expect(!ca.equals(cb)).toBeFalsy();
});
});
12 changes: 6 additions & 6 deletions test/exif/exif.base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ describe('Exif', () => {
const val2 = exif2.imageIfd.getValue(i);
const eq = val2!.equals(val!);
if (i === 7) {
expect(eq).toBe(false);
expect(eq).toBeFalsy();
} else {
expect(eq).toBe(true);
expect(eq).toBeTruthy();
}
}

Expand All @@ -92,9 +92,9 @@ describe('Exif', () => {
const val2 = ifd2.getValue(i);
const eq = val2!.equals(val!);
if (i === 7) {
expect(eq).toBe(false);
expect(eq).toBeFalsy();
} else {
expect(eq).toBe(true);
expect(eq).toBeTruthy();
}
}

Expand All @@ -104,9 +104,9 @@ describe('Exif', () => {
const val2 = exif2.thumbnailIfd.getValue(i);
const eq = val2!.equals(val!);
if (i === 7) {
expect(eq).toBe(false);
expect(eq).toBeFalsy();
} else {
expect(eq).toBe(true);
expect(eq).toBeTruthy();
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/format/format.gif.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('Format: GIF', () => {
const p1 = g1.frames[f.frameIndex].getPixel(0, 0);
const p2 = f.getPixel(0, 0);
const equals = p1.equals(p2);
expect(equals).toBe(true);
expect(equals).toBeTruthy();

const g3 = encodeGif({
image: f,
Expand Down
2 changes: 1 addition & 1 deletion test/format/format.png.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ describe('Format: PNG', () => {
expect(image.height).toBe(186);
expect(image.numChannels).toBe(3);
expect(image.format).toBe(Format.uint8);
expect(image.hasPalette).toBe(true);
expect(image.hasPalette).toBeTruthy();

const png = encodePng({
image: image,
Expand Down
2 changes: 1 addition & 1 deletion test/format/format.tiff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('Format: TIFF', () => {
expect(i3p2).toBeDefined();
expect(i3p2.width).toBe(i3p.width);
expect(i3p2.height).toBe(i3p.height);
expect(i3p2.hasPalette).toBe(true);
expect(i3p2.hasPalette).toBeTruthy();

for (const p of i3p2) {
expect(p.r).toBe(p.x);
Expand Down
16 changes: 8 additions & 8 deletions test/format/format.webp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ describe('Format: WEBP', () => {

const test = webpTests.get(file.fileName);
if (test !== undefined) {
expect(data.format).toEqual(test.format);
expect(data.width).toEqual(test.width);
expect(data.height).toEqual(test.height);
expect(data.hasAlpha).toEqual(test.hasAlpha);
expect(data.hasAnimation).toEqual(test.hasAnimation);
expect(data.format).toBe(test.format);
expect(data.width).toBe(test.width);
expect(data.height).toBe(test.height);
expect(data.hasAlpha).toBe(test.hasAlpha);
expect(data.hasAnimation).toBe(test.hasAnimation);
if (data.hasAnimation) {
expect(webpDecoder.numFrames).toEqual(test.numFrames);
expect(webpDecoder.numFrames).toBe(test.numFrames);
}
}
});
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('Format: WEBP', () => {
return;
}

expect(anim.numFrames).toEqual(20);
expect(anim.numFrames).toBe(20);

for (let i = 0; i < anim.numFrames; ++i) {
const image = anim.getFrame(i);
Expand All @@ -213,7 +213,7 @@ describe('Format: WEBP', () => {
output
);
}
expect(anim.getFrame(2).getPixel(0, 0).equals([0, 0, 0, 0])).toEqual(true);
expect(anim.getFrame(2).getPixel(0, 0).equals([0, 0, 0, 0])).toBeTruthy();
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/image/image.base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import { TestUtils } from '../_utils/test-utils';
describe('Image', () => {
test('empty', () => {
const i0 = new MemoryImage();
expect(i0.isValid).toBe(false);
expect(i0.isValid).toBeFalsy();

const i1 = new MemoryImage();
expect(i1.isValid).toBe(false);
expect(i1.isValid).toBeFalsy();
});

test('rowStride', () => {
Expand Down
32 changes: 16 additions & 16 deletions test/image/image.float16.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ describe('Image', () => {
i1.setPixelRgb(0, 1, -75, 0, 0);
i1.setPixelRgb(1, 1, -115, 0, 0);

expect(i1.getPixel(0, 0).equals([32])).toBe(true);
expect(i1.getPixel(1, 0).equals([64])).toBe(true);
expect(i1.getPixel(0, 1).equals([-75])).toBe(true);
expect(i1.getPixel(1, 1).equals([-115])).toBe(true);
expect(i1.getPixel(0, 0).equals([32])).toBeTruthy();
expect(i1.getPixel(1, 0).equals([64])).toBeTruthy();
expect(i1.getPixel(0, 1).equals([-75])).toBeTruthy();
expect(i1.getPixel(1, 1).equals([-115])).toBeTruthy();

const i2 = new MemoryImage({
width: 2,
Expand All @@ -41,10 +41,10 @@ describe('Image', () => {
i2.setPixelRgb(0, 1, -58, 52, 0);
i2.setPixelRgb(1, 1, 110, 84, 0);

expect(i2.getPixel(0, 0).equals([32, 64])).toBe(true);
expect(i2.getPixel(1, 0).equals([64, 32])).toBe(true);
expect(i2.getPixel(0, 1).equals([-58, 52])).toBe(true);
expect(i2.getPixel(1, 1).equals([110, 84])).toBe(true);
expect(i2.getPixel(0, 0).equals([32, 64])).toBeTruthy();
expect(i2.getPixel(1, 0).equals([64, 32])).toBeTruthy();
expect(i2.getPixel(0, 1).equals([-58, 52])).toBeTruthy();
expect(i2.getPixel(1, 1).equals([110, 84])).toBeTruthy();

const i3 = new MemoryImage({
width: 2,
Expand All @@ -61,10 +61,10 @@ describe('Image', () => {
i3.setPixelRgb(0, 1, -58, 52, 5);
i3.setPixelRgb(1, 1, 110, 84, 94);

expect(i3.getPixel(0, 0).equals([32, 64, 86])).toBe(true);
expect(i3.getPixel(1, 0).equals([64, 32, 14])).toBe(true);
expect(i3.getPixel(0, 1).equals([-58, 52, 5])).toBe(true);
expect(i3.getPixel(1, 1).equals([110, 84, 94])).toBe(true);
expect(i3.getPixel(0, 0).equals([32, 64, 86])).toBeTruthy();
expect(i3.getPixel(1, 0).equals([64, 32, 14])).toBeTruthy();
expect(i3.getPixel(0, 1).equals([-58, 52, 5])).toBeTruthy();
expect(i3.getPixel(1, 1).equals([110, 84, 94])).toBeTruthy();

const i4 = new MemoryImage({
width: 2,
Expand All @@ -81,9 +81,9 @@ describe('Image', () => {
i4.setPixelRgba(0, 1, 12, 52, 5, 52);
i4.setPixelRgba(1, 1, 100, 84, 94, 82);

expect(i4.getPixel(0, 0).equals([32, 64, 86, 44])).toBe(true);
expect(i4.getPixel(1, 0).equals([64, 32, 14, 14])).toBe(true);
expect(i4.getPixel(0, 1).equals([12, 52, 5, 52])).toBe(true);
expect(i4.getPixel(1, 1).equals([100, 84, 94, 82])).toBe(true);
expect(i4.getPixel(0, 0).equals([32, 64, 86, 44])).toBeTruthy();
expect(i4.getPixel(1, 0).equals([64, 32, 14, 14])).toBeTruthy();
expect(i4.getPixel(0, 1).equals([12, 52, 5, 52])).toBeTruthy();
expect(i4.getPixel(1, 1).equals([100, 84, 94, 82])).toBeTruthy();
});
});
32 changes: 16 additions & 16 deletions test/image/image.float32.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ describe('Image', () => {
i1.setPixelRgb(0, 1, -75, 0, 0);
i1.setPixelRgb(1, 1, -115, 0, 0);

expect(i1.getPixel(0, 0).equals([32])).toBe(true);
expect(i1.getPixel(1, 0).equals([64])).toBe(true);
expect(i1.getPixel(0, 1).equals([-75])).toBe(true);
expect(i1.getPixel(1, 1).equals([-115])).toBe(true);
expect(i1.getPixel(0, 0).equals([32])).toBeTruthy();
expect(i1.getPixel(1, 0).equals([64])).toBeTruthy();
expect(i1.getPixel(0, 1).equals([-75])).toBeTruthy();
expect(i1.getPixel(1, 1).equals([-115])).toBeTruthy();

const i2 = new MemoryImage({
width: 2,
Expand All @@ -41,10 +41,10 @@ describe('Image', () => {
i2.setPixelRgb(0, 1, -58, 52, 0);
i2.setPixelRgb(1, 1, 110, 84, 0);

expect(i2.getPixel(0, 0).equals([32, 64])).toBe(true);
expect(i2.getPixel(1, 0).equals([64, 32])).toBe(true);
expect(i2.getPixel(0, 1).equals([-58, 52])).toBe(true);
expect(i2.getPixel(1, 1).equals([110, 84])).toBe(true);
expect(i2.getPixel(0, 0).equals([32, 64])).toBeTruthy();
expect(i2.getPixel(1, 0).equals([64, 32])).toBeTruthy();
expect(i2.getPixel(0, 1).equals([-58, 52])).toBeTruthy();
expect(i2.getPixel(1, 1).equals([110, 84])).toBeTruthy();

const i3 = new MemoryImage({
width: 2,
Expand All @@ -61,10 +61,10 @@ describe('Image', () => {
i3.setPixelRgb(0, 1, -58, 52, 5);
i3.setPixelRgb(1, 1, 110, 84, 94);

expect(i3.getPixel(0, 0).equals([32, 64, 86])).toBe(true);
expect(i3.getPixel(1, 0).equals([64, 32, 14])).toBe(true);
expect(i3.getPixel(0, 1).equals([-58, 52, 5])).toBe(true);
expect(i3.getPixel(1, 1).equals([110, 84, 94])).toBe(true);
expect(i3.getPixel(0, 0).equals([32, 64, 86])).toBeTruthy();
expect(i3.getPixel(1, 0).equals([64, 32, 14])).toBeTruthy();
expect(i3.getPixel(0, 1).equals([-58, 52, 5])).toBeTruthy();
expect(i3.getPixel(1, 1).equals([110, 84, 94])).toBeTruthy();

const i4 = new MemoryImage({
width: 2,
Expand All @@ -81,9 +81,9 @@ describe('Image', () => {
i4.setPixelRgba(0, 1, 12, 52, 5, 52);
i4.setPixelRgba(1, 1, 100, 84, 94, 82);

expect(i4.getPixel(0, 0).equals([32, 64, 86, 44])).toBe(true);
expect(i4.getPixel(1, 0).equals([64, 32, 14, 14])).toBe(true);
expect(i4.getPixel(0, 1).equals([12, 52, 5, 52])).toBe(true);
expect(i4.getPixel(1, 1).equals([100, 84, 94, 82])).toBe(true);
expect(i4.getPixel(0, 0).equals([32, 64, 86, 44])).toBeTruthy();
expect(i4.getPixel(1, 0).equals([64, 32, 14, 14])).toBeTruthy();
expect(i4.getPixel(0, 1).equals([12, 52, 5, 52])).toBeTruthy();
expect(i4.getPixel(1, 1).equals([100, 84, 94, 82])).toBeTruthy();
});
});
32 changes: 16 additions & 16 deletions test/image/image.float64.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ describe('Image', () => {
i1.setPixelRgb(0, 1, -75, 0, 0);
i1.setPixelRgb(1, 1, -115, 0, 0);

expect(i1.getPixel(0, 0).equals([32])).toBe(true);
expect(i1.getPixel(1, 0).equals([64])).toBe(true);
expect(i1.getPixel(0, 1).equals([-75])).toBe(true);
expect(i1.getPixel(1, 1).equals([-115])).toBe(true);
expect(i1.getPixel(0, 0).equals([32])).toBeTruthy();
expect(i1.getPixel(1, 0).equals([64])).toBeTruthy();
expect(i1.getPixel(0, 1).equals([-75])).toBeTruthy();
expect(i1.getPixel(1, 1).equals([-115])).toBeTruthy();

const i2 = new MemoryImage({
width: 2,
Expand All @@ -41,10 +41,10 @@ describe('Image', () => {
i2.setPixelRgb(0, 1, -58, 52, 0);
i2.setPixelRgb(1, 1, 110, 84, 0);

expect(i2.getPixel(0, 0).equals([32, 64])).toBe(true);
expect(i2.getPixel(1, 0).equals([64, 32])).toBe(true);
expect(i2.getPixel(0, 1).equals([-58, 52])).toBe(true);
expect(i2.getPixel(1, 1).equals([110, 84])).toBe(true);
expect(i2.getPixel(0, 0).equals([32, 64])).toBeTruthy();
expect(i2.getPixel(1, 0).equals([64, 32])).toBeTruthy();
expect(i2.getPixel(0, 1).equals([-58, 52])).toBeTruthy();
expect(i2.getPixel(1, 1).equals([110, 84])).toBeTruthy();

const i3 = new MemoryImage({
width: 2,
Expand All @@ -61,10 +61,10 @@ describe('Image', () => {
i3.setPixelRgb(0, 1, -58, 52, 5);
i3.setPixelRgb(1, 1, 110, 84, 94);

expect(i3.getPixel(0, 0).equals([32, 64, 86])).toBe(true);
expect(i3.getPixel(1, 0).equals([64, 32, 14])).toBe(true);
expect(i3.getPixel(0, 1).equals([-58, 52, 5])).toBe(true);
expect(i3.getPixel(1, 1).equals([110, 84, 94])).toBe(true);
expect(i3.getPixel(0, 0).equals([32, 64, 86])).toBeTruthy();
expect(i3.getPixel(1, 0).equals([64, 32, 14])).toBeTruthy();
expect(i3.getPixel(0, 1).equals([-58, 52, 5])).toBeTruthy();
expect(i3.getPixel(1, 1).equals([110, 84, 94])).toBeTruthy();

const i4 = new MemoryImage({
width: 2,
Expand All @@ -81,9 +81,9 @@ describe('Image', () => {
i4.setPixelRgba(0, 1, 12, 52, 5, 52);
i4.setPixelRgba(1, 1, 100, 84, 94, 82);

expect(i4.getPixel(0, 0).equals([32, 64, 86, 44])).toBe(true);
expect(i4.getPixel(1, 0).equals([64, 32, 14, 14])).toBe(true);
expect(i4.getPixel(0, 1).equals([12, 52, 5, 52])).toBe(true);
expect(i4.getPixel(1, 1).equals([100, 84, 94, 82])).toBe(true);
expect(i4.getPixel(0, 0).equals([32, 64, 86, 44])).toBeTruthy();
expect(i4.getPixel(1, 0).equals([64, 32, 14, 14])).toBeTruthy();
expect(i4.getPixel(0, 1).equals([12, 52, 5, 52])).toBeTruthy();
expect(i4.getPixel(1, 1).equals([100, 84, 94, 82])).toBeTruthy();
});
});
32 changes: 16 additions & 16 deletions test/image/image.int16.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ describe('Image', () => {
i1.setPixelRgb(0, 1, -75, 0, 0);
i1.setPixelRgb(1, 1, -115, 0, 0);

expect(i1.getPixel(0, 0).equals([32])).toBe(true);
expect(i1.getPixel(1, 0).equals([64])).toBe(true);
expect(i1.getPixel(0, 1).equals([-75])).toBe(true);
expect(i1.getPixel(1, 1).equals([-115])).toBe(true);
expect(i1.getPixel(0, 0).equals([32])).toBeTruthy();
expect(i1.getPixel(1, 0).equals([64])).toBeTruthy();
expect(i1.getPixel(0, 1).equals([-75])).toBeTruthy();
expect(i1.getPixel(1, 1).equals([-115])).toBeTruthy();

const i2 = new MemoryImage({
width: 2,
Expand All @@ -41,10 +41,10 @@ describe('Image', () => {
i2.setPixelRgb(0, 1, -58, 52, 0);
i2.setPixelRgb(1, 1, 110, 84, 0);

expect(i2.getPixel(0, 0).equals([32, 64])).toBe(true);
expect(i2.getPixel(1, 0).equals([64, 32])).toBe(true);
expect(i2.getPixel(0, 1).equals([-58, 52])).toBe(true);
expect(i2.getPixel(1, 1).equals([110, 84])).toBe(true);
expect(i2.getPixel(0, 0).equals([32, 64])).toBeTruthy();
expect(i2.getPixel(1, 0).equals([64, 32])).toBeTruthy();
expect(i2.getPixel(0, 1).equals([-58, 52])).toBeTruthy();
expect(i2.getPixel(1, 1).equals([110, 84])).toBeTruthy();

const i3 = new MemoryImage({
width: 2,
Expand All @@ -61,10 +61,10 @@ describe('Image', () => {
i3.setPixelRgb(0, 1, -58, 52, 5);
i3.setPixelRgb(1, 1, 110, 84, 94);

expect(i3.getPixel(0, 0).equals([32, 64, 86])).toBe(true);
expect(i3.getPixel(1, 0).equals([64, 32, 14])).toBe(true);
expect(i3.getPixel(0, 1).equals([-58, 52, 5])).toBe(true);
expect(i3.getPixel(1, 1).equals([110, 84, 94])).toBe(true);
expect(i3.getPixel(0, 0).equals([32, 64, 86])).toBeTruthy();
expect(i3.getPixel(1, 0).equals([64, 32, 14])).toBeTruthy();
expect(i3.getPixel(0, 1).equals([-58, 52, 5])).toBeTruthy();
expect(i3.getPixel(1, 1).equals([110, 84, 94])).toBeTruthy();

const i4 = new MemoryImage({
width: 2,
Expand All @@ -81,9 +81,9 @@ describe('Image', () => {
i4.setPixelRgba(0, 1, 12, 52, 5, 52);
i4.setPixelRgba(1, 1, 100, 84, 94, 82);

expect(i4.getPixel(0, 0).equals([32, 64, 86, 44])).toBe(true);
expect(i4.getPixel(1, 0).equals([64, 32, 14, 14])).toBe(true);
expect(i4.getPixel(0, 1).equals([12, 52, 5, 52])).toBe(true);
expect(i4.getPixel(1, 1).equals([100, 84, 94, 82])).toBe(true);
expect(i4.getPixel(0, 0).equals([32, 64, 86, 44])).toBeTruthy();
expect(i4.getPixel(1, 0).equals([64, 32, 14, 14])).toBeTruthy();
expect(i4.getPixel(0, 1).equals([12, 52, 5, 52])).toBeTruthy();
expect(i4.getPixel(1, 1).equals([100, 84, 94, 82])).toBeTruthy();
});
});
Loading

0 comments on commit 8e8ca90

Please sign in to comment.