43 lines
824 B
Python
43 lines
824 B
Python
from math import pi
|
|
|
|
import pytest
|
|
|
|
from compute import rot_2D, rot_3D
|
|
|
|
|
|
def test_rot_2D() -> None:
|
|
"""Test a 90-degree rotation matrix in 2D."""
|
|
# Arrange
|
|
angle = pi / 2
|
|
expected = [
|
|
[0.0, -1.0],
|
|
[1.0, 0.0],
|
|
]
|
|
|
|
# Act
|
|
result = rot_2D(angle)
|
|
|
|
# Assert
|
|
for i in range(2):
|
|
for j in range(2):
|
|
assert result[i][j] == pytest.approx(expected[i][j])
|
|
|
|
|
|
def test_rot_3D() -> None:
|
|
"""Test a 90-degree rotation matrix around the z-axis."""
|
|
# Arrange
|
|
angle = pi / 2
|
|
axis = "z"
|
|
expected = [
|
|
[0.0, -1.0, 0.0],
|
|
[1.0, 0.0, 0.0],
|
|
[0.0, 0.0, 1.0],
|
|
]
|
|
|
|
# Act
|
|
result = rot_3D(angle, axis)
|
|
|
|
# Assert
|
|
for i in range(3):
|
|
for j in range(3):
|
|
assert result[i][j] == pytest.approx(expected[i][j]) |