-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Added tests for using PNM decoder
- Loading branch information
1 parent
47c1718
commit 2f6c4d5
Showing
7 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ export enum TestSection { | |
ico, | ||
jpeg, | ||
png, | ||
pnm, | ||
tiff, | ||
tga, | ||
transform, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
}); | ||
} | ||
}); |