calrissian/test/unit-calrissian-maybe-monad-tests.lfe

34 lines
1,023 B
Text
Raw Normal View History

2014-07-10 01:19:14 +00:00
(defmodule unit-calrissian-maybe-monad-tests
2014-08-22 02:40:41 +00:00
(behaviour ltest-unit)
2014-04-24 04:47:45 +00:00
(export all)
(import
2014-08-22 02:40:41 +00:00
(from ltest
2014-04-24 04:47:45 +00:00
(check-failed-assert 2)
(check-wrong-assert-exception 2))))
2014-08-22 02:40:41 +00:00
(include-lib "deps/ltest/include/ltest-macros.lfe")
2014-04-24 19:33:28 +00:00
(include-lib "include/monads.lfe")
2014-04-25 04:20:10 +00:00
(include-lib "include/monad-tests.lfe")
2014-04-24 04:47:45 +00:00
2014-07-10 02:28:06 +00:00
(test-monad (monad 'maybe))
2014-04-25 04:20:10 +00:00
(deftest nothing-short-circuits-value
2014-04-24 04:47:45 +00:00
(is-equal 'nothing
2014-07-10 02:28:06 +00:00
(>>= (monad 'maybe) 'nothing
2014-04-24 04:47:45 +00:00
(lambda (x) (+ 5 x)))))
(deftest nothing-short-circuits-error
2014-04-24 04:47:45 +00:00
(is-equal 'nothing
2014-07-10 02:28:06 +00:00
(>>= (monad 'maybe) 'nothing
2014-04-24 04:47:45 +00:00
(lambda (_) (error 'bad-func)))))
(deftest fold-increment-value
2014-04-24 04:47:45 +00:00
(is-equal #(just 3)
2014-07-10 02:28:06 +00:00
(let ((minc (lambda (x) (return (monad 'maybe) (+ 1 x))))
(bind (lambda (f m) (>>= (monad 'maybe) m f))))
2014-04-24 04:47:45 +00:00
(lists:foldr bind
#(just 0)
(list minc
minc
minc)))))