From 10d6dfd0de4ca42fb6a493bb905c64a4ba2ca9ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 28 Jun 2022 16:22:08 +0200 Subject: Add time[+-] overflow tests. --- tests/test/datetime.scm | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/test/datetime.scm b/tests/test/datetime.scm index b1501adb..2a5ac141 100644 --- a/tests/test/datetime.scm +++ b/tests/test/datetime.scm @@ -760,7 +760,30 @@ date/-time> date/-time>? date/-time>= date/-time>=? (test-equal "Add" #22:00:00 (time+ #20:00:00 (time hour: 2))) (test-equal "Remove" #20:00:00 (time- #22:00:00 (time hour: 2))))) - )) + (test-group "Overflowing cases" + (test-group "Addition" + (test-group "Single overflow" + (call-with-values (lambda () (time+ #20:00:00 (time hour: 5))) + (lambda (result overflow) + (test-equal "Time" (time hour: 1) result) + (test-equal "Overflow" 1 overflow)))) + (test-group "Mulitple overflows" + (call-with-values (lambda () (time+ #20:00:00 (time hour: 5) (time hour: 24))) + (lambda (result overflow) + (test-equal "Time" (time hour: 1) result) + (test-equal "Overflow" 2 overflow))))) + + (test-group "Subtraction" + (test-group "Single overflow" + (call-with-values (lambda () (time- #20:00:00 (time hour: 25))) + (lambda (result overflow) + (test-equal "Time" (time hour: 19) result) + (test-equal "Overflow" 1 overflow)))) + (test-group "Mulitple overflows" + (call-with-values (lambda () (time- (time hour: 4) (time hour: 10) (time hour: 24))) + (lambda (result overflow) + (test-equal "Time" (time hour: 18) result) + (test-equal "Overflow" 2 overflow)))))))) ;; TODO datetime+ datetime- -- cgit v1.2.3