From cee0c23bd76294ff88795a655d56e2564ceaf9d3 Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Wed, 19 Aug 2020 12:56:30 +0200 Subject: [PATCH] Add test_cumcount. --- tests/triacontagon/test_cumcount.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/triacontagon/test_cumcount.py diff --git a/tests/triacontagon/test_cumcount.py b/tests/triacontagon/test_cumcount.py new file mode 100644 index 0000000..b9a8780 --- /dev/null +++ b/tests/triacontagon/test_cumcount.py @@ -0,0 +1,26 @@ +from triacontagon.cumcount import dfill, \ + argunsort, \ + cumcount +import numpy as np + + +def test_dfill_01(): + input = np.array([1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5]) + output = dfill(input) + expected = np.array([0, 0, 0, 0, 0, 5, 5, 7, 7, 7, 10, 10, 12, 12]) + assert np.all(output == expected) + + +def test_argunsort_01(): + input = np.array([1, 1, 2, 3, 3, 4, 1, 1, 5, 5, 2, 3, 1, 4]) + output = np.argsort(input, kind='mergesort') + output = argunsort(output) + expected = np.array([0, 1, 5, 7, 8, 10, 2, 3, 12, 13, 6, 9, 4, 11]) + assert np.all(output == expected) + + +def test_cumcount_01(): + input = np.array([1, 1, 2, 3, 3, 4, 1, 1, 5, 5, 2, 3, 1, 4]) + output = cumcount(input) + expected = np.array([0, 1, 0, 0, 1, 0, 2, 3, 0, 1, 1, 2, 4, 1]) + assert np.all(output == expected)