; Copyright (C) 2006 Will M. Farr ; ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License along ; with this program; if not, write to the Free Software Foundation, Inc., ; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. (module generics-test "generics.ss" (require (planet "test.ss" ("schematics" "schemeunit.plt" 2))) (require (lib "math.ss")) (provide generics-test-suite) (define (close? a b) (< (abs (- a b)) 1e-6)) (define generics-test-suite (test-suite "Generics tests" (test-case "+-tests" (check = (+ 1 2 3) 6) (check = (+ 1) 1) (check = (+ 3 5) 8)) (test-case "--tests" (check = (- 1 2 3) -4) (check = (- 1) -1) (check = (- 2 3) -1)) (test-case "*-tests" (check = (* 1 2 3) 6) (check = (* 1) 1) (check = (* 2 5) 10)) (test-case "/-tests" (check = (/ 1 2 6) 1/12) (check = (/ 5) 1/5) (check close? (/ 1 3.0 1) 0.3333333333333333)) (test-case "exp-tests" (check close? (exp 0) 1) (check close? (exp 1) e)) (test-case "log-tests" (check close? (log 1) 0) (check close? (log e) 1)) (test-case "sin-cos-tests" (check close? (+ (* (sin 1) (sin 1)) (* (cos 1) (cos 1))) 1) (check close? (sin 0) 0.0) (check close? (cos 0) 1.0)) (test-case "tan-tests" (check close? (tan 4.0) (/ (sin 4.0) (cos 4.0)))) (test-case "inverse trig functions" (check close? (asin (sin 1.34)) 1.34) (check close? (acos (cos 1.53)) 1.53) (check close? (atan (tan 0.453)) 0.453)) (test-case "sqrt" (check close? (sqrt 4) 2) (check close? (* (sqrt 3) (sqrt 3)) 3)) (test-case "square" (check = (square 15) (* 15 15))) (test-case "cube" (check = (cube 15) (* 15 15 15))))))