diff --git a/data/scenarios/Testing/1780-structure-merge-expansion/00-ORDER.txt b/data/scenarios/Testing/1780-structure-merge-expansion/00-ORDER.txt index b551229c8..37cfa0703 100644 --- a/data/scenarios/Testing/1780-structure-merge-expansion/00-ORDER.txt +++ b/data/scenarios/Testing/1780-structure-merge-expansion/00-ORDER.txt @@ -3,3 +3,4 @@ root-map-expansion.yaml structure-composition.yaml sequential-placement.yaml coordinate-offset-propagation.yaml +simultaneous-north-and-west-offset.yaml diff --git a/data/scenarios/Testing/1780-structure-merge-expansion/simultaneous-north-and-west-offset.yaml b/data/scenarios/Testing/1780-structure-merge-expansion/simultaneous-north-and-west-offset.yaml new file mode 100644 index 000000000..3619d7aba --- /dev/null +++ b/data/scenarios/Testing/1780-structure-merge-expansion/simultaneous-north-and-west-offset.yaml @@ -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: | + Ω diff --git a/test/unit/TestOverlay.hs b/test/unit/TestOverlay.hs index 7d728ab6e..1481c3f79 100644 --- a/test/unit/TestOverlay.hs +++ b/test/unit/TestOverlay.hs @@ -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 @@ -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]] @@ -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)) + ] ] ] @@ -122,11 +140,17 @@ 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 @@ -134,8 +158,9 @@ mkOverlaySequenceTest f testLabel overlays expectedBaseLoc = 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). @@ -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 () \ No newline at end of file