Skip to content

Refactor test interface#100

Merged
patritzenfeld merged 23 commits intomainfrom
reader
Jan 26, 2026
Merged

Refactor test interface#100
patritzenfeld merged 23 commits intomainfrom
reader

Conversation

@patritzenfeld
Copy link
Copy Markdown
Member

@patritzenfeld patritzenfeld commented Jan 19, 2026

  • Predicates/Queries are of type Reader (Picture,Components) a
  • For animations, the type changes to Reader (Double -> (Picture,Components)) a
  • Predicates can be given a label to promote them to a test (ReaderT env (Except String) ())
  • An arbitrary amount of tests can be run yielding the label of the first failed test or the empty String if every test passed. (for direct use in the HUnit function assertString, which fails on any non-empty String)

Example use:

test :: [ Test ]
test =
  [ "scene =/= undefined?" ~: isDeeplyDefined Task02.scene
  , TestCase $ assertString $ testPicture Task02.scene $ do
      complain "Picture contains a trunk?" $ containsElem wood
      complain "Tree has at least a trunk and two branches?" $ wood `atLeast` 3
      complain "Tree has a green crown?" $ containsElem $ withColor green someSolidCircle
      complain "The trunk stands upright and there is a tree crown above it?" $
        hasRelation $ withColor green someSolidCircle `isNorthOf` uprightWood
      complain
        ( "Branches are roughly symmetrical? " ++
          "(if they already are, make sure your branches share code as much as possible)" 
        )
       $ containsElem (rotatedQuarter uprightWood) `ifThen` containsElem (rotatedUpToFull uprightWood) <&&>
         containsElem (rotatedUpToFull uprightWood) `ifThen` containsElem (rotatedQuarter uprightWood)
      complain
        ( "Branches are in the correct position? " ++
          "(They should neither cross, nor be detached from the trunk, nor be at level with the trunk)"
        )
        $ hasRelation (rotatedQuarter uprightWood `isAbove` uprightWood) <&&>
          hasRelation (rotatedUpToFull uprightWood `isAbove` uprightWood) <&&>
          hasRelation (rotatedQuarter uprightWood `isLeftOf` rotatedUpToFull uprightWood)
  ]
  where
    wood = withColor brown someSolidRectangle
    uprightWood = withColor brown someTallSolidRectangle

ToDo:

  • adjust remaining tests

@patritzenfeld patritzenfeld marked this pull request as ready for review January 19, 2026 17:15
@patritzenfeld patritzenfeld linked an issue Jan 26, 2026 that may be closed by this pull request
@patritzenfeld
Copy link
Copy Markdown
Member Author

@jvoigtlaender can you take a quick look if there's anything you'd want to be different in the example config usage?

@jvoigtlaender
Copy link
Copy Markdown
Member

That's the

test :: [ Test ]
...

listing above?

Looks good to me right now.

As an aside (apparently not relevant for the expressions in the tests, only their types and implementation): Maybe the pair in Reader (Picture,Components) should be replaced by something more abstract (later, as a refactoring)? I guess these will be accessed with fst/snd. Also, there is apparent redundancy, since presumably the components are derived from the picture. Maybe the environment should have a more abstract name/type, like Artefact or whatnot. Of course, it could internally still be a record with exactly the above two components, also retaining the fact that the components are explicitly stored in order to avoid their recomputation from the picture on each access; but instead of fst/snd there would be named accessors.

@patritzenfeld
Copy link
Copy Markdown
Member Author

Sounds good.

I had also debated about the current redundancy in the environment, but it seemed to be better to only do the tree normalization once instead of (presumably) on every call of a function accessing the components.

@patritzenfeld patritzenfeld merged commit 1b04aef into main Jan 26, 2026
17 checks passed
@patritzenfeld patritzenfeld deleted the reader branch January 26, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Reader for predicates

2 participants