Skip to content

Commit

Permalink
test: Added tests for using PNM decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor-pelykh committed Mar 26, 2024
1 parent 47c1718 commit 2f6c4d5
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/_input/pnm/test.pbm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
P1
24 # PBM example
7
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0
0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0
0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0
0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
10 changes: 10 additions & 0 deletions test/_input/pnm/test.pgm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
P2
24 7
15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0
0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0
0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0
0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0
0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
8 changes: 8 additions & 0 deletions test/_input/pnm/test.ppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
P3
# example from the man page
4 4
15
0 0 0 0 0 0 0 0 0 15 0 15
0 0 0 0 15 7 0 0 0 0 0 0
0 0 0 0 0 0 0 15 7 0 0 0
15 0 15 0 0 0 0 0 0 0 0 0
Binary file added test/_input/pnm/z00n2c08.pnm
Binary file not shown.
1 change: 1 addition & 0 deletions test/_utils/test-section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum TestSection {
ico,
jpeg,
png,
pnm,
tiff,
tga,
transform,
Expand Down
2 changes: 2 additions & 0 deletions test/_utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export abstract class TestUtils {
return 'jpg';
case TestSection.png:
return 'png';
case TestSection.pnm:
return 'pnm';
case TestSection.tiff:
return 'tiff';
case TestSection.tga:
Expand Down
38 changes: 38 additions & 0 deletions test/format/format.pnm.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/** @format */

import { encodePng, PnmDecoder } from '../../src';
import { TestFolder } from '../_utils/test-folder';
import { TestSection } from '../_utils/test-section';
import { TestUtils } from '../_utils/test-utils';

describe('Format: PNM', () => {
const resFiles = TestUtils.listFiles(TestFolder.input, TestSection.pnm);

for (const file of resFiles) {
test(`pnm ${file.fileName}`, () => {
const input = TestUtils.readFromFilePath(file.path);
const decoder = new PnmDecoder();

const isValidFile = decoder.isValidFile(input);
expect(isValidFile).toBeTruthy();

const image = decoder.decode({
bytes: input,
});
expect(image).toBeDefined();
if (image === undefined) {
return;
}

const output = encodePng({
image: image,
});
TestUtils.writeToFile(
TestFolder.output,
TestSection.pnm,
`${file.fileName}.png`,
output
);
});
}
});

0 comments on commit 2f6c4d5

Please sign in to comment.