X-Git-Url: https://jxself.org/git/?p=8sync.git;a=blobdiff_plain;f=tests.scm;h=0843fb4b8ab484d475b33cf9f3895fa71b7bfea5;hp=b865ca809bb728c6798db8a25b1e3e9bc6fa9cdc;hb=9ed57ce7714e4228941d689aa717196d3280db43;hpb=e0499fb27f966a6c81679e9d83260164197e5ff7 diff --git a/tests.scm b/tests.scm index b865ca8..0843fb4 100644 --- a/tests.scm +++ b/tests.scm @@ -14,15 +14,31 @@ ;; Timer tests ;; =========== -(test-assert (time-= '(1 . 1) '(1 . 1))) -(test-assert (not (time-= '(1 . 1) '(1 . 0)))) -(test-assert (not (time-= '(0 . 1) '(1 . 1)))) - -(test-assert (time-< '(1 . 1) '(1 . 2))) -(test-assert (time-< '(7 . 2) '(8 . 2))) -(test-assert (not (time-< '(7 . 2) '(7 . 2)))) -(test-assert (not (time-< '(7 . 8) '(7 . 2)))) -(test-assert (not (time-< '(8 . 2) '(7 . 2)))) +(test-assert (time= '(1 . 1) '(1 . 1))) +(test-assert (not (time= '(1 . 1) '(1 . 0)))) +(test-assert (not (time= '(0 . 1) '(1 . 1)))) + +(test-assert (time< '(1 . 1) '(1 . 2))) +(test-assert (time< '(7 . 2) '(8 . 2))) +(test-assert (not (time< '(7 . 2) '(7 . 2)))) +(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))) @@ -45,7 +61,7 @@ (test-assert (schedule-empty? sched)) ;; Add a segment at (10 . 0) -(schedule-add! 10 a-proc sched) +(schedule-add! sched 10 a-proc) (test-assert (not (schedule-empty? sched))) (test-equal (length (schedule-segments sched)) 1) (test-equal (time-segment-time (car (schedule-segments sched))) @@ -62,7 +78,7 @@ '((10 . 0))) ;; Add another segment at (10 . 0) -(schedule-add! '(10 . 0) b-proc sched) +(schedule-add! sched '(10 . 0) b-proc) (test-assert (not (schedule-empty? sched))) (test-equal (length (schedule-segments sched)) 1) (test-equal (time-segment-time (car (schedule-segments sched))) @@ -77,9 +93,9 @@ '((10 . 0))) ;; Add a segment to (11 . 0), (8 . 1) and (10 . 10) -(schedule-add! 11 c-proc sched) -(schedule-add! '(8 . 1) d-proc sched) -(schedule-add! '(10 . 10) e-proc sched) +(schedule-add! sched 11 c-proc) +(schedule-add! sched '(8 . 1) d-proc) +(schedule-add! sched '(10 . 10) e-proc) (test-assert (not (schedule-empty? sched))) (test-equal (length (schedule-segments sched)) 4) (assert-times-expected (schedule-segments sched) @@ -134,7 +150,7 @@ ;; Add one more and test flattening to a queue (test-assert (not (schedule-empty? sched))) -(schedule-add! '(10 . 10) f-proc sched) +(schedule-add! sched '(10 . 10) f-proc) (define remaining-segments (schedule-extract-until! sched '(9000 . 1))) (test-assert (schedule-empty? sched)) @@ -184,11 +200,51 @@ (test-equal (run-request-when run-two-squared) '(88 . 0))) -;; Agenda tests -;; ------------ - +;;; Agenda tests +;;; ------------ +;; helpers +(define (speak-it) + (let ((messages '())) + (lambda* (#:optional message) + (if message (set! messages (append messages (list message)))) + messages))) + +(define (true-after-n-times n) + (let ((count 0)) + (lambda _ + (set! count (+ count 1)) + (if (>= count n) #t #f)))) + +;; the dummy test + +(define speaker (speak-it)) + +(define (dummy-func) + (speaker "I'm a dummy\n")) + +(define (run-dummy) + (speaker "I bet I can make you say you're a dummy!\n") + (run dummy-func)) + +(let ((q (make-q))) + (set! speaker (speak-it)) ; reset the speaker + (enq! q run-dummy) + (start-agenda (make-agenda #:queue q) + #:stop-condition (true-after-n-times 2)) + (test-equal (speaker) + '("I bet I can make you say you're a dummy!\n" + "I'm a dummy\n"))) + +;; should only do the first one after one round though +(let ((q (make-q))) + (set! speaker (speak-it)) ; reset the speaker + (enq! q run-dummy) + (start-agenda (make-agenda #:queue q) + #:stop-condition (true-after-n-times 1)) + (test-equal (speaker) + '("I bet I can make you say you're a dummy!\n"))) ;; End tests