From 3ac729a31e823e0231e9eedb90b3d213cb63696f Mon Sep 17 00:00:00 2001 From: KHLee Date: Wed, 22 Jan 2025 21:15:40 +0800 Subject: [PATCH] Add basic test case for sorting of SimpleArray --- tests/test_buffer.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_buffer.py b/tests/test_buffer.py index 1ac6a2db..219bf4ad 100644 --- a/tests/test_buffer.py +++ b/tests/test_buffer.py @@ -824,6 +824,18 @@ def test_SimpleArray_SimpleArrayPlex_type_switch(self): self.assertEqual( str(type(arrayplex_int32_2)), "") + def test_sort(self): + narr = np.random.randint(0, 100, 20, dtype='int32') + sarr = modmesh.SimpleArrayInt32(array=narr); + args = sarr.argsort() + for i in range(1, len(args)): + self.assertLessEqual(sarr[args[i]], sarr[args[i]]) + + sarr.sort() + for i in range(1, len(args)): + self.assertLessEqual(sarr[i - 1], sarr[i]) + + class SimpleArrayCalculatorsTC(unittest.TestCase): @@ -1068,5 +1080,7 @@ def test_construct(self): for it in range(6): ct[it] = it + 10 self.assertEqual(list(it + 10 for it in range(6)), list(ct)) + + # vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4: