Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions test/Test/Property/ListSetGenerator.flix
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
})

Expand All @@ -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)
Expand All @@ -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))
}
}
19 changes: 9 additions & 10 deletions test/Test/Property/TestListSet.flix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading