Skip to content

Commit

Permalink
Merge pull request #445 from KHLee529/add_simplearray_test
Browse files Browse the repository at this point in the history
Add unit test for `SimpleArray`
  • Loading branch information
yungyuc authored Jan 1, 2025
2 parents 35650f4 + 6962dcf commit 8f7ad03
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def test_SimpleArray(self):

self.assertEqual((1, 24), sarr.reshape((1, 24)).shape)
self.assertEqual((12, 2), sarr.reshape((12, 2)).shape)
self.assertEqual((2, 2, 2, 3), sarr.reshape((2, 2, 2, 3)).shape)

def test_SimpleArray_clone(self):
sarr = modmesh.SimpleArrayFloat64((2, 3, 4))
Expand Down Expand Up @@ -436,6 +437,22 @@ def test_SimpleArray_from_ndarray(self):
sarr_from_cpp = modmesh.SimpleArrayFloat64(shape=(2, 3, 4))
self.assertFalse(sarr_from_cpp.is_from_python)

shape = (2, 3, 5, 7)
np_sarr = np.empty(shape, dtype='float64')
py_sarr = modmesh.SimpleArrayFloat64(array=np_sarr)
self.assertTupleEqual(shape, py_sarr.shape)

shape = (5, 5, 5, 5)
np_sarr = np.empty(shape, dtype='float64')
for i in range(5):
for j in range(5):
for k in range(5):
for x in range(5):
np_sarr[i, j, k, x] = i * 1000 + j * 100 + k * 10 + x

py_sarr = modmesh.SimpleArrayFloat64(array=np_sarr)
self.assertTupleEqual(shape, py_sarr.shape)

def test_SimpleArray_from_ndarray_content(self):

ndarr = np.arange(24, dtype='float64').reshape((2, 3, 4))
Expand Down

0 comments on commit 8f7ad03

Please sign in to comment.