Prepare stats infrastructure.

This commit is contained in:
Dominik Pantůček 2023-03-19 18:30:09 +01:00
parent 15926d124e
commit cd2a08e2ec
2 changed files with 30 additions and 5 deletions

View file

@ -34,6 +34,7 @@
month=?
month<?
month-diff
month-add
month-tests!
)
@ -113,6 +114,12 @@
(error 'month-diff "Second argument is not a valid month" t))
(error 'month-diff "First argument is not a valid month" f)))
;; Returns a month n months after the month m.
(define (month-add m n)
(let ((mi (+ (* 12 (car m)) (cadr m) n)))
(list (quotient mi 12)
(remainder mi 12))))
;; Performs self-tests of the month module.
(define (month-tests!)
(run-tests
@ -136,6 +143,7 @@
(test-eq? month-diff (month-diff '(2023 1) '(2023 2)) 1)
(test-eq? month-diff (month-diff '(2023 1) '(2023 12)) 11)
(test-eq? month-diff (month-diff '(2023 1) '(2022 2)) -11)
(test-eq? month-add (month-add '(2023 1) 2) '(2023 3))
))
)