Skip to content

Commit 34fcda5

Browse files
committed
add new tests
1 parent 016d321 commit 34fcda5

File tree

5 files changed

+218
-7
lines changed

5 files changed

+218
-7
lines changed

jscomp/test/build.ninja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ build test/inner_unused.cmi test/inner_unused.cmj : cc test/inner_unused.ml | $s
359359
build test/installation_test.cmi test/installation_test.cmj : cc test/installation_test.ml | test/mt.cmj $stdlib
360360
build test/int32_test.cmi test/int32_test.cmj : cc test/int32_test.ml | test/ext_array_test.cmj test/mt.cmj $stdlib
361361
build test/int64_mul_div_test.cmi test/int64_mul_div_test.cmj : cc test/int64_mul_div_test.ml | test/mt.cmj $stdlib
362+
build test/int64_string_bench.cmi test/int64_string_bench.cmj : cc test/int64_string_bench.ml | $stdlib
363+
build test/int64_string_test.cmi test/int64_string_test.cmj : cc test/int64_string_test.ml | test/mt.cmj $stdlib
362364
build test/int64_test.cmi test/int64_test.cmj : cc test/int64_test.ml | test/ext_array_test.cmj test/mt.cmj $stdlib
363365
build test/int_hashtbl_test.cmi test/int_hashtbl_test.cmj : cc test/int_hashtbl_test.ml | test/mt.cmj $stdlib
364366
build test/int_map.cmi test/int_map.cmj : cc test/int_map.ml | $stdlib

jscomp/test/caml_format_test.ml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ let int64_suites =
188188
"i64_simple4", (fun _ -> Eq(a "%LX" 44L, "2C"));
189189
"i64_simple5", (fun _ -> Eq(a "%Lx" 44L, "2c"));
190190
"i64_simple6", (fun _ -> Eq(a "%*Lx" 5 44L, " 2c"));
191-
"i64_simple7", (fun _ -> Eq(Int64.to_string 3333L, "3333"));
191+
"i64_simple7", (fun _ -> Eq(Int64.to_string 3333L, "3333"));
192192
"i64_simple8", (fun _ -> Eq( a "%Ld%018Ld" 3L 3L, "3000000000000000003"));
193193
"i64_simple9", (fun _ -> Eq( a "%Ld%018Ld" 460800000000000L 0L,
194194
"460800000000000000000000000000000"));
@@ -203,20 +203,26 @@ let int64_suites =
203203

