From 6962dcf0f9fb517873f6ee991e86e92b9a914628 Mon Sep 17 00:00:00 2001 From: KHLee Date: Mon, 30 Dec 2024 20:33:57 +0800 Subject: [PATCH] Add multi-dimension tests for constructing `SimpleArray` from `ndarray` --- tests/test_buffer.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_buffer.py b/tests/test_buffer.py index e632ac70..1ac6a2db 100644 --- a/tests/test_buffer.py +++ b/tests/test_buffer.py @@ -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)) @@ -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))