65 lines
1.7 KiB
Scheme
65 lines
1.7 KiB
Scheme
(use-modules (d-)
|
|
(d- test)
|
|
(srfi srfi-1))
|
|
|
|
(define-test-suite "~>"
|
|
(define-test "unwrapped"
|
|
(define value (~> 1 1+ 1+))
|
|
(assert-equal 3 value))
|
|
(define-test "wrapped"
|
|
(define value (~> 1 (/ 2) (/ 2)))
|
|
(assert-equal 1/4 value)))
|
|
|
|
(define-test-suite "~>>"
|
|
(define-test "unwrapped"
|
|
(define value (~>> 1 1+ 1+))
|
|
(assert-equal 3 value))
|
|
(define-test "wrapped"
|
|
(define value (~>> 1 (/ 2) (/ 2)))
|
|
(assert-equal 1 value)))
|
|
|
|
(define-test-suite "if-not"
|
|
(define-test "test"
|
|
(assert-equal 'a (if-not #f 'a 'b))))
|
|
|
|
(define-test-suite "when-not"
|
|
(define-test "positive-case"
|
|
(assert-equal 'return (when-not #f 'do-some-stuff 'return)))
|
|
(define-test "negative-case"
|
|
(assert-unspecified (when-not #t 'do-some-stuff 'return))))
|
|
|
|
(define-test-suite "for"
|
|
(define-test "permutation"
|
|
(define value (for ([i (iota 2)]
|
|
[j (iota 2)])
|
|
(cons i j)))
|
|
(assert-equal '((0 . 0) (0 . 1) (1 . 0) (1 . 1)) value)))
|
|
|
|
(define-test-suite "if-let"
|
|
(define-test "positive-case"
|
|
(assert-equal 2 (if-let ([v (or #f 1)]) (+ v 1))))
|
|
(define-test "negative-case"
|
|
(assert-equal #f (if-let ([v (and #f 1)]) (+ v 1)))))
|
|
|
|
(define-test-suite "partial"
|
|
(define-test "test"
|
|
(define value (partial / 2))
|
|
(assert-equal 1/2 (value 4))
|
|
(assert-equal 2 (value 1))))
|
|
|
|
(define-test-suite "argmin"
|
|
(define-test "test"
|
|
(assert-equal '(b . 2) (argmin cdr < '(a . 5) '(b . 2) '(c . 3)))))
|
|
|
|
(define-test-suite "generator"
|
|
(define-test "test"
|
|
(define number-generator
|
|
(generator
|
|
(let loop ([i 1])
|
|
(yield i)
|
|
(loop (1+ i)))))
|
|
(assert-equal 1 (number-generator))
|
|
(assert-equal 2 (number-generator))
|
|
(assert-equal 3 (number-generator))
|
|
(assert-equal 4 (number-generator))))
|