diff options
author | Matti Picus <matti.picus@gmail.com> | 2018-10-23 08:37:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-23 08:37:19 +0300 |
commit | 2705bd5f9e6c7999e25d42daddd5bd11223472c8 (patch) | |
tree | 7edfd42fc517d865021177212df26bd39c7c114f /numpy/lib/tests/test_function_base.py | |
parent | 73151451437fa6ce0d8b5f033c1e005885f63cf8 (diff) | |
parent | 80d3a7ac9a0cb14536ab80c8b383d0b1f2f76b67 (diff) | |
download | numpy-2705bd5f9e6c7999e25d42daddd5bd11223472c8.tar.gz |
Merge pull request #12245 from tylerjereddy/test_sort_complex
TST: tests for sort_complex()
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 40cca1dbb..0c789e012 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -3114,3 +3114,29 @@ class TestAdd_newdoc(object): assert_equal(np.core.flatiter.index.__doc__[:len(tgt)], tgt) assert_(len(np.core.ufunc.identity.__doc__) > 300) assert_(len(np.lib.index_tricks.mgrid.__doc__) > 300) + +class TestSortComplex(object): + + @pytest.mark.parametrize("type_in, type_out", [ + ('l', 'D'), + ('h', 'F'), + ('H', 'F'), + ('b', 'F'), + ('B', 'F'), + ('g', 'G'), + ]) + def test_sort_real(self, type_in, type_out): + # sort_complex() type casting for real input types + a = np.array([5, 3, 6, 2, 1], dtype=type_in) + actual = np.sort_complex(a) + expected = np.sort(a).astype(type_out) + assert_equal(actual, expected) + assert_equal(actual.dtype, expected.dtype) + + def test_sort_complex(self): + # sort_complex() handling of complex input + a = np.array([2 + 3j, 1 - 2j, 1 - 3j, 2 + 1j], dtype='D') + expected = np.array([1 - 3j, 1 - 2j, 2 + 1j, 2 + 3j], dtype='D') + actual = np.sort_complex(a) + assert_equal(actual, expected) + assert_equal(actual.dtype, expected.dtype) |