programming_languages/sml/week1/date_tests.sml

100 lines
2.3 KiB
Standard ML
Raw Normal View History

2020-05-31 18:35:01 +03:00
use "test.sml";
use "date.sml";
2020-06-01 01:55:44 +03:00
val () =
assert
2020-05-31 18:35:01 +03:00
(is_older ((1999, 12, 31), (1999, 12, 31)) = false)
"is_older: same dates evaluates to false"
2020-06-01 01:55:44 +03:00
val () =
assert
2020-05-31 18:35:01 +03:00
(is_older ((2000, 11, 28), (2000, 11, 29)) = true)
"is_older: first date older than second by day"
2020-06-01 01:55:44 +03:00
val () =
assert
2020-05-31 18:35:01 +03:00
(is_older ((1999, 12, 31), (1999, 11, 31)) = false)
"is_older: first date greater by month"
2020-06-01 01:55:44 +03:00
val () =
assert
2020-05-31 18:35:01 +03:00
(is_older ((1999, 12, 31), (1999, 11, 31)) = false)
"is_older: first date greater by month"
2020-06-01 01:55:44 +03:00
val () =
assert
2020-05-31 18:35:01 +03:00
(is_older ((2000, 12, 31), (1999, 12, 31)) = false)
"is_older: first date greater by year"
2020-06-01 01:55:44 +03:00
val () =
assert
2020-05-31 18:35:01 +03:00
(number_in_month ([(2000, 12, 31)], 12) = 1)
"number_in_month: one date with exact month"
2020-06-01 01:55:44 +03:00
val () =
2020-05-31 18:35:01 +03:00
let
val dates = [(2000, 12, 31), (2000, 12, 31)]
val month = 12
val expect = 2
in
2020-06-01 01:55:44 +03:00
assert
2020-05-31 18:35:01 +03:00
(number_in_month (dates, month) = expect)
"number_in_month: two date with exact month"
end
2020-06-01 01:55:44 +03:00
val () =
let
val dates = [(2000, 11, 31), (2000, 12, 31)]
val month = 11
val expect = 1
in
assert
(number_in_month (dates, month) = expect)
"number_in_month: two date but only one matches"
end
val () =
2020-05-31 18:35:01 +03:00
let
val dates = []
val month = 12
val expect = 0
in
2020-06-01 01:55:44 +03:00
assert
2020-05-31 18:35:01 +03:00
(number_in_month (dates, month) = expect)
2020-06-01 01:55:44 +03:00
"number_in_month: empty list should return 0"
end
val () =
let
val dates = []
val months = []
val expect = 0
in
assert
(number_in_months (dates, months) = expect)
"number_in_months: empty list should return 0"
end
val () =
let
val dates = [(2000, 11, 31), (2000, 11, 31)]
val months = [11]
val expect = 2
in
assert
(number_in_months (dates, months) = expect)
"number_in_months: one month matches with two dates"
end
val () =
let
val dates = [(2000, 11, 31), (2000, 12, 31), (2000, 12, 31)]
val months = [11, 12]
val expect = 3
in
assert
(number_in_months (dates, months) = expect)
"number_in_months: multiple dates with same month"
2020-05-31 18:35:01 +03:00
end
val () = complete ()