diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-03-07 15:31:00 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-03-07 20:29:14 +0100 |
commit | f7716ac1a87649cad96242f2d5bf0a987d7f430c (patch) | |
tree | b4b84951ef468fd644c42e9e0fee535d879f0387 /tests/test/datetime-util.scm | |
parent | Cleanup in (hnh util path). (diff) | |
download | calp-f7716ac1a87649cad96242f2d5bf0a987d7f430c.tar.gz calp-f7716ac1a87649cad96242f2d5bf0a987d7f430c.tar.xz |
Add new tests.
Diffstat (limited to '')
-rw-r--r-- | tests/test/datetime-util.scm | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/tests/test/datetime-util.scm b/tests/test/datetime-util.scm new file mode 100644 index 00000000..ca8a9241 --- /dev/null +++ b/tests/test/datetime-util.scm @@ -0,0 +1,182 @@ +;;; Commentary: +;; Tests timespan overlaps and month-streams. +;; Separate from tests/datetime.scm since +;; (datetime util) originally was its own module. +;;; Code: + +(define-module (test datetime-util) + :use-module (srfi srfi-64) + :use-module (srfi srfi-88) + :use-module ((datetime) + :select (date time + datetime + month-stream + in-date-range? + timespan-overlaps?)) + :use-module ((srfi srfi-41) + :select (stream->list stream-take))) + +(test-assert + "jan->dec" + (stream->list + (stream-take + 11 + (month-stream + #2020-01-01)))) + +(test-assert + "dec->jan" + (stream->list + (stream-take + 2 + (month-stream + #2020-12-01)))) + +(test-assert + "dec->feb" + (stream->list + (stream-take + 3 + (month-stream + #2020-12-01)))) + +(test-assert + "20 months" + (stream->list + (stream-take + 20 + (month-stream + #2020-01-01)))) + +(test-equal + "Correct months" + (list #2020-02-01 + #2020-03-01 + #2020-04-01 + #2020-05-01 + #2020-06-01 + #2020-07-01 + #2020-08-01 + #2020-09-01 + #2020-10-01 + #2020-11-01 + #2020-12-01 + #2021-01-01) + (stream->list + (stream-take + 12 + (month-stream + #2020-02-01)))) + +(test-assert + "in-date-range?" + (not ((in-date-range? + #2020-01-01 + #2020-02-29) + #2018-02-02))) + +(test-assert + "A" + (timespan-overlaps? + #2020-01-01 + #2020-01-10 + #2020-01-05 + #2020-01-15)) + +(test-assert + "A, shared start" + (timespan-overlaps? + #2020-01-01 + #2020-01-10 + #2020-01-01 + #2020-01-15)) + +(test-assert + "A, tangential" + (not (timespan-overlaps? + #2020-01-01T00:00:00 + #2020-01-10T00:00:00 + #2020-01-10T00:00:00 + #2020-01-30T00:00:00))) + +(test-assert + "s1 instant" + (timespan-overlaps? + #2020-01-15T10:00:00 + #2020-01-15T10:00:00 + #2020-01-10T00:00:00 + #2020-01-30T00:00:00)) + +(test-assert + "s2 instant" + (timespan-overlaps? + #2020-01-10T00:00:00 + #2020-01-30T00:00:00 + #2020-01-15T10:00:00 + #2020-01-15T10:00:00)) + +(test-assert + "s1 instant, shared start with s2" + (timespan-overlaps? + #2020-01-15T10:00:00 + #2020-01-15T10:00:00 + #2020-01-15T10:00:00 + #2020-01-30T00:00:00)) + +(test-assert + "s1 instant, shared end with s2" + (not (timespan-overlaps? + #2020-01-15T10:00:00 + #2020-01-15T10:00:00 + #2020-01-10T00:00:00 + #2020-01-15T10:00:00))) + +(test-assert + "s2 instant, shared start with s1" + (timespan-overlaps? + #2020-01-15T10:00:00 + #2020-01-30T00:00:00 + #2020-01-15T10:00:00 + #2020-01-15T10:00:00)) + +(test-assert + "s2 instant, shared end with s1" + (not (timespan-overlaps? + #2020-01-10T00:00:00 + #2020-01-15T10:00:00 + #2020-01-15T10:00:00 + #2020-01-15T10:00:00))) + +(test-assert + "both instant" + (not (timespan-overlaps? + #2020-01-15T10:00:00 + #2020-01-15T10:00:00 + #2020-01-15T10:00:00 + #2020-01-15T10:00:00))) + +(test-assert + "tangential whole day" + (not (timespan-overlaps? + #2020-01-01 + #2020-01-02 + #2020-01-02 + #2020-01-03))) + +(test-assert + "B" + (timespan-overlaps? + #2020-01-05 + #2020-01-15 + #2020-01-01 + #2020-01-10)) + +(test-assert + "E" + (timespan-overlaps? + #2020-01-01 + #2020-01-10 + #2020-01-01 + #2020-01-10)) + + |