@@ -75,7 +75,7 @@ open OUnitTypes
75
75
76
76
(** Most simple heuristic, just pick the first test. *)
77
77
let simple state =
78
- (* 153 *) List.hd state.tests_planned
78
+ (* 154 *) List.hd state.tests_planned
79
79
80
80
end
81
81
module OUnitUtils
@@ -98,22 +98,22 @@ let is_success =
98
98
let is_failure =
99
99
function
100
100
| RFailure _ -> (* 0 *) true
101
- | RSuccess _ | RError _ | RSkip _ | RTodo _ -> (* 306 *) false
101
+ | RSuccess _ | RError _ | RSkip _ | RTodo _ -> (* 308 *) false
102
102
103
103
let is_error =
104
104
function
105
105
| RError _ -> (* 0 *) true
106
- | RSuccess _ | RFailure _ | RSkip _ | RTodo _ -> (* 306 *) false
106
+ | RSuccess _ | RFailure _ | RSkip _ | RTodo _ -> (* 308 *) false
107
107
108
108
let is_skip =
109
109
function
110
110
| RSkip _ -> (* 0 *) true
111
- | RSuccess _ | RFailure _ | RError _ | RTodo _ -> (* 306 *) false
111
+ | RSuccess _ | RFailure _ | RError _ | RTodo _ -> (* 308 *) false
112
112
113
113
let is_todo =
114
114
function
115
115
| RTodo _ -> (* 0 *) true
116
- | RSuccess _ | RFailure _ | RError _ | RSkip _ -> (* 306 *) false
116
+ | RSuccess _ | RFailure _ | RError _ | RSkip _ -> (* 308 *) false
117
117
118
118
let result_flavour =
119
119
function
@@ -145,7 +145,7 @@ let rec was_successful =
145
145
| [] -> (* 3 *) true
146
146
| RSuccess _::t
147
147
| RSkip _::t ->
148
- (* 459 *) was_successful t
148
+ (* 462 *) was_successful t
149
149
150
150
| RFailure _::_
151
151
| RError _::_
@@ -155,22 +155,22 @@ let rec was_successful =
155
155
let string_of_node =
156
156
function
157
157
| ListItem n ->
158
- (* 612 *) string_of_int n
158
+ (* 616 *) string_of_int n
159
159
| Label s ->
160
- (* 918 *) s
160
+ (* 924 *) s
161
161
162
162
(* Return the number of available tests *)
163
163
let rec test_case_count =
164
164
function
165
- | TestCase _ -> (* 153 *) 1
166
- | TestLabel (_, t) -> (* 176 *) test_case_count t
165
+ | TestCase _ -> (* 154 *) 1
166
+ | TestLabel (_, t) -> (* 177 *) test_case_count t
167
167
| TestList l ->
168
168
(* 23 *) List.fold_left
169
- (fun c t -> (* 175 *) c + test_case_count t)
169
+ (fun c t -> (* 176 *) c + test_case_count t)
170
170
0 l
171
171
172
172
let string_of_path path =
173
- (* 306 *) String.concat ":" (List.rev_map string_of_node path)
173
+ (* 308 *) String.concat ":" (List.rev_map string_of_node path)
174
174
175
175
let buff_format_printf f =
176
176
(* 0 *) let buff = Buffer.create 13 in
@@ -194,12 +194,12 @@ let mapi f l =
194
194
195
195
let fold_lefti f accu l =
196
196
(* 23 *) let rec rfold_lefti cnt accup l =
197
- (* 198 *) match l with
197
+ (* 199 *) match l with
198
198
| [] ->
199
199
(* 23 *) accup
200
200
201
201
| h::t ->
202
- (* 175 *) rfold_lefti (cnt + 1) (f accup h cnt) t
202
+ (* 176 *) rfold_lefti (cnt + 1) (f accup h cnt) t
203
203
in
204
204
rfold_lefti 0 accu l
205
205
@@ -217,7 +217,7 @@ open OUnitUtils
217
217
type event_type = GlobalEvent of global_event | TestEvent of test_event
218
218
219
219
let format_event verbose event_type =
220
- (* 920 *) match event_type with
220
+ (* 926 *) match event_type with
221
221
| GlobalEvent e ->
222
222
(* 2 *) begin
223
223
match e with
@@ -276,31 +276,31 @@ let format_event verbose event_type =
276
276
end
277
277
278
278
| TestEvent e ->
279
- (* 918 *) begin
279
+ (* 924 *) begin
280
280
let string_of_result =
281
281
if verbose then
282
- (* 459 *) function
283
- | RSuccess _ -> (* 153 *) "ok\n"
282
+ (* 462 *) function
283
+ | RSuccess _ -> (* 154 *) "ok\n"
284
284
| RFailure (_, _) -> (* 0 *) "FAIL\n"
285
285
| RError (_, _) -> (* 0 *) "ERROR\n"
286
286
| RSkip (_, _) -> (* 0 *) "SKIP\n"
287
287
| RTodo (_, _) -> (* 0 *) "TODO\n"
288
288
else
289
- (* 459 *) function
290
- | RSuccess _ -> (* 153 *) "."
289
+ (* 462 *) function
290
+ | RSuccess _ -> (* 154 *) "."
291
291
| RFailure (_, _) -> (* 0 *) "F"
292
292
| RError (_, _) -> (* 0 *) "E"
293
293
| RSkip (_, _) -> (* 0 *) "S"
294
294
| RTodo (_, _) -> (* 0 *) "T"
295
295
in
296
296
if verbose then
297
- (* 459 *) match e with
297
+ (* 462 *) match e with
298
298
| EStart p ->
299
- (* 153 *) Printf.sprintf "%s start\n" (string_of_path p)
299
+ (* 154 *) Printf.sprintf "%s start\n" (string_of_path p)
300
300
| EEnd p ->
301
- (* 153 *) Printf.sprintf "%s end\n" (string_of_path p)
301
+ (* 154 *) Printf.sprintf "%s end\n" (string_of_path p)
302
302
| EResult result ->
303
- (* 153 *) string_of_result result
303
+ (* 154 *) string_of_result result
304
304
| ELog (lvl, str) ->
305
305
(* 0 *) let prefix =
306
306
match lvl with
@@ -312,21 +312,21 @@ let format_event verbose event_type =
312
312
| ELogRaw str ->
313
313
(* 0 *) str
314
314
else
315
- (* 459 *) match e with
316
- | EStart _ | EEnd _ | ELog _ | ELogRaw _ -> (* 306 *) ""
317
- | EResult result -> (* 153 *) string_of_result result
315
+ (* 462 *) match e with
316
+ | EStart _ | EEnd _ | ELog _ | ELogRaw _ -> (* 308 *) ""
317
+ | EResult result -> (* 154 *) string_of_result result
318
318
end
319
319
320
320
let file_logger fn =
321
321
(* 1 *) let chn = open_out fn in
322
322
(fun ev ->
323
- (* 460 *) output_string chn (format_event true ev);
323
+ (* 463 *) output_string chn (format_event true ev);
324
324
flush chn),
325
325
(fun () -> (* 1 *) close_out chn)
326
326
327
327
let std_logger verbose =
328
328
(* 1 *) (fun ev ->
329
- (* 460 *) print_string (format_event verbose ev);
329
+ (* 463 *) print_string (format_event verbose ev);
330
330
flush stdout),
331
331
(fun () -> (* 1 *) ())
332
332
@@ -343,7 +343,7 @@ let create output_file_opt verbose (log,close) =
343
343
(* 0 *) null_logger
344
344
in
345
345
(fun ev ->
346
- (* 460 *) std_log ev; file_log ev; log ev),
346
+ (* 463 *) std_log ev; file_log ev; log ev),
347
347
(fun () ->
348
348
(* 1 *) std_close (); file_close (); close ())
349
349
@@ -705,7 +705,7 @@ let assert_failure msg =
705
705
(* 0 *) failwith ("OUnit: " ^ msg)
706
706
707
707
let assert_bool msg b =
708
- (* 2009418 *) if not b then (* 0 *) assert_failure msg
708
+ (* 2009421 *) if not b then (* 0 *) assert_failure msg
709
709
710
710
let assert_string str =
711
711
(* 0 *) if not (str = "") then (* 0 *) assert_failure str
@@ -951,7 +951,7 @@ let (@?) = assert_bool
951
951
952
952
(* Some shorthands which allows easy test construction *)
953
953
let (>:) s t = (* 0 *) TestLabel(s, t) (* infix *)
954
- let (>::) s f = (* 153 *) TestLabel(s, TestCase(f)) (* infix *)
954
+ let (>::) s f = (* 154 *) TestLabel(s, TestCase(f)) (* infix *)
955
955
let (>:::) s l = (* 23 *) TestLabel(s, TestList(l)) (* infix *)
956
956
957
957
(* Utility function to manipulate test *)
@@ -1087,7 +1087,7 @@ let maybe_backtrace = ""
1087
1087
(* Run all tests, report starts, errors, failures, and return the results *)
1088
1088
let perform_test report test =
1089
1089
(* 1 *) let run_test_case f path =
1090
- (* 153 *) try
1090
+ (* 154 *) try
1091
1091
f ();
1092
1092
RSuccess path
1093
1093
with
@@ -1106,22 +1106,22 @@ let perform_test report test =
1106
1106
let rec flatten_test path acc =
1107
1107
function
1108
1108
| TestCase(f) ->
1109
- (* 153 *) (path, f) :: acc
1109
+ (* 154 *) (path, f) :: acc
1110
1110
1111
1111
| TestList (tests) ->
1112
1112
(* 23 *) fold_lefti
1113
1113
(fun acc t cnt ->
1114
- (* 175 *) flatten_test
1114
+ (* 176 *) flatten_test
1115
1115
((ListItem cnt)::path)
1116
1116
acc t)
1117
1117
acc tests
1118
1118
1119
1119
| TestLabel (label, t) ->
1120
- (* 176 *) flatten_test ((Label label)::path) acc t
1120
+ (* 177 *) flatten_test ((Label label)::path) acc t
1121
1121
in
1122
1122
let test_cases = List.rev (flatten_test [] [] test) in
1123
1123
let runner (path, f) =
1124
- (* 153 *) let result =
1124
+ (* 154 *) let result =
1125
1125
report (EStart path);
1126
1126
run_test_case f path
1127
1127
in
@@ -1130,18 +1130,18 @@ let perform_test report test =
1130
1130
result
1131
1131
in
1132
1132
let rec iter state =
1133
- (* 154 *) match state.tests_planned with
1133
+ (* 155 *) match state.tests_planned with
1134
1134
| [] ->
1135
1135
(* 1 *) state.results
1136
1136
| _ ->
1137
- (* 153 *) let (path, f) = !global_chooser state in
1137
+ (* 154 *) let (path, f) = !global_chooser state in
1138
1138
let result = runner (path, f) in
1139
1139
iter
1140
1140
{
1141
1141
results = result :: state.results;
1142
1142
tests_planned =
1143
1143
List.filter
1144
- (fun (path', _) -> (* 11781 *) path <> path') state.tests_planned
1144
+ (fun (path', _) -> (* 11935 *) path <> path') state.tests_planned
1145
1145
}
1146
1146
in
1147
1147
iter {results = []; tests_planned = test_cases}
@@ -1171,7 +1171,7 @@ let run_test_tt ?verbose test =
1171
1171
time_fun
1172
1172
perform_test
1173
1173
(fun ev ->
1174
- (* 459 *) log (OUnitLogger.TestEvent ev))
1174
+ (* 462 *) log (OUnitLogger.TestEvent ev))
1175
1175
test
1176
1176
in
1177
1177
@@ -8986,6 +8986,15 @@ val exclude_tail : 'a list -> 'a * 'a list
8986
8986
8987
8987
val length_compare : 'a list -> int -> [`Gt | `Eq | `Lt ]
8988
8988
8989
+ (**
8990
+
8991
+ {[length xs = length ys + n ]}
8992
+ input n should be positive
8993
+ TODO: input checking
8994
+ *)
8995
+
8996
+ val length_larger_than_n :
8997
+ int -> 'a list -> 'a list -> bool
8989
8998
8990
8999
val filter_map2 : ('a -> 'b -> 'c option) -> 'a list -> 'b list -> 'c list
8991
9000
@@ -9270,14 +9279,25 @@ let try_take n l =
9270
9279
9271
9280
9272
9281
let rec length_compare l n =
9273
- (* 13 *) if n < 0 then (* 2 *) `Gt
9282
+ (* 19 *) if n < 0 then (* 2 *) `Gt
9274
9283
else
9275
- (* 11 *) begin match l with
9276
- | _ ::xs -> (* 8 *) length_compare xs (n - 1)
9284
+ (* 17 *) begin match l with
9285
+ | _ ::xs -> (* 11 *) length_compare xs (n - 1)
9277
9286
| [] ->
9278
- (* 3 *) if n = 0 then (* 2 *) `Eq
9287
+ (* 6 *) if n = 0 then (* 5 *) `Eq
9279
9288
else (* 1 *) `Lt
9280
9289
end
9290
+ (**
9291
+
9292
+ {[length xs = length ys + n ]}
9293
+ *)
9294
+ let rec length_larger_than_n n xs ys =
9295
+ (* 6 *) match xs, ys with
9296
+ | _, [] -> (* 3 *) length_compare xs n = `Eq
9297
+ | _::xs, _::ys ->
9298
+ (* 3 *) length_larger_than_n n xs ys
9299
+ | [], _ -> (* 0 *) false
9300
+
9281
9301
9282
9302
9283
9303
let exclude_tail (x : 'a list) =
@@ -9542,6 +9562,15 @@ let suites =
9542
9562
(Ext_list.length_compare [] (-1)) `Gt ;
9543
9563
OUnit.assert_equal
9544
9564
(Ext_list.length_compare [] (0)) `Eq ;
9565
+ end;
9566
+ __LOC__ >:: begin fun _ ->
9567
+ (* 1 *) OUnit.assert_bool __LOC__
9568
+ (Ext_list.length_larger_than_n 1 [1;2] [1]);
9569
+ OUnit.assert_bool __LOC__
9570
+ (Ext_list.length_larger_than_n 0 [1;2] [1;2]);
9571
+ OUnit.assert_bool __LOC__
9572
+ (Ext_list.length_larger_than_n 2 [1;2] [])
9573
+
9545
9574
end
9546
9575
9547
9576
]
0 commit comments