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
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fi

export DBL_LIB="lib/"

TIMEOUT=1.0
TIMEOUT=3.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeout should be increased selectively, only for stdlib tests. For functional tests, it's better to keep it small, as tested programs are very tiny. However, we can fix it once #312 will be merged.


binary="_build/default/src/$1.exe"
flags=""
Expand Down
83 changes: 83 additions & 0 deletions test/stdlib/Map.fram
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import open Testing
import /Map

let (Map { module IntMap }) = Map.make { Key = Int }
let (Map { module StrMap }) = Map.make { Key = String }
let (Map { module IntMap2 }) =
Map.make { Key = Int, method lt = fn x y => x > y }

let _ =
testSuite "isEmpty" (fn _ =>
testCase "true" (fn _ =>
assertTrue (IntMap.empty {Val=Bool} >.isEmpty));

testCase "false" (fn _ =>
assertFalse (IntMap.singleton 13 "A" >.isEmpty)));

testSuite "size" (fn _ =>
testCase "empty" (fn _ =>
assertEq (IntMap.empty {Val=Int} >.size) 0);

testCase "not empty" (fn _ =>
assertEq (IntMap.singleton 42 True >.size) 1));

testCase "randomized test" (fn _ =>
handle
rand = effect () => fn seed =>
let seed = (seed * 39989 + 7) % 65536 in
resume (seed >> 12) seed
return x => fn _ => x
finally c => c 0

let doExtraTest (map : IntMap.T Int) (bitSet : Int) (bitMap : Int) =
assertEq (map.fold (fn _ acc => acc + 1) 0) map.size;
let rest = map.fold
(fn {key} v bitSet =>
let bit = 1 << key in
assertTrue ((bitSet &&& bit) != 0);
assertEq v (key + (bitMap &&& bit));
# check if the order is ascending
assertEq (bitSet ^^^ bit) (bitSet &&& (bitSet - 1));
bitSet ^^^ bit)
bitSet
in
assertEq rest 0

let rec randTest (map : IntMap.T _) (bitSet : Int) (bitMap : Int) (n : Int) =
if n == 0 then ()
else (
let op = rand () in
if op == 0 then doExtraTest map bitSet bitMap;
let key = rand ()
let bit = 1 << key
in
if (bitSet &&& bit) == 0 then (
assertFalse (map.mem key);
assertEq (map.find key >.unwrapOr (-1)) (-1);
assertEq (map.findErr {~onError = fn () => -1} key) (-1))
else (
assertTrue (map.mem key);
assertEq (map.find key >.unwrapOr (-1)) (key + (bitMap &&& bit));
assertEq (map.findErr {~onError = fn () => -1} key)
(key + (bitMap &&& bit)));
if op < 8 then (
let v = if op < 4 then 0 else bit
let map = map.add key (key + v)
let bitSet = bitSet ||| bit
let bitMap = bitMap ^^^ (bitMap &&& bit) ^^^ v
in
assertTrue (map.mem key);
assertEq (map.find key >.unwrapOr (-1)) (key + v);
assertEq (map.findErr {~onError = fn () => -1} key) (key + v);
randTest map bitSet bitMap (n - 1))
else (
let map = map.remove key
let bitSet = bitSet ^^^ (bitSet &&& bit)
in
assertFalse (map.mem key);
assertEq (map.find key >.unwrapOr (-1)) (-1);
assertEq (map.findErr {~onError = fn () => -1} key) (-1);
randTest map bitSet bitMap (n - 1))
)
in
randTest IntMap.empty 0 0 1000)
1 change: 1 addition & 0 deletions test/stdlib/TestAll.fram
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Base/Pair
import Base/Show
import Base/ToString
import List
import Map
import Mutable
import Prelude
import State
Expand Down
74 changes: 0 additions & 74 deletions test/stdlib/stdlib0008_Map.fram

This file was deleted.

1 change: 0 additions & 1 deletion test/test_suite
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ run_with_flags simple_examples ""
function simple_stdlib_tests {
simple_test test/stdlib/TestAll.fram
simple_test test/stdlib/stdlib0007_Stream.fram
simple_test test/stdlib/stdlib0008_Map.fram
}

run_with_flags simple_stdlib_tests ""
Expand Down