From 93c80b41e3cc9090227559234e659ef49b8bd7a2 Mon Sep 17 00:00:00 2001 From: JonathanStarup <32037926+JonathanStarup@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:52:36 +0100 Subject: [PATCH] work --- test/Test/Property/ListSetGenerator.flix | 5 +++-- test/Test/Property/TestListSet.flix | 19 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/test/Test/Property/ListSetGenerator.flix b/test/Test/Property/ListSetGenerator.flix index 7e6e069..fd36f6f 100644 --- a/test/Test/Property/ListSetGenerator.flix +++ b/test/Test/Property/ListSetGenerator.flix @@ -17,7 +17,7 @@ mod JonathanStarup.Test.Property.ListSetGenerator { if (get(runningLength) <= 0) None else { runningLength |> transform(Sub.sub(1)); - Some(do Random.randomInt32()) + Some(Random.randomInt32()) } }) @@ -43,6 +43,7 @@ mod JonathanStarup.Test.Property.ListSetGenerator { Some(fromLength(get(runningLen))) } }); + // We cant use fromLength now, so we do it lazily. def consThing(k, it) = { let justK = Iterator.singleton(rc, () -> checked_ecast(fromLength(k))) |> Iterator.map(f -> f()); Iterator.append(justK, it) @@ -54,6 +55,6 @@ mod JonathanStarup.Test.Property.ListSetGenerator { } def nextNatWithMax(max: Int32): Int32 \ Random = { - Int32.modulo(do Random.randomInt32(), Int32.max(max, 1)) + Int32.modulo(Random.randomInt32(), Int32.max(max, 1)) } } diff --git a/test/Test/Property/TestListSet.flix b/test/Test/Property/TestListSet.flix index 6611bac..4b57ee3 100644 --- a/test/Test/Property/TestListSet.flix +++ b/test/Test/Property/TestListSet.flix @@ -22,34 +22,33 @@ mod JonathanStarup.Test.Property.TestListSet { pub def crash(msg: String): Void } - def runCrash(f: Unit -> Unit \ ef + Crash): Bool \ ef + IO = - checked_ecast (try {(f(): _ \ ef + Crash); true} with Crash { + def runCrash(f: Unit -> Unit \ ef): Bool \ ef + IO - Crash = + try {f(); true} with Crash { def crash(msg, _) = { println("Test failed: ${msg}"); false } - }) + } def _assertEq(x: t, y: t): Unit \ Crash with Eq[t], ToString[t] = { if (x == y) () - else do Crash.crash("${x} != ${y}") + else Crash.crash("${x} != ${y}") } def assertExpect(expect: {expect = t}, actual: t): Unit \ Crash with Eq[t], ToString[t] = { if (expect#expect == actual) () - else do Crash.crash("found ${actual} instead of ${expect#expect}") + else Crash.crash("found ${actual} but expected ${expect#expect}") } def runTest( tests: Int32, seed: Int64, prop: c -> Unit \ Crash - ): Bool \ IO + Collectable.Aef[c] + ): Bool \ IO + (Collectable.Aef[c] - Crash - Random) with Collectable[c] where Collectable.Elm[c] ~ Int32 = region local { - let f: Unit -> Unit \ local + Crash + Random + Collectable.Aef[c] = () -> + let f = () -> ListSetGenerator.randomIterator(local, tests) |> Iterator.forEach(prop); - let g: Unit -> Bool \ local + IO + Random + Collectable.Aef[c] = () -> runCrash(f); - // manually compute the set difference - unchecked_cast((Random.runWithSeed(seed, g): _ \ (local + IO + Collectable.Aef[c]) - Random) as _ \ local + IO + Collectable.Aef[c]) + let g = () -> runCrash(f); + Random.runWithSeed(seed, g) } @test