Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Aug 24, 2024
1 parent d1791a1 commit 477b93d
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
nonoverlapping-structure-merge.yaml
root-map-expansion.yaml
structure-composition.yaml
structure-composition.yaml
sequential-placement.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: 1
name: Flipped structure placement
author: Karl Ostmo
description: |
Sequentially place structures that are larger than the map
with flipped orientation.
creative: false
robots:
- name: base
dir: north
known: [boulder, mountain]
seed: 0
world:
structures:
- name: house
structure:
palette:
'x': [stone, boulder]
'A': [stone, mountain]
'.': [stone]
map: |
xxxx
x..x
x..A
xxAA
- name: street pair
structure:
palette:
'.': [grass]
placements:
- src: house
offset: [-1, 0]
orient:
up: south
map: |
.
.
.
.
.
.
.
.
.
- name: block
structure:
placements:
- src: street pair
orient:
flip: true
- src: street pair
map: ""
palette:
'Ω': [grass, erase, base]
placements:
- src: block
offset: [-2, -1]
upperleft: [0, 0]
dsl: |
{grass}
map: |
Ω
Binary file added data/test/standalone-topography/flip-duplicate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions data/test/standalone-topography/flip-duplicate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
structures:
- name: house
structure:
palette:
'x': "#ff0000"
'A': "#ff8800"
'.': "#ffff00"
map: |
xxxx
x..x
x..A
xxAA
- name: street pair
structure:
palette:
'.': "#00ff00"
placements:
- src: house
offset: [-1, 0]
orient:
up: south
map: |
.
.
.
.
.
.
.
.
.
- name: block
structure:
placements:
- src: street pair
orient:
flip: true
- src: street pair
map: ""
palette:
'Ω': "#00ffff"
placements:
- src: block
offset: [-2, -1]
upperleft: [0, 0]
map: |
Ω
7 changes: 7 additions & 0 deletions test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ testScenarioSolutions rs ui key =
[ testSolution Default "Testing/1535-ping/1535-in-range"
, testSolution Default "Testing/1535-ping/1535-out-of-range"
]
, testGroup
"Structure placement (#1780)"
[ testSolution Default "Testing/1780-structure-merge-expansion/nonoverlapping-structure-merge"
, testSolution Default "Testing/1780-structure-merge-expansion/root-map-expansion"
, testSolution Default "Testing/1780-structure-merge-expansion/structure-composition"
, testSolution Default "Testing/1780-structure-merge-expansion/sequential-placement"
]
, testGroup
"Structure recognition (#1575)"
[ testSolution Default "Testing/1575-structure-recognizer/1575-browse-structures"
Expand Down
10 changes: 5 additions & 5 deletions test/standalone-topography/src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ parseStructures dataDir baseFilename = do
dataDir </> "test/standalone-topography" </> baseFilename
return $ forceEither $ left prettyPrintParseException eitherResult

compareToReferenceImage :: FilePath -> Assertion
compareToReferenceImage fileStem = do
compareToReferenceImage ::
Bool -- ^ set this to update the golden tests
-> FilePath
-> Assertion
compareToReferenceImage refreshReferenceImage fileStem = do
dataDir <- getDataDir
parentStruct <- parseStructures dataDir $ fileStem <.> "yaml"
let MergedStructure overlayArea _ _ = forceEither $ mergeStructures mempty Root parentStruct
Expand All @@ -44,6 +47,3 @@ compareToReferenceImage fileStem = do
else do
decodedImg <- LBS.readFile referenceFilepath
assertEqual "Generated image must equal reference image!" decodedImg encodedImgBytestring
where
-- Manually toggle this to update the golden tests
refreshReferenceImage = False
43 changes: 30 additions & 13 deletions test/standalone-topography/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,37 @@
-- SPDX-License-Identifier: BSD-3-Clause
module Main where

import Test.Tasty (defaultMain, testGroup)
import Test.Tasty.HUnit (testCase)
import Test.Tasty
import Test.Tasty.Options
import Test.Tasty.HUnit ( testCase )
import Data.Typeable (Typeable)
import Data.Proxy

import Lib
import Lib ( compareToReferenceImage )

newtype UpdateGoldenTests = UpdateGoldenTests Bool
deriving (Eq, Ord, Typeable)

instance IsOption UpdateGoldenTests where
parseValue = fmap UpdateGoldenTests . safeRead
defaultValue = UpdateGoldenTests False
optionName = return "refresh"
optionHelp = return "Should overwrite the golden test images"
optionCLParser = mkFlagCLParser mempty (UpdateGoldenTests True)

main :: IO ()
main = do
defaultMain $
defaultMainWithIngredients ingreds $ askOption $ \(UpdateGoldenTests shouldRefreshTests) -> let
doTest stem =
testCase (unwords ["Image equality:", stem]) $
compareToReferenceImage shouldRefreshTests stem

mkGroup title members =
testGroup title $
map
doTest
members
in
testGroup
"Test structure assembly"
[ mkGroup
Expand All @@ -22,15 +45,9 @@ main = do
, mkGroup
"Color"
[ "rainbow"
, "flip-duplicate"
]
]
where
doTest stem =
testCase (unwords ["Image equality:", stem]) $
compareToReferenceImage stem

mkGroup title members =
testGroup title $
map
doTest
members
ingreds = includingOptions [Option (Proxy :: Proxy UpdateGoldenTests)] : defaultIngredients

0 comments on commit 477b93d

Please sign in to comment.