204204
"FFFFFFFFFFFFFFFF"
205205
));
206-
"i64_simple17", (fun _ ->
206+
__LOC__, (fun _ ->
207207
Eq( a "%Lx" (-1L),
208208

209209
"ffffffffffffffff"
210210
));
211211

212212
"i64_simple11", (fun _ -> Eq( a "%LX" Int64.max_int,"7FFFFFFFFFFFFFFF"
213213
));
214-
"i64_simple12", (fun _ -> Eq( a "%LX" Int64.min_int, "8000000000000000"));
215-
"i64_simple17", (fun _ ->
214+
__LOC__, (fun _ -> Eq( a "%LX" Int64.min_int, "8000000000000000"));
215+
__LOC__, (fun _ ->
216216

217217
Eq(a "%Lu" (-1L), "18446744073709551615")
218218
);
219-
"i64_simple21", (fun _ -> Eq(a "%Lu" (-10000L), "18446744073709541616"));
219+
__LOC__, (fun _ ->
220+
Eq (a "%Lu" (-100L), "18446744073709551516")
221+
) ;
222+
__LOC__, (fun _ ->
223+
Eq (a "%Lu" Int64.(add min_int 1L), "9223372036854775809")
224+
);
225+
__LOC__, (fun _ -> Eq(a "%Lu" (-10000L), "18446744073709541616"));
220226
"i64_simple19", (fun _ -> Eq(a "%Lo" Int64.min_int , "1000000000000000000000") );
221227
"i64_simple13", (fun _ -> Eq( a "%LX" Int64.(add min_int 1L),
222228
"8000000000000001"));

jscomp/test/int64_string_bench.ml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
3+
let () =
4+
Js.Console.timeStart "Int64.to_string";
5+
let u = Int64.( max_int |. sub 200_000L) in
6+
(* let u = 3L in *)
7+
for i = 0 to 1_00_000 do
8+
Int64.to_string u |> ignore
9+
done ;
10+
Js.Console.timeEnd "Int64.to_string"
11+
12+
let () =
13+
Js.Console.timeStart "Int64.to_string";
14+
let u = 30_000_000L in
15+
for i = 0 to 1_00_000 do
16+
Int64.to_string u |> ignore
17+
done ;
18+
Js.Console.timeEnd "Int64.to_string"
19+
20+
21+
let () =
22+
Js.Console.timeStart "Int64.to_string";
23+
let u = Int64.(min_int |. add 100L) in
24+
for i = 0 to 1_00_000 do
25+
Int64.to_string u |> ignore
26+
done ;
27+
Js.Console.timeEnd "Int64.to_string"

jscomp/test/int64_string_test.ml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
2+
let suites : Mt.pair_suites ref = ref []
3+
let test_id = ref 0
4+
let eq loc x y = Mt.eq_suites ~test_id ~suites loc x y
5+
6+
7+
8+
let v = Int64.to_string Int64.max_int
9+
;; eq __LOC__ v "9223372036854775807"
10+
let f a b =
11+
eq __LOC__ (Int64.to_string a) b
12+
13+
let hh = Int64.(add min_int 100L)
14+
15+
;; eq __LOC__
16+
hh
17+
(-9223372036854775708L)
18+
;; f (-33L) "-33"
19+
;; f (33L) "33"
20+
;; f Int64.min_int "-9223372036854775808"
21+
;; f hh
22+
"-9223372036854775708"
23+
;; f (1_000_000_000_000_000L) "1000000000000000"
24+
;; for i = 0 to 8 do
25+
eq __LOC__ (Int64.(to_string (add min_int (of_int i))))
26+
("-922337203685477580" ^ string_of_int (8 - i))
27+
done
28+
;; for i = 0 to 8 do
29+
eq __LOC__ (Int64.(to_string (add min_int (of_int @@ 100 + i))))
30+
("-922337203685477570" ^ string_of_int (8 - i))
31+
done
32+
;; for i = 0 to 8 do
33+
eq __LOC__ (Int64.(to_string (add min_int (of_int @@ 1_000_000 + i))))
34+
("-922337203685377580" ^ string_of_int (8 - i))
35+
done
36+
37+
38+
let u = 9007199254730991L
39+
(* + 100 *)
40+
;; for i = 0 to 6 do
41+
let open Int64 in
42+
eq __LOC__ (u |. add (i * 100_00 |. of_int) |. to_string) ("90071992547"^ (string_of_int (3+i)) ^ "0991")
43+
done
44+
45+
let v = -9007199254790991L
46+
47+
;; for i = 0 to 9 do
48+
let open Int64 in
49+
eq __LOC__ (v |. add (i * 100_00 |. of_int) |. to_string) ("-90071992547"^ (string_of_int (9-i)) ^ "0991")
50+
done
51+
52+
;; eq __LOC__ (9007199254740991L |. Int64.to_string) ("9007199254740991")
53+
;; eq __LOC__ (-9007199254740991L |. Int64.to_string) ("-9007199254740991")
54+
;; eq __LOC__ (Int64.to_string (-233L)) "-233"
55+
;; eq __LOC__ Int64.(to_string 9223372036854775807L) "9223372036854775807"
56+
57+
let random_data = [[9222265526802072873L,"9222265526802072873"];
58+
[-9222265526802072873L,"-9222265526802072873"];
59+
[8259675854677364784L,"8259675854677364784"];
60+
[-8259675854677364784L,"-8259675854677364784"];
61+
[8835388831347763546L,"8835388831347763546"];
62+
[-8835388831347763546L,"-8835388831347763546"];
63+
[8432790778033508297L,"8432790778033508297"];
64+
[-8432790778033508297L,"-8432790778033508297"];
65+
[8803803312937127383L,"8803803312937127383"];
66+
[-8803803312937127383L,"-8803803312937127383"];
67+
[8554209517442287148L,"8554209517442287148"];
68+
[-8554209517442287148L,"-8554209517442287148"];
69+
[8827502340722511268L,"8827502340722511268"];
70+
[-8827502340722511268L,"-8827502340722511268"];
71+
[8959938688116877129L,"8959938688116877129"];
72+
[-8959938688116877129L,"-8959938688116877129"];
73+
[8375343173485592219L,"8375343173485592219"];
74+
[-8375343173485592219L,"-8375343173485592219"];
75+
[8247185433903973425L,"8247185433903973425"];
76+
[-8247185433903973425L,"-8247185433903973425"];
77+
[8877202292449085084L,"8877202292449085084"];
78+
[-8877202292449085084L,"-8877202292449085084"];
79+
[8714039183933054831L,"8714039183933054831"];
80+
[-8714039183933054831L,"-8714039183933054831"];
81+
[8882991722536356759L,"8882991722536356759"];
82+
[-8882991722536356759L,"-8882991722536356759"];
83+
[8334238200124664212L,"8334238200124664212"];
84+
[-8334238200124664212L,"-8334238200124664212"];
85+
[9187027304886433402L,"9187027304886433402"];
86+
[-9187027304886433402L,"-9187027304886433402"];
87+
[9133057717520266586L,"9133057717520266586"];
88+
[-9133057717520266586L,"-9133057717520266586"];
89+
[9166371576562570333L,"9166371576562570333"];
90+
[-9166371576562570333L,"-9166371576562570333"];
91+
[8654171949643731022L,"8654171949643731022"];
92+
[-8654171949643731022L,"-8654171949643731022"];
93+
[9034842133647271125L,"9034842133647271125"];
94+
[-9034842133647271125L,"-9034842133647271125"];
95+
[8608580663100712151L,"8608580663100712151"];
96+
[-8608580663100712151L,"-8608580663100712151"];
97+
[8820716511945020972L,"8820716511945020972"];
98+
[-8820716511945020972L,"-8820716511945020972"];
99+
[9156810478222264303L,"9156810478222264303"];
100+
[-9156810478222264303L,"-9156810478222264303"];
101+
[8755426876594915757L,"8755426876594915757"];
102+
[-8755426876594915757L,"-8755426876594915757"];
103+
[8774739039348243521L,"8774739039348243521"];
104+
[-8774739039348243521L,"-8774739039348243521"];
105+
[9075741205602894645L,"9075741205602894645"];
106+
[-9075741205602894645L,"-9075741205602894645"];
107+
[8786231674279984331L,"8786231674279984331"];
108+
[-8786231674279984331L,"-8786231674279984331"];
109+
[8949021411802516758L,"8949021411802516758"];
110+
[-8949021411802516758L,"-8949021411802516758"];
111+
[8524723253526423954L,"8524723253526423954"];
112+
[-8524723253526423954L,"-8524723253526423954"];
113+
[8513293021681741708L,"8513293021681741708"];
114+
[-8513293021681741708L,"-8513293021681741708"];
115+
[8421467387985654104L,"8421467387985654104"];
116+
[-8421467387985654104L,"-8421467387985654104"];
117+
[8408716644548688797L,"8408716644548688797"];
118+
[-8408716644548688797L,"-8408716644548688797"];
119+
[8742836281862819756L,"8742836281862819756"];
120+
[-8742836281862819756L,"-8742836281862819756"];
121+
[8499829234439401537L,"8499829234439401537"];
122+
[-8499829234439401537L,"-8499829234439401537"];
123+
[8324213839613616899L,"8324213839613616899"];
124+
[-8324213839613616899L,"-8324213839613616899"];
125+
[9113404037906038527L,"9113404037906038527"];
126+
[-9113404037906038527L,"-9113404037906038527"];
127+
[8925488822310827593L,"8925488822310827593"];
128+
[-8925488822310827593L,"-8925488822310827593"];
129+
[9078209327951782997L,"9078209327951782997"];
130+
[-9078209327951782997L,"-9078209327951782997"];
131+
[8785053603418932244L,"8785053603418932244"];
132+
[-8785053603418932244L,"-8785053603418932244"];
133+
[8455581919940329271L,"8455581919940329271"];
134+
[-8455581919940329271L,"-8455581919940329271"];
135+
[8955835585569938560L,"8955835585569938560"];
136+
[-8955835585569938560L,"-8955835585569938560"];
137+
[9045075481293885891L,"9045075481293885891"];
138+
[-9045075481293885891L,"-9045075481293885891"];
139+
[8500775118540200419L,"8500775118540200419"];
140+
[-8500775118540200419L,"-8500775118540200419"];
141+
[9143290613252626570L,"9143290613252626570"];
142+
[-9143290613252626570L,"-9143290613252626570"];
143+
[8724850568849864514L,"8724850568849864514"];
144+
[-8724850568849864514L,"-8724850568849864514"];
145+
[9165646820667917008L,"9165646820667917008"];
146+
[-9165646820667917008L,"-9165646820667917008"];
147+
[8820340945276105736L,"8820340945276105736"];
148+
[-8820340945276105736L,"-8820340945276105736"];
149+
[9111963357615419435L,"9111963357615419435"];
150+
[-9111963357615419435L,"-9111963357615419435"];
151+
[9207756291626696888L,"9207756291626696888"];
152+
[-9207756291626696888L,"-9207756291626696888"];
153+
[8936229796511192184L,"8936229796511192184"];
154+
[-8936229796511192184L,"-8936229796511192184"];
155+
[8852749148056563032L,"8852749148056563032"];
156+
[-8852749148056563032L,"-8852749148056563032"]]
157+
158+
;; Belt_List.forEach random_data (fun u->
159+
match u with
160+
| [v , str] -> eq __LOC__ (Int64.to_string v) str
161+
| _ -> assert false
162+
)
163+
164+
;; eq __LOC__ (Int64.to_string (-9007199254740991L)) "-9007199254740991"
165+
;; eq __LOC__ (Int64.to_string (-9007199254740992L)) "-9007199254740992"
166+
;; Mt.from_pair_suites __LOC__ !suites
167+

jscomp/test/int64_test.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ let suites : Mt.pair_suites = Mt.[
7777
"of_int", (fun _ -> Eq(3L, Int64.of_int 3));
7878
"lognot", (fun _ -> Eq(-3L, Int64.lognot 2L));
7979
"neg", (fun _ -> Eq(-2L, Int64.neg 2L));
80+
__LOC__, (fun _ -> Eq(Int64.min_int, Int64.neg Int64.min_int));
81+
__LOC__, (fun _ -> Eq (Int64.max_int, Int64.neg Int64.(add min_int 1L)));
8082
"sub1", (fun _ -> Eq (2L, Int64.(sub 3L 1L)));
8183
"xor1", (fun _ ->
8284
Eq ((logxor 0xEEFFEEFFL 0xFFEEFFEEL, logxor a 0xEEFFEEFFL),
@@ -184,13 +186,20 @@ let id loc (x : int64) =
184186
| FP_nan -> ()
185187
| _ ->
186188
eq loc (Int64.bits_of_float float_value) x
189+
190+
187191
let () =
188192
eq __LOC__ (Int64.bits_of_float 0.3) 4599075939470750515L;
189193
eq __LOC__ (Int64.float_of_bits 4599075939470750515L) 0.3;
190194
id __LOC__ (-1L);
191195
id __LOC__ (-100L);
192196
id __LOC__ 0xff_ff_ff_ffL;
193197
id __LOC__ 0x1f_ff_ff_ffL;
194-
id __LOC__ 0x1f_ff_fe_ffL
195-
198+
id __LOC__ 0x1f_ff_fe_ffL;
199+
eq __LOC__ Int64.(div min_int 10L) (-922337203685477580L);
200+
eq __LOC__ Int64.(to_string (div min_int 10L)) "-922337203685477580";
201+
eq __LOC__ Int64.(mul min_int 10L) 0L;
202+
eq __LOC__ Int64.(mul 10L min_int) 0L;
203+
eq __LOC__ Int64.(mul 1L min_int) min_int;
204+
eq __LOC__ Int64.(mul max_int 10L) (-10L)
196205
;; Mt.from_pair_suites __MODULE__ !suites

0 commit comments

Comments
 (0)