Skip to content

Commit a4cfb85

Browse files
committed
[add] tests for matrix rotations and vector cross products.
1 parent 156d02f commit a4cfb85

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

crates/lambda-rs/src/math/matrix.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ mod tests {
397397

398398
use super::{
399399
filled_matrix,
400+
identity_matrix,
400401
perspective_matrix,
401402
rotate_matrix,
402403
submatrix,
@@ -542,4 +543,30 @@ mod tests {
542543
}
543544
}
544545
}
546+
547+
/// Verify that `rotate_matrix` returns `InvalidRotationAxis` when a non-unit
548+
/// axis vector is provided.
549+
#[test]
550+
fn rotate_matrix_fails_for_invalid_axis() {
551+
let matrix: [[f32; 4]; 4] = identity_matrix(4, 4);
552+
let result = rotate_matrix(matrix, [1.0, 1.0, 0.0], 0.25);
553+
assert_eq!(
554+
result,
555+
Err(MathError::InvalidRotationAxis {
556+
axis: [1.0, 1.0, 0.0]
557+
})
558+
);
559+
}
560+
561+
/// Verify that `rotate_matrix` returns `InvalidRotationMatrixSize` when a
562+
/// non-4x4 matrix is provided.
563+
#[test]
564+
fn rotate_matrix_fails_for_non_4x4_matrix() {
565+
let matrix: [[f32; 3]; 3] = identity_matrix(3, 3);
566+
let result = rotate_matrix(matrix, [0.0, 1.0, 0.0], 0.25);
567+
assert_eq!(
568+
result,
569+
Err(MathError::InvalidRotationMatrixSize { rows: 3, cols: 3 })
570+
);
571+
}
545572
}

crates/lambda-rs/src/math/vector.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,20 @@ mod tests {
215215
assert_eq!(result, Err(MathError::CrossProductDimension { actual: 2 }));
216216
}
217217

218+
/// Verify that `cross` returns `MismatchedVectorDimensions` when vectors of
219+
/// different dimensions are provided.
220+
#[test]
221+
fn cross_product_fails_for_mismatched_dimensions() {
222+
let a: Vec<f32> = vec![1.0, 2.0];
223+
let b: Vec<f32> = vec![4.0, 5.0, 6.0];
224+
225+
let result = a.cross(&b);
226+
assert_eq!(
227+
result,
228+
Err(MathError::MismatchedVectorDimensions { left: 2, right: 3 })
229+
);
230+
}
231+
218232
#[test]
219233
fn length() {
220234
let a = [1.0, 2.0, 3.0];

0 commit comments

Comments
 (0)