From cabc854555d7b02bbac1361ca67c8e04f8035143 Mon Sep 17 00:00:00 2001 From: Kevin Ryde Date: Sun, 5 Dec 2004 22:15:54 +0000 Subject: [PATCH] (partition): New tests, by Matthias Koeppe. --- test-suite/tests/srfi-1.test | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test-suite/tests/srfi-1.test b/test-suite/tests/srfi-1.test index e88ffe989..cb6cc9151 100644 --- a/test-suite/tests/srfi-1.test +++ b/test-suite/tests/srfi-1.test @@ -415,3 +415,46 @@ (pass-if "(1 2) / (3 4) / (5 6)" (equal? '(9 12) (map + '(1 2) '(3 4) '(5 6)))))) +;; +;; partition +;; + +(define (test-partition pred list kept-good dropped-good) + (call-with-values (lambda () + (partition pred list)) + (lambda (kept dropped) + (and (equal? kept kept-good) + (equal? dropped dropped-good))))) + +(with-test-prefix "partition" + + (pass-if "with dropped tail" + (test-partition even? '(1 2 3 4 5 6 7) + '(2 4 6) '(1 3 5 7))) + + (pass-if "with kept tail" + (test-partition even? '(1 2 3 4 5 6) + '(2 4 6) '(1 3 5))) + + (pass-if "with everything dropped" + (test-partition even? '(1 3 5 7) + '() '(1 3 5 7))) + + (pass-if "with everything kept" + (test-partition even? '(2 4 6) + '(2 4 6) '())) + + (pass-if "with empty list" + (test-partition even? '() + '() '())) + + (pass-if "with reasonably long list" + ;; the old implementation from SRFI-1 reference implementation + ;; would signal a stack-overflow for a list of only 500 elements! + (call-with-values (lambda () + (partition even? + (make-list 10000 1))) + (lambda (even odd) + (and (= (length odd) 10000) + (= (length even) 0)))))) +