@@ -236,12 +236,14 @@ truncatedTime t =
236236 let (n,f) = properFraction t
237237 in show (n :: Int ) ++ take 3 (tail (show f))
238238----------
239+ {-# language NoMonomorphismRestriction #-}
240+
239241module Test (test ) where
240242import qualified Task04
241-
243+ import Data.Maybe ( isNothing )
242244import Data.List.Extra (nubOrd )
243- import Data.Tuple.Extra (both )
244- import Test.HUnit ((~:) , (~?) , Test (.. ), assertBool )
245+ import Data.Tuple.Extra ((&&&) )
246+ import Test.HUnit ((~:) , Test (.. ), assertBool , assertString )
245247import CodeWorld.Test (
246248 withColor ,
247249 green ,
@@ -251,48 +253,67 @@ import CodeWorld.Test (
251253 yellow ,
252254
253255 contains ,
254- findMaybeActual ,
255- getComponents ,
256+ findMaybeActualAnd ,
256257 getExactTranslation ,
257258 getRotation ,
258259
259260 containsElem ,
260- evaluatePred ,
261261 hasRelation ,
262262 isBelow ,
263263
264+ atTime ,
265+ noneAt ,
266+ rawImagesAt ,
267+ queryAt ,
268+
269+ complain ,
270+ testAnimation ,
271+ testPicture ,
272+
264273 samplesUntil ,
265274 )
266-
275+ import Control.Monad.Reader
267276import qualified TestHarness as TH
268277import TestHelper (isDeeplyDefined )
269278
270279test :: [ Test ]
271280test =
272281 [ " scene =/= undefined?" ~: isDeeplyDefined (Task04. scene 1.0 )
273- , onSceneAt 0 (containsElem someSolidCircle) ~?
274- " This animation does not contain a solid circle."
275- , onSceneAt 0 (containsElem someSolidRectangle) ~?
276- " This animation does not contain a solid rectangle."
277- , onSceneAt 0 (containsElem sun) ~?
278- " The circle is not yellow."
279- , onSceneAt 0 (containsElem grass) ~?
280- " The rectangle is not green."
281- , grassRotations (100 : frames) == 1 &&
282- grassMovement (100 : frames) == 1 ~?
283- " The grass seems to move or disappear at some point during this animation. " ++
284- " It should be stationary and the sun should move instead."
285- , not (onSceneAt 0 (containsElem cheat)) ~?
286- " The scene contains a solid white rectangle. " ++
287- " This suggests you are trying to conceal the movement of the sun at some point."
288- , differentFrames (map (+ 100 ) frames) == 1 ~?
289- " Your animation has changing frames after running for 100 seconds. " ++
290- " This suggests your sun is permanently moving instead of setting at some point."
291- , differentFrames frames > 1 ~?
292- " Cannot detect (reasonable) movement in this animation. Make sure parameter 't' is not ignored. " ++
293- " Your sun might be moving in a strange way if 't' is actually used for movement."
294- , all (\ t -> not $ onSceneAt t (hasRelation (sun `isBelow` grass))) (samplesUntil 0.5 30 ) ~?
295- " Your sun is moving under the grass!"
282+ , TestCase $ assertString $ testAnimation Task04. scene $ do
283+ atTime 0 $ do
284+ complain " This animation does not contain a solid circle."
285+ $ containsElem someSolidCircle
286+ complain " This animation does not contain a solid rectangle."
287+ $ containsElem someSolidRectangle
288+ complain " The circle is not yellow." $ containsElem sun
289+ complain " The rectangle is not green." $ containsElem grass
290+ complain
291+ ( " The scene contains a solid white rectangle. " ++
292+ " This suggests you are trying to conceal the movement of the sun at some point."
293+ )
294+ $ not <$> containsElem cheat
295+
296+ complain
297+ ( " The grass seems to move or disappear at some point during this animation. " ++
298+ " It should be stationary and the sun should move instead."
299+ )
300+ $ (== 1 ) . uniques <$> queryAt (100 : frames) getGrassValues
301+
302+ complain
303+ ( " Your animation has changing frames after running for 100 seconds. " ++
304+ " This suggests your sun is permanently moving instead of setting at some point."
305+ )
306+ $ (== 1 ) . uniques <$> rawImagesAt (map (+ 100 ) frames)
307+
308+ complain
309+ ( " Cannot detect (reasonable) movement in this animation. Make sure parameter 't' is not ignored. " ++
310+ " Your sun might be moving in a strange way if 't' is actually used for movement."
311+ )
312+ $ (> 1 ) . uniques <$> rawImagesAt frames
313+
314+ complain " Your sun is moving under the grass!"
315+ $ noneAt (samplesUntil 0.5 30 ) $ hasRelation $ sun `isBelow` grass
316+
296317 , TestCase $ TH. syntaxCheckWithExts [" LambdaCase" ," NoTemplateHaskell" ," TupleSections" ] $ \ m -> assertBool
297318 ( " The sun is not exhibiting circular movement. " ++
298319 " Please make sure it is not following a parabola shape or other different motions."
@@ -303,13 +324,7 @@ test =
303324 frames = samplesUntil 0.2 5
304325 grass = withColor green someSolidRectangle
305326 cheat = withColor white someSolidRectangle
306- onSceneAt t = flip evaluatePred (Task04. scene t)
307- sceneAt = getComponents . Task04. scene
308- mapUniques f = length . nubOrd . map f
309- differentFrames = mapUniques Task04. scene
310- getElementAt p = findMaybeActual (`contains` p) . Task04. scene
311- rotationAt p t = getRotation <$> getElementAt p t
312- grassRotations = mapUniques $ rotationAt grass
313- grassMovement = mapUniques (fmap getExactTranslation . getElementAt grass)
327+ uniques = length . nubOrd
328+ getGrassValues = findMaybeActualAnd (`contains` grass)
329+ $ getRotation &&& getExactTranslation
314330 sun = withColor yellow someSolidCircle
315-
0 commit comments