68 lines
2.8 KiB
Common Lisp
68 lines
2.8 KiB
Common Lisp
#|
|
|
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
|
|
:prove))
|
|
(in-package :stoe-test.maths)
|
|
|
|
(plan 23)
|
|
|
|
(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)
|
|
|
|
(diag "Matrix Constructor Tests")
|
|
(is (m:mat 1 2 3 4 5 6 7 8 9 10 11 12) #2A((1.0 2.0 3.0 4.0) (5.0 6.0 7.0 8.0) (9.0 10.0 11.0 12.0))
|
|
"Matrix Constructor" :test #'equalp)
|
|
|
|
(defvar *matrix22* (f22:mat 1 2
|
|
3 4))
|
|
(defvar *matrix33* (f33:mat 1 2 3
|
|
4 5 6
|
|
7 8 9))
|
|
(defvar *matrix44* (f44:mat 1 2 3 4
|
|
5 6 7 8
|
|
9 10 11 12
|
|
13 14 15 16))
|
|
|
|
(is *matrix22* #2a((1.0 2.0) (3.0 4.0)) "Matrix22 Constructor" :test #'equalp)
|
|
(is *matrix33* #2a((1.0 2.0 3.0) (4.0 5.0 6.0) (7.0 8.0 9.0)) "Matrix33 Constructor" :test #'equalp)
|
|
(is *matrix44* #2a((1.0 2.0 3.0 4.0) (5.0 6.0 7.0 8.0) (9.0 10.0 11.0 12.0) (13.0 14.0 15.0 16.0))
|
|
"Matrix44 Constructor" :test #'equalp)
|
|
|
|
(diag "Simple Matrix Operations")
|
|
(is (m:+ *matrix22* (f22:mat-ident)) #2a((2.0 2.0) (3.0 5.0)) "Add f22" :test #'equalp)
|
|
|
|
(finalize)
|