Skip to content
Snippets Groups Projects
Verified Commit fb093e17 authored by Justin Carpentier's avatar Justin Carpentier
Browse files

test: add Python test for return-by-ref

parent 594096ca
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,7 @@ ENDIF()
ADD_PYTHON_UNIT_TEST("py-matrix" "unittest/python/test_matrix.py" "unittest")
ADD_PYTHON_UNIT_TEST("py-geometry" "unittest/python/test_geometry.py" "unittest")
ADD_PYTHON_UNIT_TEST("py-complex" "unittest/python/test_complex.py" "unittest")
ADD_PYTHON_UNIT_TEST("py-return-by-ref" "unittest/python/test_return_by_ref.py" "unittest")
ADD_PYTHON_UNIT_TEST("py-switch" "unittest/python/test_switch.py" "python/eigenpy")
SET_TESTS_PROPERTIES("py-switch" PROPERTIES DEPENDS ${PYWRAP})
......
from return_by_ref import Matrix, RowMatrix, Vector
import numpy as np
def test(mat):
m_ref = mat.ref()
m_ref.fill(0)
m_copy = mat.copy()
assert np.array_equal(m_ref,m_copy)
m_const_ref = mat.const_ref()
assert np.array_equal(m_const_ref,m_copy)
assert np.array_equal(m_const_ref,m_ref)
m_ref.fill(1)
assert not np.array_equal(m_ref,m_copy)
assert np.array_equal(m_const_ref,m_ref)
try:
m_const_ref.fill(2)
assert False
except:
assert True
rows = 10
cols = 30
mat = Matrix(rows,cols)
row_mat = RowMatrix(rows,cols)
vec = Vector(rows,1)
test(mat)
test(row_mat)
test(vec)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment