test vector and matrix (TODO: Debug trait)

This commit is contained in:
Quaternions 2024-09-05 17:47:28 -07:00
parent 4d2aa0b2c8
commit 2312ee27b7

View File

@ -1,4 +1,4 @@
use crate::types::Vector3;
use crate::types::{Vector3,Matrix3x4,Matrix4x2,Matrix3x2};
#[test]
fn test_bool(){
@ -7,3 +7,36 @@ fn test_bool(){
assert_eq!(Vector3::new([false,false,true]).all(),false);
assert_eq!(Vector3::new([true,true,true]).all(),true);
}
#[test]
fn test_arithmetic(){
let a=Vector3::new([1,2,3]);
assert_eq!((a+a*2).array,Vector3::new([1*3,2*3,3*3]).array);
}
#[test]
fn matrix_dot(){
let lhs=Matrix3x4::new([
[1.0,2.0,3.0,4.0],
[5.0,6.0,7.0,8.0],
[9.0,1.0,1.0,1.0],
]);
let rhs=Matrix4x2::new([
[1.0,2.0],
[3.0,4.0],
[5.0,6.0],
[7.0,8.0],
]);
// Mat3<Vec4>.dot(Mat4<Vec2>) -> Mat3<Vec2>
let m_dot=lhs.dot(rhs);
//In[1]:= {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}} . {{1, 2}, {3, 4}, {5, 6}, {7, 8}}
//Out[1]= {{50, 60}, {114, 140}, {178, 220}}
assert_eq!(
m_dot.array,
Matrix3x2::new([
[50.0,60.0],
[114.0,140.0],
[178.0,220.0],
]).array
);
}