Skip to content

Commit

Permalink
Added more tests for format string parsing stuff, slight code refacto…
Browse files Browse the repository at this point in the history
…ring in timedesc/timedesc.ml
  • Loading branch information
darrenldl committed Apr 4, 2023
1 parent 43d40d5 commit 19a58ef
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
10 changes: 10 additions & 0 deletions timedesc-tests/date_time_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,15 @@ module Qc = struct
let ns' = Timedesc.ns d in
hour = hour' && minute = minute' && second = second' && ns = ns')

let to_string_does_not_crash =
QCheck.Test.make ~count:100_000 ~name:"to_string_does_not_crash" timestamp (fun ts ->
let dt =
Timedesc.of_timestamp_exn ~tz_of_date_time:Timedesc.Time_zone.utc ts
in
Timedesc.to_string dt |> ignore;
true
)

let suite =
[
to_rfc3339_nano_of_iso8601_is_lossless;
Expand All @@ -747,5 +756,6 @@ module Qc = struct
iso_week_date_accessors;
ymd_date_accessors;
time_accessors;
to_string_does_not_crash;
]
end
19 changes: 19 additions & 0 deletions timedesc-tests/interval_tests.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
open Test_utils

module Alco = struct
let suite = []
end

module Qc = struct
let to_string_does_not_crash =
QCheck.Test.make ~count:100_000 ~name:"to_string_does_not_crash"
QCheck.(pair timestamp timestamp) (fun (ts1, ts2) ->
Timedesc.Interval.to_string (ts1, ts2) |> ignore;
true
)

let suite =
[
to_string_does_not_crash;
]
end
2 changes: 2 additions & 0 deletions timedesc-tests/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let () =
("Ym_tests.Alco", Ym_tests.Alco.suite);
("ISO_week_tests.Alco", ISO_week_tests.Alco.suite);
("Date_time_tests.Alco", Date_time_tests.Alco.suite);
("Interval_tests.Alco", Interval_tests.Alco.suite);
("Date_time_util_tests.Alco", Date_time_util_tests.Alco.suite);
("Tzdb_tests.Alco", Tzdb_tests.Alco.suite);
]
Expand All @@ -19,6 +20,7 @@ let () =
("Ym_tests.Qc", Ym_tests.Qc.suite);
("ISO_week_tests.Qc", ISO_week_tests.Qc.suite);
("Date_time_tests.Qc", Date_time_tests.Qc.suite);
("Interval_tests.Qc", Interval_tests.Qc.suite);
("Date_time_util_tests.Qc", Date_time_util_tests.Qc.suite);
("Ptime_tests.Qc", Ptime_tests.Qc.suite);
("Time_zone_tests.Qc", Time_zone_tests.Qc.suite);
Expand Down
14 changes: 14 additions & 0 deletions timedesc-tests/span_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,18 @@ module Qc = struct
in
Timedesc.Span.equal s s')

let to_string_does_not_crash =
QCheck.Test.make ~count:100_000 ~name:"to_string_does_not_crash" timestamp (fun s ->
Timedesc.Span.to_string s |> ignore;
true
)

let for_human_to_string_does_not_crash =
QCheck.Test.make ~count:100_000 ~name:"for_human_to_string_does_not_crash" timestamp (fun s ->
Timedesc.Span.For_human.to_string s |> ignore;
true
)

let suite =
[
make_is_lossless;
Expand Down Expand Up @@ -481,5 +493,7 @@ module Qc = struct
accessors;
of_to_view;
to_of_sexp;
to_string_does_not_crash;
for_human_to_string_does_not_crash;
]
end
6 changes: 3 additions & 3 deletions timedesc/timedesc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,18 @@ end
module Interval = struct
type t = timestamp * timestamp

let equal (x1, y1) (x2, y2) = Span.(x1 = x2 && y1 = y2)

let lt (x1, y1) (x2, y2) =
(* lexicographic order *)
Span.(x1 < x2 || (x1 = x2 && y1 < y2))

let le x y = lt x y || x = y
let le x y = lt x y || equal x y

let gt x y = lt y x

let ge x y = le y x

let equal (x1, y1) (x2, y2) = Span.(x1 = x2 && y1 = y2)

let compare x y = if lt x y then -1 else if x = y then 0 else 1

let pp = Printers.pp_interval
Expand Down

0 comments on commit 19a58ef

Please sign in to comment.