Skip to content

Commit

Permalink
Switches from fiasco to fiveam test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
weslleymberg committed Apr 2, 2019
1 parent 7072d93 commit 62c4339
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*~
*~
*.fasl
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cache:

install:
- curl -L https://raw.githubusercontent.com/roswell/roswell/release/scripts/install-for-ci.sh | sh
- ros install fiasco
- ros install fiveam

script:
- ros -l cl-transducer.asd -e "(or (asdf:test-system :cl-transducer) (uiop:quit -1))"
- ros -l cl-transducer.asd -s cl-transducer/tests -e "(in-package :cl-transducer-tests)" -e "(or (run-all-tests) (uiop:quit -1))"
8 changes: 3 additions & 5 deletions cl-transducer.asd
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
:serial t
:pathname "src"
:components ((:file "packages")
(:file "transducer"))
:in-order-to ((test-op (test-op "cl-transducer/tests"))))
(:file "transducer")))

(asdf:defsystem #:cl-transducer/tests
:description "Test suite for cl-transducer"
:depends-on ("cl-transducer" "fiasco")
:depends-on ("cl-transducer" "fiveam")
:pathname "t"
:components ((:file "test"))
:perform (test-op (o c) (symbol-call :fiasco '#:run-tests :cl-transducer-test)))
:components ((:file "test")))
3 changes: 2 additions & 1 deletion src/packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
(:export #:tmap
#:tfilter
#:flip
#:combine))
#:combine
#:transducer))
4 changes: 4 additions & 0 deletions src/transducer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ from last to fisrt.
(reduce (lambda (acc x) (funcall x acc)) funcs
:initial-value base))

(defmacro transducer (init-value base &rest funcs)
(let ((arg (gensym)))
`(lambda (,arg) (reduce (combine ,base ,@funcs) ,arg :initial-value ,init-value))))

#+nil
(let ((even (tfilter evenp))
(plus-1 (tmap 1+)))
Expand Down
16 changes: 11 additions & 5 deletions t/test.lisp
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
(fiasco:define-test-package #:cl-transducer-test
(:use #:cl-transducer))
(defpackage #:cl-transducer-tests
(:use #:5AM #:cl #:cl-transducer))

(in-package #:cl-transducer-test)
(in-package #:cl-transducer-tests)

(deftest test-reduce-to-a-single-output ()
(def-suite* transducer-suite :description "cl-transducer test suite.")

(test reduce-to-a-single-output ()
(let ((input '(1 2 3 4))
(reducer (combine #'+ (tmap 1+) (tfilter evenp))))
(is (equal 8 (reduce reducer input :initial-value 0)))))

(deftest test-reduce-to-list ()
(test reduce-to-list ()
(is (equal '(2 4) (reverse (reduce (combine (flip cons)
(tmap incf)
(tfilter oddp))
'(1 2 3 4)
:initial-value nil)))))

(test transducer-macro ()
(let ((transd (transducer 0 #'+ (tmap 1+) (tfilter evenp))))
(is (equal 8 (funcall transd '(1 2 3 4))))))

0 comments on commit 62c4339

Please sign in to comment.