Skip to content

Commit fb093e1

Browse files
committed
test: add Python test for return-by-ref
1 parent 594096c commit fb093e1

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

unittest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ ENDIF()
4040
ADD_PYTHON_UNIT_TEST("py-matrix" "unittest/python/test_matrix.py" "unittest")
4141
ADD_PYTHON_UNIT_TEST("py-geometry" "unittest/python/test_geometry.py" "unittest")
4242
ADD_PYTHON_UNIT_TEST("py-complex" "unittest/python/test_complex.py" "unittest")
43+
ADD_PYTHON_UNIT_TEST("py-return-by-ref" "unittest/python/test_return_by_ref.py" "unittest")
4344

4445
ADD_PYTHON_UNIT_TEST("py-switch" "unittest/python/test_switch.py" "python/eigenpy")
4546
SET_TESTS_PROPERTIES("py-switch" PROPERTIES DEPENDS ${PYWRAP})
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from return_by_ref import Matrix, RowMatrix, Vector
2+
import numpy as np
3+
4+
def test(mat):
5+
6+
m_ref = mat.ref()
7+
m_ref.fill(0)
8+
m_copy = mat.copy()
9+
assert np.array_equal(m_ref,m_copy)
10+
11+
m_const_ref = mat.const_ref()
12+
assert np.array_equal(m_const_ref,m_copy)
13+
assert np.array_equal(m_const_ref,m_ref)
14+
15+
m_ref.fill(1)
16+
assert not np.array_equal(m_ref,m_copy)
17+
assert np.array_equal(m_const_ref,m_ref)
18+
19+
try:
20+
m_const_ref.fill(2)
21+
assert False
22+
except:
23+
assert True
24+
25+
rows = 10
26+
cols = 30
27+
28+
mat = Matrix(rows,cols)
29+
row_mat = RowMatrix(rows,cols)
30+
vec = Vector(rows,1)
31+
32+
test(mat)
33+
test(row_mat)
34+
test(vec)

0 commit comments

Comments
 (0)