diff --git a/examples/configs/Task03.hs b/examples/configs/Task03.hs index e059cb0..12ac3ad 100644 --- a/examples/configs/Task03.hs +++ b/examples/configs/Task03.hs @@ -199,7 +199,7 @@ import CodeWorld.Test ( white, yellow, - findAllAnd, + findAllThen, getExactScalingFactors, contains, @@ -229,7 +229,7 @@ test = ) $ oneOf containsElem [egg, solidGray, multiEgg, polyEgg] complain "The egg shell does not seem to have an oval shape." $ do - circleEggs <- findAllAnd + circleEggs <- findAllThen ((||) <$> (`contains` egg) <*> (`contains` solidGray)) getExactScalingFactors pure (any (uncurry (<)) circleEggs) <||> containsElem polyEgg diff --git a/examples/configs/Task04.hs b/examples/configs/Task04.hs index 598845d..fa75c2b 100644 --- a/examples/configs/Task04.hs +++ b/examples/configs/Task04.hs @@ -253,7 +253,7 @@ import CodeWorld.Test ( yellow, contains, - findMaybeActualAnd, + findFirstTranslatedThen, getExactTranslation, getRotation, @@ -325,6 +325,6 @@ test = grass = withColor green someSolidRectangle cheat = withColor white someSolidRectangle uniques = length . nubOrd - getGrassValues = findMaybeActualAnd (`contains` grass) + getGrassValues = findFirstTranslatedThen (`contains` grass) $ getRotation &&& getExactTranslation sun = withColor yellow someSolidCircle diff --git a/examples/configs/Task08.hs b/examples/configs/Task08.hs index 93878d3..2f88d39 100644 --- a/examples/configs/Task08.hs +++ b/examples/configs/Task08.hs @@ -247,7 +247,7 @@ import CodeWorld.Test ( white, contains, - findMaybeActualAnd, + findFirstTranslatedThen, getExactRotation, getExactTranslation, @@ -340,7 +340,7 @@ test = sunMoonCheck = samplesUntil 0.2 50 grass = withColor green someSolidRectangle cheat = withColor white someSolidRectangle - getGrassValues = findMaybeActualAnd (`contains` grass) + getGrassValues = findFirstTranslatedThen (`contains` grass) $ getExactRotation &&& getExactTranslation lengthUniques = length . nubOrd pictureHas = containsElem . normalizeAndAbstract diff --git a/examples/configs/Task09.hs b/examples/configs/Task09.hs index a2cba33..613110b 100644 --- a/examples/configs/Task09.hs +++ b/examples/configs/Task09.hs @@ -245,7 +245,7 @@ test = -- animation includes three different colors complain "Balloon has three different colors (each for a few seconds) during animation?" - $ (==3) . lengthUniques <$> queryAt framesToCheck (getBalloonAnd getColor) + $ (==3) . lengthUniques <$> queryAt framesToCheck (getBalloonThen getColor) -- size of the balloon changes complain "Balloon starts out growing, then shrinks and finally stops changing at all?" @@ -263,9 +263,9 @@ test = framesToCheck = drop 1 $ samplesUntil 0.2 100 -- no balloon at 't = 0' balloon = someSolidCircle coloredBalloon = someColor balloon - getBalloonAnd = findMaybeAnd (`contains` balloon) + getBalloonThen = findFirstThen (`contains` balloon) -- This doubles as a plain predicate thanks to 'MonadReader r ((->),r)' - getBalloonSize = getBalloonAnd getExactCircleRadius + getBalloonSize = getBalloonThen getExactCircleRadius checkBalloonSizes (x:y:xs) | x < y = checkBalloonSizes (y:xs) diff --git a/examples/configs/Task11.hs b/examples/configs/Task11.hs index e65f3d1..07aff45 100644 --- a/examples/configs/Task11.hs +++ b/examples/configs/Task11.hs @@ -235,8 +235,8 @@ import CodeWorld.Test ( contains, findAll, - findAllActualAnd, - findMaybeActualAnd, + findAllTranslatedThen, + findFirstTranslatedThen, getColor, getExactCircleRadius, getExactRotation, @@ -300,7 +300,7 @@ test = "It should be stationary and not move at all." ) $ (==1) . lengthUniques <$> queryAt (100 : movementCheck) getGrassValues - eggRotations <- queryAt widerCheck $ findAllActualAnd isEgg getExactRotation + eggRotations <- queryAt widerCheck $ findAllTranslatedThen isEgg getExactRotation -- eggs rotation changes complain "Eggs are swaying?" $ pure (lengthUniques (concat eggRotations) >= 6) <||> @@ -347,7 +347,7 @@ test = isEgg p = p `contains` singleEgg || p `contains` doubleEgg || p `contains` polyEggSolid || p `contains` polyEggThick - getGrassValues = findMaybeActualAnd (`contains` grass) + getGrassValues = findFirstTranslatedThen (`contains` grass) $ getExactRotation &&& getExactTranslation lengthUniques :: Ord a => [a] -> Int diff --git a/examples/configs/Task12.hs b/examples/configs/Task12.hs index 564e7e3..039ed77 100644 --- a/examples/configs/Task12.hs +++ b/examples/configs/Task12.hs @@ -293,7 +293,7 @@ test = $ all (\name -> TH.contains (TH.ident name) $ TH.findTopLevelDeclsOf "scene" m) ["aTile", "level"] , TestCase $ assertString $ testPicture Task12.scene $ do complain "Each tile is moved to a unique coordinate?" $ do - translations <- findAllActualAnd (`contains` someSolidRectangle) getExactTranslation + translations <- findAllTranslatedThen (`contains` someSolidRectangle) getExactTranslation pure $ length (nub translations) == length translations complain "scene draws the level correctly?" $ do image <- normalizedImage diff --git a/examples/configs/Task28.hs b/examples/configs/Task28.hs index 05b0064..eb6ee89 100644 --- a/examples/configs/Task28.hs +++ b/examples/configs/Task28.hs @@ -317,7 +317,7 @@ test = "Submission contains do-notation. This was explicitly forbidden by the task description!" $ not $ TH.contains TH.doNotation m , TestCase $ assertString $ testPicture (Task28.visualize Task28.level) $ do - translations <- findAllActualAnd (`contains` someSolidRectangle) getExactTranslation + translations <- findAllTranslatedThen (`contains` someSolidRectangle) getExactTranslation let tileAmount = length translations complain "All and only tiles of the level are drawn to the screen?" $ pure $ tileAmount == numberOfTiles diff --git a/src/CodeWorld/Test.hs b/src/CodeWorld/Test.hs index 1053260..f11dd87 100644 --- a/src/CodeWorld/Test.hs +++ b/src/CodeWorld/Test.hs @@ -111,14 +111,14 @@ module CodeWorld.Test ( -- ** Queries on Components rawImage, normalizedImage, - findMaybe, - findMaybeAnd, - findMaybeActual, - findMaybeActualAnd, findAll, - findAllAnd, - findAllActual, - findAllActualAnd, + findAllThen, + findAllTranslated, + findAllTranslatedThen, + findFirst, + findFirstThen, + findFirstTranslated, + findFirstTranslatedThen, -- ** Helpers for Animations mapAnimation, @@ -438,14 +438,14 @@ import CodeWorld.Test.Solution ( inRangeOf, oneOf, - findMaybe, findAll, - findAllAnd, - findMaybeAnd, - findAllActual, - findMaybeActual, - findAllActualAnd, - findMaybeActualAnd, + findAllThen, + findAllTranslated, + findAllTranslatedThen, + findFirst, + findFirstThen, + findFirstTranslated, + findFirstTranslatedThen, rawImage, normalizedImage, diff --git a/src/CodeWorld/Test/Solution.hs b/src/CodeWorld/Test/Solution.hs index 7207152..e519551 100644 --- a/src/CodeWorld/Test/Solution.hs +++ b/src/CodeWorld/Test/Solution.hs @@ -22,14 +22,14 @@ module CodeWorld.Test.Solution ( inRangeOf, rawImage, normalizedImage, - findMaybe, findAll, - findAllAnd, - findMaybeAnd, - findAllActual, - findMaybeActual, - findAllActualAnd, - findMaybeActualAnd, + findAllThen, + findAllTranslated, + findAllTranslatedThen, + findFirst, + findFirstThen, + findFirstTranslated, + findFirstTranslatedThen, oneOf, mapAnimation, atTime, @@ -138,17 +138,17 @@ specElems f (Components (ps,_)) = f ps {- | -Returns the first picture element satisfying the predicate if it exists. (translation is removed) +Returns the first subpictures satisfying the predicate if it exists. (translation is removed) -} -findMaybe +findFirst :: MonadReader StaticImage m => (AbstractPicture -> Bool) -> m (Maybe AbstractPicture) -findMaybe = fmap listToMaybe . findAll +findFirst = fmap listToMaybe . findAll {- | -Returns all picture elements satisfying the predicate. (translation is removed) +Returns all subpictures satisfying the predicate. (translation is removed) -} findAll :: MonadReader StaticImage m @@ -160,65 +160,65 @@ findAll f = asks $ filter f . specElems (map stripTranslation . getSubPictures) {- | Returns all subpictures satisfying the predicate. (includes translation) -} -findAllActual +findAllTranslated :: MonadReader StaticImage m => (AbstractPicture -> Bool) -> m [AbstractPicture] -findAllActual f = asks $ filter f . specElems getSubPictures . snd +findAllTranslated f = asks $ filter f . specElems getSubPictures . snd {- | Returns the first subpicture satisfying the predicate if it exists. (includes translation) -} -findMaybeActual +findFirstTranslated :: MonadReader StaticImage m => (AbstractPicture -> Bool) -> m (Maybe AbstractPicture) -findMaybeActual = fmap listToMaybe . findAllActual +findFirstTranslated = fmap listToMaybe . findAllTranslated {- | Finds all subpictures satisfying a predicate, then applies a function. (includes translation) -} -findAllActualAnd +findAllTranslatedThen :: MonadReader StaticImage m => (AbstractPicture -> Bool) -> (AbstractPicture -> a) -> m [a] -findAllActualAnd p f = map f <$> findAllActual p +findAllTranslatedThen p f = map f <$> findAllTranslated p {- | Finds the first subpicture satisfying a predicate, then applies a function if it exists. (includes translation) -} -findMaybeActualAnd +findFirstTranslatedThen :: MonadReader StaticImage m => (AbstractPicture -> Bool) -> (AbstractPicture -> a) -> m (Maybe a) -findMaybeActualAnd p = fmap listToMaybe . findAllActualAnd p +findFirstTranslatedThen p = fmap listToMaybe . findAllTranslatedThen p {- | -Finds all picture elements satisfying a predicate, then applies a function. (translation is removed) +Finds all subpictures satisfying a predicate, then applies a function. (translation is removed) -} -findAllAnd +findAllThen :: MonadReader StaticImage m => (AbstractPicture -> Bool) -> (AbstractPicture -> a) -> m [a] -findAllAnd f g = map g <$> findAll f +findAllThen f g = map g <$> findAll f {- | -Finds the first element satisfying a predicate, then applies a function if it exists. (translation is removed) +Finds the first subpictures satisfying a predicate, then applies a function if it exists. (translation is removed) -} -findMaybeAnd +findFirstThen :: MonadReader StaticImage m => (AbstractPicture -> Bool) -> (AbstractPicture -> a) -> m (Maybe a) -findMaybeAnd f = fmap listToMaybe . findAllAnd f +findFirstThen f = fmap listToMaybe . findAllThen f {- |