(module vector-test mzscheme
(require (planet "test.ss" ("schematics" "schemeunit.plt" 2))
"vector.ss"
(lib "math.ss")
(planet "srfi-4-comprehensions.ss" ("wmfarr" "srfi-4-comprehensions.plt" 1)))
(provide vector-test-suite)
(define-simple-check (check-close? eps a b)
(< (abs (- a b)) (abs eps)))
(define vector-test-suite
(test-suite
"vector.ss test suite"
(test-case
"f64vector-norm"
(check-close? 1e-10
(f64vector-norm (f64vector 1.0 2.0 3.0 4.0))
(sqrt 30)))
(test-case
"f64vector-add, f64vector-sub, f64vector-scale"
(let ((v1 (f64vector-of-length-ec 10 (:range i 10) (random)))
(v2 (f64vector-of-length-ec 10 (:range i 10) (random))))
(do-ec (:parallel (:f64vector x (f64vector-sub v1 v2))
(:f64vector y (f64vector-add v1 (f64vector-scale v2 -1))))
(check-close? 1e-10 x y))))
(test-case
"f64vector-dot"
(let ((v (f64vector-of-length-ec 10 (:range i 10) (random))))
(check-close? 1e-10 (f64vector-dot v v) (sqr (f64vector-norm v))))))))