;;;; File: loops-test.scm ;;;; Author: Juergen Lorenz ;;;; ju (at) jugilo (dot) de ;;;; Date: Feb 16, 2011 ;;;; Mar 06, 2011 (require 'loops 'tests) (import loops (only tests dispatcher compare-with)) (define loops-test (dispatcher #f (do-times (compare-with equal? (let ((lst '())) (do-times i (+ 2 3) (set! lst (cons i lst))) lst) '(4 3 2 1 0))) (do-list (compare-with equal? (let ((lst '())) (do-list i '(1 2 3) (set! lst (cons i lst))) lst) '(3 2 1))) (do-for (compare-with equal? (let ((lst '())) (do-for i (1 5) (set! lst (cons i lst))) (reverse lst)) '(1 2 3 4) (let ((lst '())) (do-for i (1 65 i) (set! lst (cons i lst))) (reverse lst)) '(1 2 4 8 16 32 64))) (do-while (compare-with equal? (let ((n 4) (lst '())) (do-while (<= 0 n) (set! lst (cons n lst)) (set! n (- n 1))) lst) '(0 1 2 3 4))) (do-until (compare-with equal? (let ((n 4) (lst '())) (do-until (> 0 n) (set! lst (cons n lst)) (set! n (- n 1))) lst) '(0 1 2 3 4))) (do-forever (compare-with equal? (let ((n 3) (lst '())) (do-forever (if (zero? n) (exit lst)) (set! lst (cons 'a lst)) (set! n (- n 1)))) '(a a a)))))