From 9e22d0dee6b14b6689815112b202ab4e4621eeac Mon Sep 17 00:00:00 2001 From: Colin Woodbury Date: Wed, 21 Dec 2022 09:30:50 +0900 Subject: [PATCH 3/3] srfi-171: add unit tests for new functions These tests mainly match the examples shown in the docs. --- test-suite/tests/srfi-171.test | 66 ++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/test-suite/tests/srfi-171.test b/test-suite/tests/srfi-171.test index 1ef7bc5f2..d1d54b2ec 100644 --- a/test-suite/tests/srfi-171.test +++ b/test-suite/tests/srfi-171.test @@ -207,15 +207,69 @@ (list-transduce (tenumerate (- 1)) rcons numeric-list))) (pass-if "tbatch" - (equal? - '((0 1) (2 3) (4)) + (equal? '((0 1) (2 3) (4)) (list-transduce (tbatch (ttake 2) rcons) rcons numeric-list))) (pass-if "tfold" - (equal? - '(0 1 3 6 10) - (list-transduce (tfold +) rcons numeric-list)))) - + (equal? '(0 1 3 6 10) + (list-transduce (tfold +) rcons numeric-list))) + + (pass-if "twindow: too wide of a window" + (equal? '() + (list-transduce (twindow 10) rcons '(1 2 3)))) + + (pass-if "twindow: acceptable window" + (equal? '((1 2 3) (2 3 4) (3 4 5)) + (list-transduce (twindow 3) rcons '(1 2 3 4 5))))) + +(with-test-prefix "reducers" + (pass-if "rfold: builtin" + (equal? 5 + (list-transduce (tfilter odd?) (rfold max 0) '(1 2 3 4 5)))) + + (pass-if "rfold: custom lambda" + (equal? "ghi" + (list-transduce (tmap identity) + (rfold (lambda (_ input) input) #f) + '("abc" "def" "ghi")))) + + (pass-if "rfirst: empty" + (equal? 0 + (list-transduce (tmap identity) (rfirst 0) '()))) + + (pass-if "rfirst: non-empty" + (equal? 1 + (list-transduce (tmap identity) (rfirst 0) '(1 2 3)))) + + (pass-if "rlast: empty" + (equal? 0 + (list-transduce (tfilter (lambda (_) #f)) (rlast 0) '(1 2 3)))) + + (pass-if "rlast: non-empty" + (equal? 5 + (list-transduce (tmap identity) (rlast 0) '(1 2 3 4 5)))) + + (pass-if "rmax: empty" + (equal? 0 + (list-transduce (tmap identity) (rmax 0) '()))) + + (pass-if "rmax: non-empty" + (equal? 31 + (list-transduce (tmap identity) (rmax 0) '(1 2 31 4 5)))) + + (pass-if "rmin: empty" + (equal? 0 + (list-transduce (tmap identity) (rmin 0) '()))) + + (pass-if "rmin: non-empty" + (equal? 1 + (list-transduce (tmap identity) (rmin 1000) '(5 3 1 7 6)))) + + (pass-if "rfind" + (equal? "Jack" + (list-transduce (tmap identity) + (rfind string?) + '(1 c #t 4.12 "Jack" ()))))) (with-test-prefix "x-transduce" (pass-if "list-transduce" -- 2.39.0