|
2 | 2 | from tests import test_module as tm
|
3 | 3 | from tests.utils import generate_matrix, check_matrix_content
|
4 | 4 |
|
| 5 | + |
5 | 6 | def test_return_by_value():
|
6 | 7 | a = tm.ClassForReturn()
|
7 |
| - assert(id(a.returnByValue()) != id(a.returnByValue())) |
8 | 8 | mat = a.returnByValue()
|
9 | 9 | a.changeInternal()
|
10 |
| - assert(np.any(mat != a.returnByValue())) |
| 10 | + assert(check_matrix_content(mat)) |
| 11 | + changed_mat = a.returnByValue() |
| 12 | + assert(not check_matrix_content(changed_mat)) |
11 | 13 |
|
12 | 14 |
|
13 | 15 | def test_return_by_ref_but_copy():
|
14 | 16 | a = tm.ClassForReturn()
|
15 |
| - assert(id(a.returnByRef()) != id(a.returnByRef())) |
16 | 17 | mat = a.returnByRef()
|
17 | 18 | a.changeInternal()
|
18 |
| - assert(np.any(mat != a.returnByValue())) |
| 19 | + assert(check_matrix_content(mat)) |
| 20 | + changed_mat = a.returnByValue() |
| 21 | + assert(not check_matrix_content(changed_mat)) |
19 | 22 |
|
20 | 23 |
|
21 | 24 | def test_return_by_ref():
|
22 | 25 | a = tm.ClassForReturn()
|
23 |
| - assert(id(a.returnByRef()) != id(a.returnByRef())) |
24 | 26 | mat = a.viewMatrix()
|
25 | 27 | a.changeInternal()
|
26 |
| - assert(np.all(mat == a.returnByValue())) |
| 28 | + # Currently return parameter perform a copy of the data, so the change is not repercuted to mat |
| 29 | + assert(check_matrix_content(mat)) |
| 30 | + changed_mat = a.returnByValue() |
| 31 | + assert(not check_matrix_content(changed_mat)) |
27 | 32 |
|
28 | 33 |
|
29 | 34 | def test_return_by_pointer():
|
30 | 35 | a = tm.ClassForReturn()
|
31 |
| - assert(id(a.returnByPointer()) != id(a.returnByPointer())) |
32 | 36 | mat = a.returnByPointer()
|
33 | 37 | a.changeInternal()
|
34 |
| - assert(np.all(mat == a.returnByValue())) |
35 |
| - |
| 38 | + # Currently return parameter perform a copy of the data, so the change is not repercuted to mat |
| 39 | + assert(check_matrix_content(mat)) |
| 40 | + changed_mat = a.returnByValue() |
| 41 | + assert(not check_matrix_content(changed_mat)) |
36 | 42 |
|
37 | 43 |
|
38 | 44 | def test_return_by_argument_by_value():
|
|
0 commit comments