Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/configs/Task03.hs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ import CodeWorld.Test (
white,
yellow,

findAllAnd,
findAllThen,
getExactScalingFactors,
contains,

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/configs/Task04.hs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ import CodeWorld.Test (
yellow,

contains,
findMaybeActualAnd,
findFirstTranslatedThen,
getExactTranslation,
getRotation,

Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions examples/configs/Task08.hs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ import CodeWorld.Test (
white,

contains,
findMaybeActualAnd,
findFirstTranslatedThen,
getExactRotation,
getExactTranslation,

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/configs/Task09.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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?"
Expand 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)
Expand Down
8 changes: 4 additions & 4 deletions examples/configs/Task11.hs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ import CodeWorld.Test (

contains,
findAll,
findAllActualAnd,
findMaybeActualAnd,
findAllTranslatedThen,
findFirstTranslatedThen,
getColor,
getExactCircleRadius,
getExactRotation,
Expand Down Expand Up @@ -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) <||>
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/configs/Task12.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/configs/Task28.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions src/CodeWorld/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,

Expand Down
50 changes: 25 additions & 25 deletions src/CodeWorld/Test/Solution.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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


{- |
Expand Down
Loading