Skip to content

Commit

Permalink
Add basic test case for sorting of SimpleArray
Browse files Browse the repository at this point in the history
  • Loading branch information
KHLee529 committed Jan 22, 2025
1 parent 00bc2b6 commit 3ac729a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/test_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,18 @@ def test_SimpleArray_SimpleArrayPlex_type_switch(self):
self.assertEqual(
str(type(arrayplex_int32_2)), "<class '_modmesh.SimpleArray'>")

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):

Expand Down Expand Up @@ -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:

0 comments on commit 3ac729a

Please sign in to comment.