summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2016-12-27 14:17:42 -0600
committerChristopher Allan Webber <cwebber@dustycloud.org>2016-12-28 10:11:11 -0600
commitb387687cfe0aea2f5461bb211b627ce072364ad4 (patch)
tree7a4804e38d2d7d6efe016b26f6bcfae1c298750a /tests
parent6a8dc6f801cc08e1b92dce53fc8a3758c9b0718a (diff)
download8sync-b387687cfe0aea2f5461bb211b627ce072364ad4.tar.gz
agenda: Major cleanup.
* 8sync/agenda.scm (<agenda>, make-agenda, agenda-time): Move from being an immutable-record-type to just a regular one. Add set-agenda-queue! and remove time slot. (time-from-float-or-fraction, time-segment-right-format, <time-delta>) (make-time-delta, tdelta, time-delta+, 8usleep): Removed. (schedule-add!, schedule-segments-split): Remove let shadowing of time. There's no need to always convert the time format since it should now be correct by the time it gets here. (delayed-time): New variable. (run-delay, 8sleep): Use delayed-time. (update-agenda-from-select!): Use gettimeofday instead of agenda-time. (start-agenda): Remove get-time and handle-ports keyword arguments. Simplify loop considerably. (agenda-run-once!): Renamed from agenda-run-once. Simplify the enqueue part of the code since we've constrained what an acceptable time value looks like. Use set-agenda-queue!. * tests/test-agenda: Update for changes to agenda.scm.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-agenda.scm46
1 files changed, 22 insertions, 24 deletions
diff --git a/tests/test-agenda.scm b/tests/test-agenda.scm
index 8d5b524..013bce7 100644
--- a/tests/test-agenda.scm
+++ b/tests/test-agenda.scm
@@ -26,6 +26,10 @@
(test-begin "test-agenda")
+(define-syntax-rule (%import var)
+ (define var
+ (@@ (8sync agenda) var)))
+
;;; Helpers
@@ -58,6 +62,11 @@
;;; Timer tests
;;; ===========
+(%import time=)
+(%import time<)
+(%import time-minus)
+(%import time-plus)
+
(test-assert (time= '(1 . 1) '(1 . 1)))
(test-assert (not (time= '(1 . 1) '(1 . 0))))
(test-assert (not (time= '(0 . 1) '(1 . 1))))
@@ -68,22 +77,6 @@
(test-assert (not (time< '(7 . 8) '(7 . 2))))
(test-assert (not (time< '(8 . 2) '(7 . 2))))
-(let ((tdelta (make-time-delta 8)))
- (test-assert (time-delta? tdelta))
- (test-eqv (time-delta-sec tdelta) 8)
- (test-eqv (time-delta-usec tdelta) 0)
- (test-equal
- (time-delta+ '(2 . 3) tdelta)
- '(10 . 3)))
-
-(let ((tdelta (make-time-delta '(10 . 1))))
- (test-assert (time-delta? tdelta))
- (test-eqv (time-delta-sec tdelta) 10)
- (test-eqv (time-delta-usec tdelta) 1)
- (test-equal
- (time-delta+ '(2 . 3) tdelta)
- '(12 . 4)))
-
(test-equal (time-minus '(100 . 100) '(50 . 66))
'(50 . 34))
(test-equal (time-minus '(2 . 0) '(0 . 1))
@@ -99,6 +92,9 @@
;;; Schedule tests
;;; ==============
+(%import time-segment-time)
+(%import time-segment-queue)
+
;; helpers
(define (assert-times-expected time-segments expected-times)
(test-equal (map time-segment-time time-segments)
@@ -115,7 +111,7 @@
(test-assert (schedule-empty? sched))
;; Add a segment at (10 . 0)
-(schedule-add! sched 10 a-proc)
+(schedule-add! sched '(10 . 0) a-proc)
(test-assert (not (schedule-empty? sched)))
(test-equal (length (schedule-segments sched)) 1)
(test-equal (time-segment-time (car (schedule-segments sched)))
@@ -147,7 +143,7 @@
'((10 . 0)))
;; Add a segment to (11 . 0), (8 . 1) and (10 . 10)
-(schedule-add! sched 11 c-proc)
+(schedule-add! sched '(11 . 0) c-proc)
(schedule-add! sched '(8 . 1) d-proc)
(schedule-add! sched '(10 . 10) e-proc)
(test-assert (not (schedule-empty? sched)))
@@ -162,7 +158,7 @@
(assert-times-expected segments-before expected-before)
(assert-times-expected segments-after expected-after)))
-(test-split-at sched 0
+(test-split-at sched '(0 . 0)
'()
'((8 . 1) (10 . 0) (10 . 10) (11 . 0)))
(test-split-at sched '(8 . 0)
@@ -171,13 +167,13 @@
(test-split-at sched '(8 . 1)
'((8 . 1))
'((10 . 0) (10 . 10) (11 . 0)))
-(test-split-at sched 9
+(test-split-at sched '(9 . 0)
'((8 . 1))
'((10 . 0) (10 . 10) (11 . 0)))
-(test-split-at sched 10
+(test-split-at sched '(10 . 0)
'((8 . 1) (10 . 0))
'((10 . 10) (11 . 0)))
-(test-split-at sched 9000
+(test-split-at sched '(9000 . 0)
'((8 . 1) (10 . 0) (10 . 10) (11 . 0))
'())
(test-split-at sched '(9000 . 1) ; over nine thousaaaaaaand
@@ -186,7 +182,7 @@
;; Break off half of those and do some tests on them
(define some-extracted
- (schedule-extract-until! sched 10))
+ (schedule-extract-until! sched '(10 . 0)))
(assert-times-expected some-extracted '((8 . 1) (10 . 0)))
(assert-times-expected (schedule-segments sched) '((10 . 10) (11 . 0)))
(define first-extracted-queue
@@ -267,8 +263,10 @@
(define (true-after-n-times n)
(let ((count 0))
(lambda _
+ (define ans
+ (if (>= count n) #t #f))
(set! count (+ count 1))
- (if (>= count n) #t #f))))
+ ans)))
;; the dummy test