Skip to content

Commit

Permalink
pretty tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidb80 committed Aug 10, 2023
1 parent 95d2ddd commit 780298c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/fastpnm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ func parsePan*(s: string, captureComments = false): Pan =
of ppsMaxVal:
if result.magic notin bitMap:
inc i, s.parseInt(result.maxValue, i)
else:
result.maxValue = 1
inc state

of ppsContent:
Expand Down
17 changes: 12 additions & 5 deletions tests/test.nim
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

0 comments on commit 780298c

Please sign in to comment.