Skip to content

Commit 41b9e96

Browse files
committed
feat: made some tests
1 parent 1183ff6 commit 41b9e96

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,18 @@ ament_export_libraries(${PROJECT_NAME})
3434

3535
ament_python_install_package(${PROJECT_NAME})
3636

37+
if(BUILD_TESTING)
38+
find_package(ament_cmake_pytest REQUIRED)
39+
set(_pytest_tests
40+
tests/test_utils.py
41+
)
42+
foreach(_test_path ${_pytest_tests})
43+
get_filename_component(_test_name ${_test_path} NAME_WE)
44+
ament_add_pytest_test(${_test_name} ${_test_path}
45+
APPEND_ENV PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}
46+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
47+
)
48+
endforeach()
49+
endif()
50+
3751
ament_package()

tests/test_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
from vortex_utils.python_utils import *
3+
4+
def test_ssa():
5+
assert ssa(0) == 0
6+
assert ssa(2 * np.pi) == 0
7+
assert ssa(3.5) == pytest.approx(-2.78, rel=0.01)
8+
assert ssa(-3.5) == pytest.approx(2.78, rel=0.01)
9+
10+
def test_euler_to_quat():
11+
quat = euler_to_quat(0, 0, 0)
12+
assert quat == pytest.approx([0, 0, 0, 1], rel=0.01)
13+
quat = euler_to_quat(1, 0, 0)
14+
assert quat == pytest.approx([0.479, 0, 0, 0.877], rel=0.01)
15+
quat = euler_to_quat(0, 1, 0)
16+
assert quat == pytest.approx([0, 0.479, 0, 0.877], rel=0.01)
17+
quat = euler_to_quat(0, 0, 1)
18+
assert quat == pytest.approx([0, 0, 0.479, 0.877], rel=0.01)
19+
quat = euler_to_quat(1, 1, 1)
20+
assert quat == pytest.approx([0.5709, 0.167, 0.5709, 0.565], rel=0.01)
21+

0 commit comments

Comments
 (0)