Skip to content

Commit

Permalink
more refined test for garbled offset
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Sep 22, 2024
1 parent 3cbb4da commit b0055d7
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ root-map-expansion.yaml
structure-composition.yaml
sequential-placement.yaml
coordinate-offset-propagation.yaml
simultaneous-north-and-west-offset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
version: 1
name: Northwest sibling structure coordinate offsets
author: Karl Ostmo
description: |
Make sure that the second sibling isn't garbled when there
is a simultaneous negative-x and postive-y offset on the first sibling.
robots:
- name: base
dir: north
creative: true
objectives:
- goal:
- Must have 3 of each color visible
condition: |
return false
solution: |
noop
known: [boulder, log, pixel (R), pixel (G), pixel (B), gold]
world:
structures:
- name: micro
structure:
mask: '.'
palette:
'x': [stone, gold]
map: |
x
- name: block
structure:
mask: '.'
palette:
'x': [stone, pixel (R)]
map: |
xx
xx
- name: master
structure:
mask: '.'
placements:
- src: micro
offset: [-1, 1]
- src: block
map: ""
dsl: |
overlay
[ {grass}
, mask (y > -4 && y < 4 || x > -4 && x < 4) {stone}
, mask (y > -2 && y < 2 || x > -2 && x < 2) {ice}
, mask (y > -1 && y < 1 || x > -1 && x < 1) {dirt}
]
palette:
'Ω': [grass, erase, base]
mask: '.'
placements:
- src: master
offset: [0, 0]
upperleft: [0, 0]
map: |
Ω
38 changes: 35 additions & 3 deletions test/unit/TestOverlay.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
-- Unit tests for generic grid overlay logic
module TestOverlay where

import Control.Monad (when)
import Data.Text (Text)
import Swarm.Game.Location
import Swarm.Game.Scenario.Topography.Grid
Expand All @@ -17,8 +18,16 @@ import Swarm.Game.Scenario.Topography.Structure.Overlay
import Test.Tasty
import Test.Tasty.HUnit

debugRenderGrid :: Bool
debugRenderGrid = True

-- * Example grids

-- | Single cell
oneByOneGrid :: [[Int]]
oneByOneGrid = [[0]]


-- | Single row with two columns
oneByTwoGrid :: [[Int]]
oneByTwoGrid = [[5, 6]]
Expand Down Expand Up @@ -87,6 +96,15 @@ testOverlay =
]
(Location 2 0)
]
, testGroup
"Northwesterly offset of first sibling"
[ mkOverlaySequenceOriginTest
"positive first south of second"
[ placeUnshifted "sibling1" (Location (-1) 1) oneByOneGrid
, placeUnshifted "sibling2" (Location 0 0) twoByTwoGrid
]
(Location 1 (-1))
]
]
]

Expand Down Expand Up @@ -122,20 +140,27 @@ mkOverlaySequenceTest ::
TestTree
mkOverlaySequenceTest f testLabel overlays expectedBaseLoc =
testCase testLabel $ do

when debugRenderGrid $
renderGridResult eitherResultGrid

assertEqual "Base loc wrong" (Right expectedBaseLoc) $
f . getGridFromMergedStructure <$> eitherResult
f <$> eitherResultGrid
where
baseArea = PositionedGrid (Location 0 0) (EmptyGrid :: Grid (Maybe Int))

eitherResultGrid = getGridFromMergedStructure <$> eitherResult

eitherResult =
foldLayer
mempty
baseArea
overlays
[]

getGridFromMergedStructure :: MergedStructure c -> PositionedGrid c
getGridFromMergedStructure (MergedStructure g _ _) = g

getGridFromMergedStructure :: MergedStructure c -> PositionedGrid c
getGridFromMergedStructure (MergedStructure g _ _) = g

-- | Place an structure at an offset.
-- The structure's local origin is (0, 0).
Expand Down Expand Up @@ -165,3 +190,10 @@ place localOrigin theName placementOffset g =
mempty
mempty
mempty

renderGridResult :: Either a (PositionedGrid (Maybe Int)) -> IO ()
renderGridResult eitherResult = case eitherResult of
Right pg -> do
print pg
print $ getRows $ gridContent pg
Left _ -> return ()

0 comments on commit b0055d7

Please sign in to comment.