Add unit tests for maths module (vectors)

This commit is contained in:
Renaud Casenave-Péré 2014-01-02 19:57:11 +09:00
parent 7731809a8a
commit c3c94fb9b2
2 changed files with 48 additions and 1 deletions

View file

@ -15,5 +15,6 @@
:cl-test-more)
:components ((:module "t"
:components
((:file "stoe"))))
((:file "stoe")
(:file "maths"))))
:perform (load-op :after (op c) (asdf:clear-system c)))

46
t/maths.lisp Normal file
View file

@ -0,0 +1,46 @@
#|
This file is a part of stoe project.
Copyright (c) 2014 Renaud Casenave-Péré (renaud@casenave-pere.fr)
|#
(in-package :cl-user)
(defpackage stoe-test.maths
(:use :cl
:stoe
:cl-test-more))
(in-package :stoe-test.maths)
(plan 17)
(diag "Vector Constructor Tests")
(is (v:vec 1 2 3) #(1.0 2.0 3.0) "Float Vector Constructor" :test #'equalp)
(is (v:vec-int 1 2 3) #(1 2 3) "Integer Vector Constructor" :test #'equalp)
(is (f2:vec 2 3) (v:vec 2 3) "Float2 Constructor" :test #'equalp)
(is (f3:vec 2 3 4) (v:vec 2 3 4) "Float3 Constructor" :test #'equalp)
(is (f4:vec 2 3 4 5) (v:vec 2 3 4 5) "Float4 Constructor" :test #'equalp)
(defvar *vector2* (f2:vec 2 3))
(defvar *vector3* (f3:vec 4 5 6))
(defvar *vector4* (f4:vec 7 8 9 10))
(diag "Swizzle Tests")
(is (v:swizzle *vector4* xy) (f2:vec 7 8) "Swizzle f4:xy" :test #'equalp)
(is (v:swizzle *vector2* xyz) (f3:vec 2 3 0) "Swizzle f2:xyz" :test #'equalp)
(is (v:swizzle *vector3* xyz) *vector3* "Swizzle f3:xyz (identity)" :test #'equalp)
(is (v:swizzle *vector4* wzyx) (f4:vec 10 9 8 7) "Swizzle f4:wzyx (reverse)" :test #'equalp)
(is (v:swizzle *vector2* xyxy) (f4:vec 2 3 2 3)
"Swizzle f2:xyxy (multiple attributes)" :test #'equalp)
(diag "Simple vector operations")
(is (v:+ *vector2* (v:swizzle *vector4* xy)) #(9.0 11.0) "Add f2" :test #'equalp)
(is (v:- *vector3* *vector3*) #(0.0 0.0 0.0) "Substract f3 to itself" :test #'equalp)
(is (v:* *vector4* (v:swizzle *vector2* xyxy)) #(14.0 24.0 18.0 30.0) "Multiply f4" :test #'equalp)
(is (v:/ *vector2* (v:swizzle *vector3* xz)) #(0.5 0.5) "Divide f2" :test #'equalp)
(diag "Simple vector / scalar operations")
(is (v:+ *vector2* 3) #(5.0 6.0) "Add f2" :test #'equalp)
(is (v:- *vector3* 1) #(3.0 4.0 5.0) "Substract f3" :test #'equalp)
(is (v:* *vector4* 2) #(14.0 16.0 18.0 20.0) "Multiply f4" :test #'equalp)
(is (v:/ *vector2* 5) #(0.4 0.6) "Divide f2" :test #'equalp)
(finalize)