aboutsummaryrefslogtreecommitdiff
path: root/tests/test.scm
blob: 6ce798e95482b584f3f16a72a1d14bbf10daadff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/guile \
-s
!#

(add-to-load-path (dirname (dirname (current-filename))))

(use-modules (srfi srfi-64))

(use-modules (monad)
             (monad optional))

(define (div d)
  (if (zero? d)
      (nothing)
      (just (/ 1 d))))

(test-begin "mapM-test")

(test-assert (equal? (mapM div '(1 2 3))
                     (just '(1 1/2 1/3))))

(test-assert (equal? (mapM div (map just '(1 2 3)))
                     (just '(1 1/2 1/3))))

;;; --------------------------------------------------

(test-assert (equal? (mapM div '(0 1 2 3))
                     (nothing)))

(test-assert (equal? (mapM div (map just '(0 1 2 3)))
                     (nothing)))

(test-end "mapM-test")

(test-begin "state-test")

(use-modules (monad state)
             (monad stack))

(test-equal (run-state (return-state 10) 20)
  '(10 20))

(test-equal
    (car
     (run-state
      (do let y = 7
          (modify (lambda (x) (+ x y)))
          (get))
      10))
  17)


(test-end "state-test")