(module test mzscheme (require "combinators.ss" (lib "list.ss") (lib "math.ss") (planet "test.ss" ("schematics" "schemeunit.plt" 2)) (planet "graphical-ui.ss" ("schematics" "schemeunit.plt" 2))) (test/graphical-ui (test-suite "combinators.plt" (test-suite "curry" (test-case "1 2 / 3 4" (check-equal? ((curry list 1 2) 3 4) (list 1 2 3 4)))) (test-suite "yrruc" (test-case "1 2 / 3 4" (check-equal? ((yrruc list 1 2) 3 4) (list 3 4 1 2)))) (test-suite "constant" (test-case "symbol" (check-eq? ((constant 'symbol) 3 'other "values") 'symbol))) (test-suite "compose/apply" (test-case "reverse-evens" (check-equal? ((compose/apply (lambda args (reverse args)) (lambda args args) (lambda args (filter even? args))) 0 1 2 3 4 5 6 7 8 9) (list 8 6 4 2 0)))) (test-suite "map2" (test-case "complex" (let*-values ([(reals imags) (map2 (lambda (complex) (values (real-part complex) (imag-part complex))) (list 0+5i 1+4i 2+3i))]) (check-equal? reals (list 0 1 2)) (check-equal? imags (list 5 4 3))))) (test-suite "map/values" (test-case "rational" (let*-values ([(signs nums denoms) (map/values 3 (lambda (rat) (values (sgn (numerator rat)) (abs (numerator rat)) (denominator rat))) (list 3/4 -4/6 0/8))]) (check-equal? signs (list 1 -1 0)) (check-equal? nums (list 3 2 0)) (check-equal? denoms (list 4 3 1))))) (test-suite "fold/values" (test-case "lo/hi" (let*-values ([(lo hi) (fold/values (lambda (n lo hi) (values (min n lo) (max n hi))) (list 0 0) (list 1 -5 -8 3 12 -7))]) (check = lo -8) (check = hi 12)))) (test-suite "negate" (test-case "not even" (check-false ((negate even?) 4))) (test-case "not odd" (check-true ((negate odd?) 4)))) (test-suite "conjoin" (test-case "all" (check-true ((conjoin exact? positive? integer?) 4))) (test-case "some" (check-false ((conjoin exact? positive? integer?) -1))) (test-case "none" (check-false ((conjoin exact? positive? integer?) -3.3)))) (test-suite "disjoin" (test-case "all" (check-true ((disjoin exact? positive? integer?) 4))) (test-case "some" (check-true ((disjoin exact? positive? integer?) -1))) (test-case "none" (check-false ((disjoin exact? positive? integer?) -3.3)))))) )