From: Christopher Allan Webber Date: Sat, 28 Nov 2015 15:17:58 +0000 (-0600) Subject: Add queue helpers, with tests X-Git-Tag: v0.1.0~50 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=2cf0efca6f8abb4938cec1cc4d00bb96dcc4de87;p=8sync.git Add queue helpers, with tests --- diff --git a/eightsync/agenda.scm b/eightsync/agenda.scm index a2463a2..ede753f 100644 --- a/eightsync/agenda.scm +++ b/eightsync/agenda.scm @@ -30,6 +30,8 @@ make-async-prompt-tag + list->q make-q* + make-time-segment time-segment? time-segment-time time-segment-queue @@ -146,6 +148,19 @@ Generally done automatically for the user through (make-agenda)." "Can't get current agenda prompt if there's no current agenda!") (agenda-prompt-tag current-agenda)))) +;; helper for making queues for an agenda +(define (list->q lst) + "Makes a queue composed of LST items" + (let ((q (make-q))) + (for-each + (lambda (x) + (enq! q x)) + lst) + q)) + +(define (make-q* . args) + "Makes a queue and populates it with this invocation's ARGS" + (list->q args)) ;;; Schedule diff --git a/tests/test-agenda.scm b/tests/test-agenda.scm index 9ab65f1..ef2c74f 100644 --- a/tests/test-agenda.scm +++ b/tests/test-agenda.scm @@ -40,8 +40,25 @@ messages))) -;; Timer tests -;; =========== +;;; queue helpers +;;; ============= + +(define test-q (list->q '(1 2 3))) +(test-equal (deq! test-q) 1) +(test-equal (deq! test-q) 2) +(test-equal (deq! test-q) 3) +(test-assert (q-empty? test-q)) + +(define test-q (make-q* 'apple 'banana 'carrot)) +(test-equal (deq! test-q) 'apple) +(test-equal (deq! test-q) 'banana) +(test-equal (deq! test-q) 'carrot) +(test-assert (q-empty? test-q)) + + + +;;; Timer tests +;;; =========== (test-assert (time= '(1 . 1) '(1 . 1))) (test-assert (not (time= '(1 . 1) '(1 . 0))))