Skip to content

Commit d6e08df

Browse files
committed
add a random test for mutable map
1 parent 9c1a499 commit d6e08df

File tree

2 files changed

+55
-16
lines changed

2 files changed

+55
-16
lines changed

jscomp/test/bs_poly_mutable_map_test.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var a0 = Belt_MutableMap.fromArray(randomRange(0, 10), Icmp);
4848

4949
Belt_MutableMap.set(a0, 3, 33);
5050

51-
eq("File \"bs_poly_mutable_map_test.ml\", line 27, characters 7-14", Belt_MutableMap.getExn(a0, 3), 33);
51+
eq("File \"bs_poly_mutable_map_test.ml\", line 29, characters 5-12", Belt_MutableMap.getExn(a0, 3), 33);
5252

5353
Belt_MutableMap.removeMany(a0, [
5454
7,
@@ -64,14 +64,41 @@ Belt_MutableMap.removeMany(a0, [
6464
6
6565
]);
6666

67-
eq("File \"bs_poly_mutable_map_test.ml\", line 29, characters 7-14", Belt_internalAVLtree.keysToArray(a0.data), [
67+
eq("File \"bs_poly_mutable_map_test.ml\", line 31, characters 5-12", Belt_internalAVLtree.keysToArray(a0.data), [
6868
9,
6969
10
7070
]);
7171

7272
Belt_MutableMap.removeMany(a0, Array_data_util.randomRange(0, 100));
7373

74-
b("File \"bs_poly_mutable_map_test.ml\", line 31, characters 6-13", Belt_MutableMap.isEmpty(a0));
74+
b("File \"bs_poly_mutable_map_test.ml\", line 33, characters 4-11", Belt_MutableMap.isEmpty(a0));
75+
76+
var a0$1 = Belt_MutableMap.fromArray(randomRange(0, 10000), Icmp);
77+
78+
Belt_MutableMap.set(a0$1, 2000, 33);
79+
80+
Belt_MutableMap.removeMany(a0$1, Belt_Array.map(randomRange(0, 1998), (function (prim) {
81+
return prim[0];
82+
})));
83+
84+
Belt_MutableMap.removeMany(a0$1, Belt_Array.map(randomRange(2002, 11000), (function (prim) {
85+
return prim[0];
86+
})));
87+
88+
eq("File \"bs_poly_mutable_map_test.ml\", line 41, characters 6-13", Belt_internalAVLtree.toArray(a0$1.data), [
89+
/* tuple */[
90+
1999,
91+
1999
92+
],
93+
/* tuple */[
94+
2000,
95+
33
96+
],
97+
/* tuple */[
98+
2001,
99+
2001
100+
]
101+
]);
75102

76103
Mt.from_pair_suites("Bs_poly_mutable_map_test", suites.contents);
77104

jscomp/test/bs_poly_mutable_map_test.ml

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let b loc v = Mt.bool_suites ~suites ~test_id loc v
66
module Icmp =
77
(val Belt.Id.comparable
88
~cmp:(fun (x : int) y -> compare x y
9-
)
9+
)
1010
)
1111
module M = Belt.MutableMap
1212
module N = Belt.Set
@@ -17,19 +17,31 @@ let f x = M.fromArray ~id:(module Icmp) x
1717
let ff x = N.fromArray ~id:(module Icmp) x
1818

1919

20-
let randomRange i j =
20+
let randomRange i j : (int * int) array =
2121
A.map (I.randomRange i j) (fun x -> (x,x))
2222

23-
24-
let () =
25-
let a0 = f (randomRange 0 10) in
26-
M.set a0 3 33;
27-
eq __LOC__ (M.getExn a0 3) 33 ;
28-
M.removeMany a0 [|7;8;0;1;3;2;4;922;4;5;6;|];
29-
eq __LOC__ (M.keysToArray a0) [|9;10|];
30-
M.removeMany a0 (I.randomRange 0 100);
31-
b __LOC__ (M.isEmpty a0)
32-
33-
23+
let %private ((.!()<-), (.!())) = M.(set, getExn)
24+
25+
26+
let () =
27+
let a0 = f (randomRange 0 10) in
28+
a0.!(3) <-33;
29+
eq __LOC__ (M.getExn a0 3) 33 ;
30+
M.removeMany a0 [|7;8;0;1;3;2;4;922;4;5;6;|];
31+
eq __LOC__ (M.keysToArray a0) [|9;10|];
32+
M.removeMany a0 (I.randomRange 0 100);
33+
b __LOC__ (M.isEmpty a0)
34+
35+
36+
let () =
37+
let a0 = f (randomRange 0 10000) in
38+
a0.!(2000) <- 33;
39+
a0 |. M.removeMany (randomRange 0 1998 |. A.map fst);
40+
a0 |. M.removeMany (randomRange 2002 11000 |. A.map fst);
41+
eq __LOC__ (a0 |. M.toArray) ([|
42+
1999, 1999;
43+
2000, 33;
44+
2001, 2001
45+
|])
3446

3547
;; Mt.from_pair_suites __MODULE__ !suites

0 commit comments

Comments
 (0)