Skip to content

Commit

Permalink
feat: add asserts and expect statements (#10)
Browse files Browse the repository at this point in the history
* feat: add greater and less than asserts

* feat: add expect statements for convenience

* Apply suggestions from code review

Co-authored-by: Paul Cadman <[email protected]>

---------

Co-authored-by: Paul Cadman <[email protected]>
  • Loading branch information
heueristik and paulcadman authored Aug 27, 2024
1 parent 12b72c6 commit a87be47
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Test/JuvixUnit.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,34 @@ assertJust {A} (msg : String) : Maybe A -> Assertion := maybe (fail msg) (const
assertNothing {A} (mkMsg : A -> String) : Maybe A -> Assertion := maybe pass (mkMsg >> fail);

assertEqual {A} {{Eq A}} (msg : String) (a1 a2 : A) : Assertion := failUnless msg (a1 == a2);

assertGreater {A} {{Ord A}} (msg : String) (a1 a2 : A) : Assertion := failUnless msg (a1 >= a2);

assertGreaterEqual {A} {{Ord A}} (msg : String) (a1 a2 : A) : Assertion :=
failUnless msg (a1 >= a2);

assertLess {A} {{Ord A}} (msg : String) (a1 a2 : A) : Assertion := failUnless msg (a1 < a2);

assertLessEqual {A} {{Ord A}} (msg : String) (a1 a2 : A) : Assertion := failUnless msg (a1 <= a2);

mkExpectMsg {A} {{Show A}} (expected actual : A) (msg : String) : String :=
"\nExpected " ++str Show.show expected ++str "\nto be " ++str msg ++str Show.show actual;

expectTrue (actual : Bool) : Assertion := assertTrue (mkExpectMsg true actual "") actual;

expectFalse (actual : Bool) : Assertion := assertFalse (mkExpectMsg false actual "") actual;

expectEqual {A} {{Eq A}} {{Show A}} (expected actual : A) : Assertion :=
assertEqual (mkExpectMsg expected actual "equal to ") expected actual;

expectGreater {A} {{Ord A}} {{Show A}} (expected actual : A) : Assertion :=
assertGreater (mkExpectMsg expected actual "greater than ") expected actual;

expectGreaterEqual {A} {{Ord A}} {{Show A}} (expected actual : A) : Assertion :=
assertGreaterEqual (mkExpectMsg expected actual "greater than or equal to ") expected actual;

expectLess {A} {{Ord A}} {{Show A}} (expected actual : A) : Assertion :=
assertLess (mkExpectMsg expected actual "less than ") expected actual;

expectLessEqual {A} {{Ord A}} {{Show A}} (expected actual : A) : Assertion :=
assertLessEqual (mkExpectMsg expected actual "less than or equal to ") expected actual;

0 comments on commit a87be47

Please sign in to comment.