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

33 lines
1 KiB
Text
Raw Normal View History

2014-07-10 01:19:14 +00:00
(defmodule unit-calrissian-maybe-monad-tests
2014-04-24 04:47:45 +00:00
(export all)
(import
(from lfeunit-util
(check-failed-assert 2)
(check-wrong-assert-exception 2))))
(include-lib "deps/lfeunit/include/lfeunit-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 01:19:14 +00:00
(test-monad 'calrissian-maybe-monad)
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 01:19:14 +00:00
(>>= 'calrissian-maybe-monad '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 01:19:14 +00:00
(>>= 'calrissian-maybe-monad '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 01:19:14 +00:00
(let ((minc (lambda (x) (return 'calrissian-maybe-monad (+ 1 x))))
(bind (lambda (f m) (>>= 'calrissian-maybe-monad m f))))
2014-04-24 04:47:45 +00:00
(lists:foldr bind
#(just 0)
(list minc
minc
minc)))))