diff options
author | Jonathan Helgert <jhelgert@users.noreply.github.com> | 2021-11-11 15:03:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-11 15:03:41 +0100 |
commit | ee7f61a5200fa54664fcc27b18ba06613bd288b0 (patch) | |
tree | 260f91344e670cf1335872328bdb5d97e77424ea /tests/run/cpp_stl_algo_comparison_ops.pyx | |
parent | 3f56484704742c1af33c9737642125c55b0634d5 (diff) | |
download | cython-ee7f61a5200fa54664fcc27b18ba06613bd288b0.tar.gz |
Add missing min/max, comparison and permutation operations of C++ algorithm library (GH-4448)
Tests are disabled on macOS+clang (failing with Apple clang++ 12) but appear to work fine on gcc-11.
Diffstat (limited to 'tests/run/cpp_stl_algo_comparison_ops.pyx')
-rw-r--r-- | tests/run/cpp_stl_algo_comparison_ops.pyx | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/run/cpp_stl_algo_comparison_ops.pyx b/tests/run/cpp_stl_algo_comparison_ops.pyx new file mode 100644 index 000000000..aa7cdc7e8 --- /dev/null +++ b/tests/run/cpp_stl_algo_comparison_ops.pyx @@ -0,0 +1,67 @@ +# mode: run +# tag: cpp, werror, cpp17, no-cpp-locals + +from libcpp cimport bool +from libcpp.algorithm cimport equal, lexicographical_compare +from libcpp.vector cimport vector + +cdef bool compare(int a, int b): + return a == b + +cdef bool less_than(char a, char b): + return a < b + +def test_equal(vector[int] v1, vector[int] v2): + """ + Test equal. + + >>> test_equal([1, 2, 3, 4], [1, 2, 3, 4]) + True + >>> test_equal([1, 2, 3, 4], [9, 2, 3, 4]) + False + """ + return equal(v1.begin(), v1.end(), v2.begin()) + +def test_equal_with_bin_pred(vector[int] v1, vector[int] v2): + """ + Test equal with binary predicate. + + >>> test_equal_with_bin_pred([1, 2, 3, 4], [1, 2, 3, 4]) + True + >>> test_equal_with_bin_pred([1, 2, 3, 4], [9, 2, 3, 4]) + False + """ + return equal(v1.begin(), v1.end(), v2.begin(), compare) + +def test_equal_with_second_range_and_bin_pred(vector[int] v1, vector[int] v2): + """ + Test equal with second range and binary predicate. + + >>> test_equal_with_second_range_and_bin_pred([1, 2, 3, 4], [1, 2, 3, 4]) + True + >>> test_equal_with_second_range_and_bin_pred([1, 2, 3, 4], [9, 2, 3, 4]) + False + """ + return equal(v1.begin(), v1.end(), v2.begin(), v2.end(), compare) + +def test_lexicographical_compare(vector[int] v1, vector[int] v2): + """ + Test lexicographical_compare. + + >>> test_lexicographical_compare([1, 2, 3, 4], [5, 6, 7, 8]) + True + >>> test_lexicographical_compare([1, 2, 3, 4], [1, 1, 3, 4]) + False + """ + return lexicographical_compare(v1.begin(), v1.end(), v2.begin(), v2.end()) + +def test_lexicographical_compare_with_bin_pred(vector[int] v1, vector[int] v2): + """ + Test lexicographical_compare with binary predicate + + >>> test_lexicographical_compare_with_bin_pred([1, 2, 3, 4], [5, 6, 7, 8]) + True + >>> test_lexicographical_compare_with_bin_pred([1, 2, 3, 4], [1, 1, 3, 4]) + False + """ + return lexicographical_compare(v1.begin(), v1.end(), v2.begin(), v2.end(), less_than) |