forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbs_array_test.ml
55 lines (44 loc) · 1.19 KB
/
bs_array_test.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
let suites : Mt.pair_suites ref = ref []
let test_id = ref 0
let eq loc x y =
incr test_id ;
suites :=
(loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites
type 'a t = 'a Js.Array.t
let () =
[| 1; 2; 3; 4 |]
|> Js.Array.filter (fun x -> x > 2)
|> Js.Array.mapi (fun x i -> x + i)
|> Js.Array.reduce (fun x y -> x + y) 0
|> Js.log
let id x =
eq __LOC__
(Js.Vector.toList @@ Js.Vector.ofList x ) x
let () =
eq __LOC__ (Js.Vector.ofList [1;2;3]) [|1;2;3|];
eq __LOC__
( Js.Vector.map (fun [@bs] x -> x + 1) [|1;2;3|] )
[|2;3;4|];
eq __LOC__ (Js.Vector.make 5 3)
[|3;3;3;3;3|];
eq __LOC__
( let a = Js.Vector.init 5 (fun [@bs] i -> i + 1) in
Js.Vector.filterInPlace (fun [@bs] j -> j mod 2 = 0) a ;
a
)
[|2;4|];
eq __LOC__
( let a = Js.Vector.init 5 (fun [@bs] i -> i + 1) in
Js.Vector.filterInPlace (fun [@bs] j -> j mod 2 <> 0) a ;
a
)
[|1;3;5|];
eq __LOC__
(Js.Vector.ofList [1;2;3] ) [|1;2;3|];
eq __LOC__
(Js.Vector.ofList [1]) [|1|];
id [] ;
id [1];
id [1;2;3;4;5];
id (Js.Vector.(toList @@ init 100 (fun [@bs] i -> i ) ))
;; Mt.from_pair_suites __LOC__ !suites