forked from hamidb80/fastpnm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
14 additions
and
5 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
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 |
---|---|---|
@@ -1,32 +1,39 @@ | ||
import std/[unittest, os, strformat] | ||
import fastpnm | ||
|
||
discard existsOrCreateDir "./temp" | ||
|
||
template checkSame(a, b): untyped = | ||
check a.width == b.width | ||
check a.height == b.height | ||
check a.maxValue == b.maxValue | ||
check a.data == b.data | ||
|
||
proc exportPan(size: int, m: PanMagic): string = | ||
let | ||
fname = fmt"./temp/arrow-{size}-{m}.{fileExt(m)}" | ||
extra = case m | ||
of P1, P2, P3: "-compress none" | ||
of compressed: "-compress none" | ||
else: "" | ||
|
||
discard execShellCmd fmt"convert {extra} -flatten -background white -alpha remove -resize {size}x{size} ./examples/arrow.png {fname}" | ||
fname | ||
|
||
|
||
suite "tests": | ||
discard existsOrCreateDir "./temp" | ||
|
||
for size in [7, 8, 9, 34, 37, 43, 120]: | ||
for (mraw, mbin) in [(P1, P4), (P2, P5), (P3, P6)]: | ||
test fmt"compare {mraw}:{mbin} at {size}x{size}": | ||
let | ||
r = parsePan readFile exportPan(size, mraw) | ||
b = parsePan readFile exportPan(size, mbin) | ||
# echo r | ||
check r.data == b.data | ||
checkSame r, b | ||
|
||
for magic in P1..P6: | ||
test fmt"re read {magic} at {size}x{size}": | ||
let | ||
prev = parsePan readFile exportPan(size, magic) | ||
next = parsePan $prev | ||
check prev.data == next.data | ||
checkSame prev, next | ||
|