;;;; tests.scm (use test) (use ftl) (test-begin) (test eqv? (%e=? e=v)) (test #t ((%oe>? oe=number) 4 3)) (test #f ((%oe>? oe=number) 4 4)) (test #t ((%oe>=? oe=number) 4 4)) (test #t ((%oe<=? oe=number) 4 4)) (test #f ((%oe<=? oe=number) 5 4)) (test #t ((%e=? (e=%oe oe=string-ci)) "abc" "ABC")) (test 2 ((%x x=add1) 1)) (test #t ((%t? (t=%x&%t x=integer->char t=char-ci)) 65 #\a)) (test #f ((%t? t=if-not) 3 odd?)) (test '(9 8 7 6 5 4 3 2 1 0) ((%g-fold g=iota) cons '() 10)) (test 100 ((%g-fold g=vector) + 0 '#(20 30 50))) (test 60 ((%g-fold g=vector) + 10 (sub '#(20 30 50) 0 2))) (test 9 ((%oe-max oe=number) 3 2 9 1 4)) (test #\a ((%oe-min oe=char-ci) #\B #\c #\a #\D)) (test #t ((%v-null? v=vector) '#())) (test #f ((%v-null? v=string) "a")) (test "ll" ((sub%mv mv=string) "hello, world!" 2 4)) (test "hello, world!" ((%mv-copy mv=string) "hello, world!")) (test "ll" ((%mv-copy mv=string) (sub "hello, world!" 2 4))) (test '#(44 44 44) (let ((x (vector 1 2 3))) ((%mv-fill! mv=vector) x 44) x)) (test "Hiiii!" (let ((x (string-copy "Hello!"))) ((%mv-fill! mv=string) (sub x 1 5) #\i) x)) (test "Franz Liszt" ((%mv-append mv=string) "Franz" " " "Liszt")) (test "Franz Liszt" ((%mv-append mv=string) "Franz" (sub "[ ]" 1 2) "Liszt")) (test '(5 4 3 2 1) ((%v-fold-left v=vector) cons '() '#(1 2 3 4 5))) (test '(1 2 3 4 5) ((%v-fold-right v=vector) cons '() '#(1 2 3 4 5))) (test '#(#\F #\r #\a #\n #\z #\space #\L #\i #\s #\z #\t) ((%v->%mv v=string mv=vector) "Franz Liszt")) (test "HeEHE!" (let ((x (string-copy "Hello!"))) ((%v->%mv! v=vector mv=string) '#(#\E #\H #\E) (sub x 2 5)) x)) (test "0120123489" (let ((x (string-copy "0123456789"))) ((%v->%mv! v=string mv=string) (sub x 0 5) (sub x 3 9)) x)) (test "3456756789" (let ((x (string-copy "0123456789"))) ((%v->%mv! v=string mv=string) (sub x 3 9) (sub x 0 5)) x)) (test '#(44 #\a 12) ((%mv mv=vector) 44 #\a 12)) (test '#(1 2 3 4 5 6 7) (let ((a '#(3 5 1 2 4 7 6))) ((%mv-sort! mv=vector) a <) a)) (test 44 ((%g-length g=iota) 44)) (test 2 ((%g-length g=file) "../ftl.scm")) ((%g-for-each g=iota) write 10) ;; writes 0123456789 (newline) ((%g-for-each g=list) write '(0 1 2 3 4 5 6 7 8 9)) ;; writes 0123456789 (newline) ((%g-for-each g=reverse-list) write '(0 1 2 3 4 5 6 7 8 9)) ;; writes 9876543210 (newline) ((%g-for-each g=reverse-string) display "0123456789") ;; writes 9876543210 (newline) (test 9 ((%g-last g=list) '(0 1 2 3 4 5 6 7 8 9))) (test ''end ((%g-last g=file) "../ftl.scm")) (test 3 ((%g-count-%t g=list t=if) even? '(0 1 2 3 4))) (test 5 ((%g-count-%t g=char-port t=char-ci) #\a (open-input-string "Abracadabra"))) (test 3 ((%g-last-%t g=list t=if-not) even? '(0 1 2 3 4))) (test '(#\h #\e #\l #\l #\o) ((%g->%o g=string o=list) "hello")) (test '(1 2 3 4 5) ((%g->%o g=list o=list) '(1 2 3 4 5))) (test 120 ((%g->%o g=list o=product) '(1 2 3 4 5))) (test '(#\H #\e #\l #\l #\o #\, #\space #\F #\T #\L #\!) ((%g-append->%o g=string o=list) "Hello" ", " "FTL!")) (test 6 ((%g-append->%o* g=list o=max) '(1 4 2 5) '(3 5 6) 0)) (test '(6 5 3 5 2 4 1 . 0) ((%g-append->%o* g=list o=reverse-list) '(1 4 2 5) '(3 5 6) 0)) (test '(#\H #\e #\l #\l #\o #\, #\space #\F #\T #\L #\!) ((%g->%o/%g-splicing g=list o=list g=string) '("He" "llo" ", FTL!"))) (test '(#\H #\E #\L #\L #\O) ((%g-map1->%o g=string o=list) char-upcase "hello")) (test '(#\H #\H #\e #\E #\l #\L #\l #\L #\o #\O #\! #\!) ((%g-map1->%o/%g-splicing g=string o=list g=list) (lambda (c) (list c (char-upcase c))) "Hello!")) (test '(#\H #\e #\o #\, #\space #\F #\T #\!) ((%g-remove-%t->%o g=string t=char-ci o=list) #\l "Hello, FTL!")) (test '((#\l #\l #\L) (#\! #\T #\F #\space #\, #\o #\e #\H)) (receive ((%g-partition-%t->%o+%o g=string t=char-ci o=list o=reverse-list) #\l "Hello, FTL!"))) (test '(#\E #\L #\L #\O) ((%g-filter-map1->%o g=string o=list) (lambda (c) (and (char-lower-case? c) (char-upcase c))) "Hello, FTL!")) (test '(#\H #\e #\* #\* #\o #\, #\space #\F #\T #\* #\!) ((%g-substitute-%t->%o g=string t=char-ci o=list) #\* #\l "Hello, FTL!")) (test-end)