Skip to content

Commit

Permalink
Deploy the new testlib to all exercises.
Browse files Browse the repository at this point in the history
  • Loading branch information
guygastineau committed Jun 11, 2022
1 parent a5d05c3 commit 8b94bcd
Show file tree
Hide file tree
Showing 27 changed files with 108 additions and 81 deletions.
7 changes: 4 additions & 3 deletions exercises/practice/accumulate/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/all-your-base/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/allergies/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/anagram/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/atbash-cipher/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/binary/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/bob/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/collatz-conjecture/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/diamond/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/difference-of-squares/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/flatten-array/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/hamming/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/hello-world/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/leap/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/list-ops/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/matching-brackets/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/nth-prime/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/pangram/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/perfect-numbers/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/phone-number/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/pig-latin/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/prime-factors/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/raindrops/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/rna-transcription/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/roman-numerals/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/sum-of-multiples/testlib.sml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ struct
then Pass
else failEq (PolyML.makestring b) (PolyML.makestring a)

fun nearTo b a =
if Real.== (a, b)
fun nearTo delta b a =
if Real.abs (a - b) <= delta * Real.abs a orelse
Real.abs (a - b) <= delta * Real.abs b
then Pass
else failEq (Real.toString b) (Real.toString a)
else failEq (Real.toString b ^ " +/- " ^ Real.toString delta) (Real.toString a)

fun anyError f =
(
Expand Down
Loading

0 comments on commit 8b94bcd

Please sign in to comment.