blob: 256c01bf3494d04c6afa8acdaa7c58d692107bd6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
(define-module (test timespec)
:use-module (srfi srfi-64)
:use-module (srfi srfi-88)
:use-module (datetime)
:use-module (datetime timespec))
(test-equal "The empty string parses to the empty timespec"
(timespec-zero) (parse-time-spec ""))
(test-group "timespec-add"
(test-equal "Zero operands gives 0"
(timespec-zero) (timespec-add))
(let ((ts (make-timespec #10:20:30 '- #\z)))
(test-equal "Single operand gives that operand"
ts (timespec-add ts)))
(test-equal "0 + 0 = 0"
(timespec-zero) (timespec-add (timespec-zero) (timespec-zero)))
(test-group
"+ -"
(test-equal "Remove a number less than the base"
(make-timespec #10:00:00 '+ #\w)
(timespec-add (make-timespec #10:20:30 '+ #\w)
(make-timespec #00:20:30 '- #\w)))
(test-equal "Remove a number greater than the base"
(make-timespec #01:00:00 '- #\w)
(timespec-add (make-timespec #10:00:00 '+ #\w)
(make-timespec #11:00:00 '- #\w)))
(test-equal "x + -x = 0"
(timespec-zero) (timespec-add (make-timespec #10:20:30 '+ #\w)
(make-timespec #10:20:30 '- #\w))))
(test-group "- +"
(test-equal "Add a number less than the (negative) base"
(make-timespec #10:00:00 '+ #\w)
(timespec-add (make-timespec #10:20:30 '- #\w)
(make-timespec #00:20:30 '+ #\w)))
(test-equal "Add a number greater than the (negative) base"
(make-timespec #01:00:00 '- #\w)
(timespec-add (make-timespec #10:00:00 '- #\w)
(make-timespec #11:00:00 '+ #\w)))
(test-equal "-x + x = 0"
(timespec-zero) (timespec-add (make-timespec #10:20:30 '- #\w)
(make-timespec #10:20:30 '+ #\w))))
(test-group "+ +"
(test-equal "x + x = 2x"
(make-timespec #20:41:00 '+ #\w)
(timespec-add (make-timespec #10:20:30 '+ #\w)
(make-timespec #10:20:30 '+ #\w))))
(test-group "- -"
(test-equal "-x + -x = -2x"
(make-timespec #20:41:00 '- #\w)
(timespec-add (make-timespec #10:20:30 '- #\w)
(make-timespec #10:20:30 '- #\w))))
;; add more than two timespecs
;; add timespecs of differing types
)
(test-group "parse-time-spec"
;; TODO what even is this case?
(test-equal (make-timespec (time) '+ #\g) (parse-time-spec "-g"))
(test-equal "Parse direct date, with hour minute and second"
(make-timespec #20:00:00 '+ #\w) (parse-time-spec "20:00:00"))
(test-equal "Parse direct date, with hour and minute"
(make-timespec #20:00:00 '+ #\w) (parse-time-spec "20:00"))
(test-equal "Parse direct date, with just hour"
(make-timespec #20:00:00 '+ #\w) (parse-time-spec "20"))
(test-equal "Parse timespec with letter at end"
(make-timespec #20:00:00 '+ #\g) (parse-time-spec "20:00g"))
(test-equal "Parse negative timespec"
(make-timespec #20:00:00 '- #\w) (parse-time-spec "-20"))
(test-equal "Parse negative timespec with letter at end"
(make-timespec #20:00:00 '- #\z) (parse-time-spec "-20z")))
|