Skip to content

Commit

Permalink
Add another demo image
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Jun 15, 2024
1 parent d6392c4 commit 2fdf1e5
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 14 deletions.
Binary file added data/test/standalone-topography/checkerboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions data/test/standalone-topography/checkerboard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
structures:
- name: checker pair
structure:
palette:
't': true
'f': false
map: |
ttttffff
ttttffff
ttttffff
ttttffff
- name: checker quad
structure:
palette:
't': true
'f': false
map: ""
placements:
- src: checker pair
offset: [0, 0]
truncate: false
- src: checker pair
offset: [0, -4]
truncate: false
orient:
up: south
- name: checker octo
structure:
palette:
't': true
'f': false
map: ""
placements:
- src: checker quad
offset: [0, 0]
truncate: false
- src: checker quad
offset: [8, 0]
truncate: false
- src: checker quad
offset: [0, -8]
truncate: false
- src: checker quad
offset: [8, -8]
truncate: false
placements:
- src: checker octo
offset: [0, 0]
truncate: false
- src: checker octo
offset: [16, 0]
truncate: false
- src: checker octo
offset: [0, -16]
truncate: false
- src: checker octo
offset: [16, -16]
truncate: false
map: ""
26 changes: 15 additions & 11 deletions test/standalone-topography/src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ newtype CustomCell = CustomCell Bool

instance FromJSONE e CustomCell

parseStructures :: IO (PStructure (Maybe CustomCell))
parseStructures = do
dataDir <- getDataDir
parseStructures :: FilePath -> FilePath -> IO (PStructure (Maybe CustomCell))
parseStructures dataDir baseFilename = do
eitherResult <-
decodeFileEitherE () $
dataDir </> "test/standalone-topography/demo-structures.yaml"
dataDir </> "test/standalone-topography" </> baseFilename
return $ forceEither $ left prettyPrintParseException eitherResult

getDisplayColor :: Maybe CustomCell -> PixelRGBA8
Expand All @@ -45,13 +44,18 @@ getDisplayColor = maybe transparent mkPixelColor

transparent = PixelRGBA8 0 0 0 0

compareToReferenceImage :: Assertion
compareToReferenceImage = do
parentStruct <- parseStructures
compareToReferenceImage :: String -> Assertion
compareToReferenceImage fileStem = do
dataDir <- getDataDir
parentStruct <- parseStructures dataDir $ fileStem <.> "yaml"
let MergedStructure overlayArea _ _ = forceEither $ mergeStructures mempty Root parentStruct
let encodedImgBytestring = encodePng $ makeImage getDisplayColor $ gridContent overlayArea

dataDir <- getDataDir
let referenceFilepath = dataDir </> "test/standalone-topography/reference.png"
decodedImg <- LBS.readFile referenceFilepath
assertEqual "Generated image must equal reference image!" decodedImg encodedImgBytestring
let referenceFilepath = dataDir </> "test/standalone-topography" </> fileStem <.> "png"
if refreshReferenceImage
then LBS.writeFile referenceFilepath encodedImgBytestring
else do
decodedImg <- LBS.readFile referenceFilepath
assertEqual "Generated image must equal reference image!" decodedImg encodedImgBytestring
where
refreshReferenceImage = False
11 changes: 8 additions & 3 deletions test/standalone-topography/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import Lib

main :: IO ()
main = do
defaultMain $
testGroup
defaultMain
$ testGroup
"Test structure assembly"
[ testCase "Image equality" compareToReferenceImage
$ map
doTest
[ "circle-and-crosses"
, "checkerboard"
]
where
doTest stem = testCase (unwords ["Image equality:", stem]) $ compareToReferenceImage stem

0 comments on commit 2fdf1e5

Please sign in to comment.