[libcxx-commits] [libcxx] d7ac595 - [libcxx][test][NFC] More tests for containers comparisons
Ruslan Arutyunyan via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Nov 3 06:15:23 PDT 2021
Author: Konstantin Boyarinov
Date: 2021-11-03T16:15:10+03:00
New Revision: d7ac595fc5175b08e9d0da4b608f4f9ffa45afca
URL: https://github.com/llvm/llvm-project/commit/d7ac595fc5175b08e9d0da4b608f4f9ffa45afca
DIFF: https://github.com/llvm/llvm-project/commit/d7ac595fc5175b08e9d0da4b608f4f9ffa45afca.diff
LOG: [libcxx][test][NFC] More tests for containers comparisons
Add more missing tests for comparisons to improve code coverage (follow-up for D111738)
Reviewed By: ldionne, rarutyun, #libc
Differential Revision: https://reviews.llvm.org/D112424
Added:
libcxx/test/std/containers/associative/map/map.nonmember/op_compare.pass.cpp
libcxx/test/std/containers/associative/multimap/multimap.nonmember/op_compare.pass.cpp
libcxx/test/std/containers/sequences/deque/compare.pass.cpp
libcxx/test/std/containers/sequences/list/compare.pass.cpp
libcxx/test/std/containers/sequences/vector.bool/compare.pass.cpp
Modified:
libcxx/test/std/containers/sequences/array/compare.pass.cpp
libcxx/test/std/containers/unord/unord.map/eq.pass.cpp
libcxx/test/std/containers/unord/unord.multimap/eq.pass.cpp
libcxx/test/support/test_comparisons.h
Removed:
################################################################################
diff --git a/libcxx/test/std/containers/associative/map/map.nonmember/op_compare.pass.cpp b/libcxx/test/std/containers/associative/map/map.nonmember/op_compare.pass.cpp
new file mode 100644
index 0000000000000..cfeb02e043872
--- /dev/null
+++ b/libcxx/test/std/containers/associative/map/map.nonmember/op_compare.pass.cpp
@@ -0,0 +1,81 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// template<class Key, class T, class Compare, class Alloc>
+// bool operator==(const std::map<Key, T, Compare, Alloc>& lhs,
+// const std::map<Key, T, Compare, Alloc>& rhs);
+//
+// template<class Key, class T, class Compare, class Alloc>
+// bool operator!=(const std::map<Key, T, Compare, Alloc>& lhs,
+// const std::map<Key, T, Compare, Alloc>& rhs);
+//
+// template<class Key, class T, class Compare, class Alloc>
+// bool operator<(const std::map<Key, T, Compare, Alloc>& lhs,
+// const std::map<Key, T, Compare, Alloc>& rhs);
+//
+// template<class Key, class T, class Compare, class Alloc>
+// bool operator>(const std::map<Key, T, Compare, Alloc>& lhs,
+// const std::map<Key, T, Compare, Alloc>& rhs);
+//
+// template<class Key, class T, class Compare, class Alloc>
+// bool operator<=(const std::map<Key, T, Compare, Alloc>& lhs,
+// const std::map<Key, T, Compare, Alloc>& rhs);
+//
+// template<class Key, class T, class Compare, class Alloc>
+// bool operator>=(const std::map<Key, T, Compare, Alloc>& lhs,
+// const std::map<Key, T, Compare, Alloc>& rhs);
+
+#include <map>
+#include <cassert>
+#include <string>
+
+#include "test_comparisons.h"
+
+int main(int, char**) {
+ typedef std::map<int, std::string> map_type;
+ typedef map_type::value_type value_type;
+ {
+ map_type m1, m2;
+ m1.insert(value_type(1, "abc"));
+ m2.insert(value_type(2, "abc"));
+ const map_type& cm1 = m1, cm2 = m2;
+ assert(testComparisons6(cm1, cm2, false, true));
+ }
+ {
+ map_type m1, m2;
+ m1.insert(value_type(1, "abc"));
+ m2.insert(value_type(1, "abc"));
+ const map_type& cm1 = m1, cm2 = m2;
+ assert(testComparisons6(cm1, cm2, true, false));
+ }
+ {
+ map_type m1, m2;
+ m1.insert(value_type(1, "ab"));
+ m2.insert(value_type(1, "abc"));
+ const map_type& cm1 = m1, cm2 = m2;
+ assert(testComparisons6(cm1, cm2, false, true));
+ }
+ {
+ map_type m1, m2;
+ m1.insert(value_type(1, "abc"));
+ m2.insert(value_type(1, "bcd"));
+ const map_type& cm1 = m1, cm2 = m2;
+ assert(testComparisons6(cm1, cm2, false, true));
+ }
+ {
+ map_type m1, m2;
+ m1.insert(value_type(1, "abc"));
+ m2.insert(value_type(1, "abc"));
+ m2.insert(value_type(2, "abc"));
+ const map_type& cm1 = m1, cm2 = m2;
+ assert(testComparisons6(cm1, cm2, false, true));
+ }
+ return 0;
+}
diff --git a/libcxx/test/std/containers/associative/multimap/multimap.nonmember/op_compare.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.nonmember/op_compare.pass.cpp
new file mode 100644
index 0000000000000..83aeca5917f8c
--- /dev/null
+++ b/libcxx/test/std/containers/associative/multimap/multimap.nonmember/op_compare.pass.cpp
@@ -0,0 +1,90 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// template<class Key, class T, class Compare, class Alloc>
+// bool operator==(const std::multimap<Key, T, Compare, Alloc>& lhs,
+// const std::multimap<Key, T, Compare, Alloc>& rhs);
+//
+// template<class Key, class T, class Compare, class Alloc>
+// bool operator!=(const std::multimap<Key, T, Compare, Alloc>& lhs,
+// const std::multimap<Key, T, Compare, Alloc>& rhs);
+//
+// template<class Key, class T, class Compare, class Alloc>
+// bool operator<(const std::multimap<Key, T, Compare, Alloc>& lhs,
+// const std::multimap<Key, T, Compare, Alloc>& rhs);
+//
+// template<class Key, class T, class Compare, class Alloc>
+// bool operator>(const std::multimap<Key, T, Compare, Alloc>& lhs,
+// const std::multimap<Key, T, Compare, Alloc>& rhs);
+//
+// template<class Key, class T, class Compare, class Alloc>
+// bool operator<=(const std::multimap<Key, T, Compare, Alloc>& lhs,
+// const std::multimap<Key, T, Compare, Alloc>& rhs);
+//
+// template<class Key, class T, class Compare, class Alloc>
+// bool operator>=(const std::multimap<Key, T, Compare, Alloc>& lhs,
+// const std::multimap<Key, T, Compare, Alloc>& rhs);
+
+#include <map>
+#include <cassert>
+#include <string>
+
+#include "test_comparisons.h"
+
+int main(int, char**) {
+ typedef std::multimap<int, std::string> map_type;
+ typedef map_type::value_type value_type;
+ {
+ map_type m1, m2;
+ m1.insert(value_type(1, "abc"));
+ m2.insert(value_type(2, "abc"));
+ const map_type& cm1 = m1, cm2 = m2;
+ assert(testComparisons6(cm1, cm2, false, true));
+ }
+ {
+ map_type m1, m2;
+ m1.insert(value_type(1, "abc"));
+ m2.insert(value_type(1, "abc"));
+ const map_type& cm1 = m1, cm2 = m2;
+ assert(testComparisons6(cm1, cm2, true, false));
+ }
+ {
+ map_type m1, m2;
+ m1.insert(value_type(1, "ab"));
+ m2.insert(value_type(1, "abc"));
+ const map_type& cm1 = m1, cm2 = m2;
+ assert(testComparisons6(cm1, cm2, false, true));
+ }
+ {
+ map_type m1, m2;
+ m1.insert(value_type(1, "abc"));
+ m2.insert(value_type(1, "bcd"));
+ const map_type& cm1 = m1, cm2 = m2;
+ assert(testComparisons6(cm1, cm2, false, true));
+ }
+ {
+ map_type m1, m2;
+ m1.insert(value_type(1, "abc"));
+ m2.insert(value_type(1, "abc"));
+ m2.insert(value_type(2, "abc"));
+ const map_type& cm1 = m1, cm2 = m2;
+ assert(testComparisons6(cm1, cm2, false, true));
+ }
+ {
+ map_type m1, m2;
+ m1.insert(value_type(1, "abc"));
+ m2.insert(value_type(1, "abc"));
+ m2.insert(value_type(1, "abc"));
+ m2.insert(value_type(1, "bcd"));
+ const map_type& cm1 = m1, cm2 = m2;
+ assert(testComparisons6(cm1, cm2, false, true));
+ }
+ return 0;
+}
diff --git a/libcxx/test/std/containers/sequences/array/compare.pass.cpp b/libcxx/test/std/containers/sequences/array/compare.pass.cpp
index a04d5584477b6..d777b7e63bbe4 100644
--- a/libcxx/test/std/containers/sequences/array/compare.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/compare.pass.cpp
@@ -26,18 +26,34 @@ TEST_CONSTEXPR_CXX20 bool tests()
{
{
typedef std::array<int, 3> C;
- C c1 = {1, 2, 3};
- C c2 = {1, 2, 3};
- C c3 = {3, 2, 1};
- C c4 = {1, 2, 1};
+ const C c1 = {1, 2, 3};
+ const C c2 = {1, 2, 3};
+ const C c3 = {3, 2, 1};
+ const C c4 = {1, 2, 1};
assert(testComparisons6(c1, c2, true, false));
assert(testComparisons6(c1, c3, false, true));
assert(testComparisons6(c1, c4, false, false));
}
{
typedef std::array<int, 0> C;
- C c1 = {};
- C c2 = {};
+ const C c1 = {};
+ const C c2 = {};
+ assert(testComparisons6(c1, c2, true, false));
+ }
+ {
+ typedef std::array<LessAndEqComp, 3> C;
+ const C c1 = {LessAndEqComp(1), LessAndEqComp(2), LessAndEqComp(3)};
+ const C c2 = {LessAndEqComp(1), LessAndEqComp(2), LessAndEqComp(3)};
+ const C c3 = {LessAndEqComp(3), LessAndEqComp(2), LessAndEqComp(1)};
+ const C c4 = {LessAndEqComp(1), LessAndEqComp(2), LessAndEqComp(1)};
+ assert(testComparisons6(c1, c2, true, false));
+ assert(testComparisons6(c1, c3, false, true));
+ assert(testComparisons6(c1, c4, false, false));
+ }
+ {
+ typedef std::array<LessAndEqComp, 0> C;
+ const C c1 = {};
+ const C c2 = {};
assert(testComparisons6(c1, c2, true, false));
}
diff --git a/libcxx/test/std/containers/sequences/deque/compare.pass.cpp b/libcxx/test/std/containers/sequences/deque/compare.pass.cpp
new file mode 100644
index 0000000000000..0ae9e6602fa71
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/deque/compare.pass.cpp
@@ -0,0 +1,119 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <deque>
+
+// template<class T, class Alloc>
+// bool operator==(const std::deque<T, Alloc>& lhs,
+// const std::deque<T,Alloc>& rhs);
+
+// template<class T, class Alloc>
+// bool operator!=(const std::deque<T,Alloc>& lhs,
+// const std::deque<T,Alloc>& rhs);
+
+// template<class T, class Alloc>
+// bool operator<(const std::deque<T,Alloc>& lhs,
+// const std::deque<T,Alloc>& rhs);
+
+// template<class T, class Alloc>
+// bool operator<=(const std::deque<T,Alloc>& lhs,
+// const std::deque<T,Alloc>& rhs);
+
+// template<class T, class Alloc>
+// bool operator>(const std::deque<T,Alloc>& lhs,
+// const std::deque<T,Alloc>& rhs);
+
+// template<class T, class Alloc>
+// bool operator>=(const std::deque<T,Alloc>& lhs,
+// const std::deque<T,Alloc>& rhs);
+
+#include <deque>
+#include <cassert>
+
+#include "test_comparisons.h"
+
+int main(int, char**)
+{
+ {
+ const std::deque<int> d1, d2;
+ assert(testComparisons6(d1, d2, true, false));
+ }
+ {
+ const std::deque<int> d1(1, 1), d2(1, 1);
+ assert(testComparisons6(d1, d2, true, false));
+ }
+ {
+ int items[3] = {1, 2, 3};
+ const std::deque<int> d1(items, items + 3);
+ const std::deque<int> d2(items, items + 3);
+ assert(testComparisons6(d1, d2, true, false));
+ }
+ {
+ const std::deque<int> d1(1, 1), d2;
+ assert(testComparisons6(d1, d2, false, false));
+ }
+ {
+ const std::deque<int> d1(1, 1), d2(1, 2);
+ assert(testComparisons6(d1, d2, false, true));
+ }
+ {
+ int items1[2] = {1, 2};
+ int items2[2] = {1, 3};
+ const std::deque<int> d1(items1, items1 + 2);
+ const std::deque<int> d2(items2, items2 + 2);
+ assert(testComparisons6(d1, d2, false, true));
+ }
+ {
+ int items1[2] = {2, 2};
+ int items2[2] = {1, 3};
+ const std::deque<int> d1(items1, items1 + 2);
+ const std::deque<int> d2(items2, items2 + 2);
+ assert(testComparisons6(d1, d2, false, false));
+ }
+ {
+ const std::deque<LessAndEqComp> d1, d2;
+ assert(testComparisons6(d1, d2, true, false));
+ }
+ {
+ const std::deque<LessAndEqComp> d1(1, LessAndEqComp(1));
+ const std::deque<LessAndEqComp> d2(1, LessAndEqComp(1));
+ assert(testComparisons6(d1, d2, true, false));
+ }
+ {
+ LessAndEqComp items[3] = {LessAndEqComp(1), LessAndEqComp(2), LessAndEqComp(3)};
+ const std::deque<LessAndEqComp> d1(items, items + 3);
+ const std::deque<LessAndEqComp> d2(items, items + 3);
+ assert(testComparisons6(d1, d2, true, false));
+ }
+ {
+ const std::deque<LessAndEqComp> d1(1, LessAndEqComp(1));
+ const std::deque<LessAndEqComp> d2;
+ assert(testComparisons6(d1, d2, false, false));
+ }
+ {
+ const std::deque<LessAndEqComp> d1(1, LessAndEqComp(1));
+ const std::deque<LessAndEqComp> d2(1, LessAndEqComp(2));
+ assert(testComparisons6(d1, d2, false, true));
+ }
+ {
+ LessAndEqComp items1[2] = {LessAndEqComp(1), LessAndEqComp(2)};
+ LessAndEqComp items2[2] = {LessAndEqComp(1), LessAndEqComp(3)};
+ const std::deque<LessAndEqComp> d1(items1, items1 + 2);
+ const std::deque<LessAndEqComp> d2(items2, items2 + 2);
+ assert(testComparisons6(d1, d2, false, true));
+ }
+ {
+ LessAndEqComp items1[2] = {LessAndEqComp(2), LessAndEqComp(2)};
+ LessAndEqComp items2[2] = {LessAndEqComp(1), LessAndEqComp(3)};
+ const std::deque<LessAndEqComp> d1(items1, items1 + 2);
+ const std::deque<LessAndEqComp> d2(items2, items2 + 2);
+ assert(testComparisons6(d1, d2, false, false));
+ }
+
+ return 0;
+}
diff --git a/libcxx/test/std/containers/sequences/list/compare.pass.cpp b/libcxx/test/std/containers/sequences/list/compare.pass.cpp
new file mode 100644
index 0000000000000..59314922e3e80
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/list/compare.pass.cpp
@@ -0,0 +1,117 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <list>
+
+// template< class T, class Alloc >
+// bool operator==( const std::list<T,Alloc>& lhs,
+// const std::list<T,Alloc>& rhs );
+
+// template< class T, class Alloc >
+// bool operator!=( const std::list<T,Alloc>& lhs,
+// const std::list<T,Alloc>& rhs );
+
+// template< class T, class Alloc >
+// bool operator<( const std::list<T,Alloc>& lhs,
+// const std::list<T,Alloc>& rhs );
+
+// template< class T, class Alloc >
+// bool operator<=( const std::list<T,Alloc>& lhs,
+// const std::list<T,Alloc>& rhs );
+
+// template< class T, class Alloc >
+// bool operator>( const std::list<T,Alloc>& lhs,
+// const std::list<T,Alloc>& rhs );
+
+// template< class T, class Alloc >
+// bool operator>=( const std::list<T,Alloc>& lhs,
+// const std::list<T,Alloc>& rhs );
+
+#include <list>
+#include <cassert>
+
+#include "test_comparisons.h"
+
+int main(int, char**) {
+ {
+ const std::list<int> l1, l2;
+ assert(testComparisons6(l1, l2, true, false));
+ }
+ {
+ const std::list<int> l1(1, 1), l2(1, 1);
+ assert(testComparisons6(l1, l2, true, false));
+ }
+ {
+ int items[3] = {1, 2, 3};
+ const std::list<int> l1(items, items + 3);
+ const std::list<int> l2(items, items + 3);
+ assert(testComparisons6(l1, l2, true, false));
+ }
+ {
+ const std::list<int> l1(1, 1), l2;
+ assert(testComparisons6(l1, l2, false, false));
+ }
+ {
+ const std::list<int> l1(1, 1), l2(1, 2);
+ assert(testComparisons6(l1, l2, false, true));
+ }
+ {
+ int items1[2] = {1, 2};
+ int items2[2] = {1, 3};
+ const std::list<int> l1(items1, items1 + 2);
+ const std::list<int> l2(items2, items2 + 2);
+ assert(testComparisons6(l1, l2, false, true));
+ }
+ {
+ int items1[2] = {2, 2};
+ int items2[2] = {1, 3};
+ const std::list<int> l1(items1, items1 + 2);
+ const std::list<int> l2(items2, items2 + 2);
+ assert(testComparisons6(l1, l2, false, false));
+ }
+ {
+ const std::list<LessAndEqComp> l1, l2;
+ assert(testComparisons6(l1, l2, true, false));
+ }
+ {
+ const std::list<LessAndEqComp> l1(1, LessAndEqComp(1));
+ const std::list<LessAndEqComp> l2(1, LessAndEqComp(1));
+ assert(testComparisons6(l1, l2, true, false));
+ }
+ {
+ LessAndEqComp items[3] = {LessAndEqComp(1), LessAndEqComp(2), LessAndEqComp(3)};
+ const std::list<LessAndEqComp> l1(items, items + 3);
+ const std::list<LessAndEqComp> l2(items, items + 3);
+ assert(testComparisons6(l1, l2, true, false));
+ }
+ {
+ const std::list<LessAndEqComp> l1(1, LessAndEqComp(1));
+ const std::list<LessAndEqComp> l2;
+ assert(testComparisons6(l1, l2, false, false));
+ }
+ {
+ const std::list<LessAndEqComp> l1(1, LessAndEqComp(1));
+ const std::list<LessAndEqComp> l2(1, LessAndEqComp(2));
+ assert(testComparisons6(l1, l2, false, true));
+ }
+ {
+ LessAndEqComp items1[2] = {LessAndEqComp(1), LessAndEqComp(2)};
+ LessAndEqComp items2[2] = {LessAndEqComp(1), LessAndEqComp(3)};
+ const std::list<LessAndEqComp> l1(items1, items1 + 2);
+ const std::list<LessAndEqComp> l2(items2, items2 + 2);
+ assert(testComparisons6(l1, l2, false, true));
+ }
+ {
+ LessAndEqComp items1[2] = {LessAndEqComp(2), LessAndEqComp(2)};
+ LessAndEqComp items2[2] = {LessAndEqComp(1), LessAndEqComp(3)};
+ const std::list<LessAndEqComp> l1(items1, items1 + 2);
+ const std::list<LessAndEqComp> l2(items2, items2 + 2);
+ assert(testComparisons6(l1, l2, false, false));
+ }
+ return 0;
+}
diff --git a/libcxx/test/std/containers/sequences/vector.bool/compare.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/compare.pass.cpp
new file mode 100644
index 0000000000000..60fede4f3061b
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/vector.bool/compare.pass.cpp
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+
+// bool operator==( const vector& lhs, const vector& rhs );
+// bool operator!=( const vector& lhs, const vector& rhs );
+// bool operator< ( const vector& lhs, const vector& rhs );
+// bool operator<=( const vector& lhs, const vector& rhs );
+// bool operator> ( const vector& lhs, const vector& rhs );
+// bool operator>=( const vector& lhs, const vector& rhs );
+
+#include <vector>
+#include <cassert>
+
+#include "test_comparisons.h"
+
+int main(int, char**) {
+ typedef std::vector<bool> VB;
+ {
+ const VB v1, v2;
+ assert(testComparisons6(v1, v2, true, false));
+ }
+ {
+ const VB v1(1, true);
+ const VB v2(1, true);
+ assert(testComparisons6(v1, v2, true, false));
+ }
+ {
+ const VB v1(1, false);
+ const VB v2(1, true);
+ assert(testComparisons6(v1, v2, false, true));
+ }
+ {
+ const VB v1, v2(1, true);
+ assert(testComparisons6(v1, v2, false, true));
+ }
+ {
+ bool items1[3] = {false, true, false};
+ bool items2[3] = {false, true, true};
+ const VB v1(items1, items1 + 3);
+ const VB v2(items2, items2 + 3);
+ assert(testComparisons6(v1, v2, false, true));
+ }
+ {
+ bool items1[3] = {false, false, false};
+ bool items2[3] = {false, true, false};
+ const VB v1(items1, items1 + 3);
+ const VB v2(items2, items2 + 3);
+ assert(testComparisons6(v1, v2, false, true));
+ }
+ {
+ bool items1[2] = {false, true};
+ bool items2[3] = {false, true, false};
+ const VB v1(items1, items1 + 2);
+ const VB v2(items2, items2 + 3);
+ assert(testComparisons6(v1, v2, false, true));
+ }
+ {
+ bool items[3] = {false, true, false};
+ const VB v1(items, items + 3);
+ const VB v2(1, true);
+ assert(testComparisons6(v1, v2, false, true));
+ }
+ {
+ assert( (std::vector<bool>() == std::vector<bool>()));
+ assert(!(std::vector<bool>() != std::vector<bool>()));
+ assert(!(std::vector<bool>() < std::vector<bool>()));
+ assert( (std::vector<bool>() <= std::vector<bool>()));
+ assert(!(std::vector<bool>() > std::vector<bool>()));
+ assert( (std::vector<bool>() >= std::vector<bool>()));
+ }
+
+ return 0;
+}
diff --git a/libcxx/test/std/containers/unord/unord.map/eq.pass.cpp b/libcxx/test/std/containers/unord/unord.map/eq.pass.cpp
index 5c924f07e5376..bcb6cb78adac4 100644
--- a/libcxx/test/std/containers/unord/unord.map/eq.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.map/eq.pass.cpp
@@ -25,6 +25,8 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "test_comparisons.h"
+
int main(int, char**)
{
{
@@ -43,8 +45,7 @@ int main(int, char**)
};
const C c1(std::begin(a), std::end(a));
const C c2;
- assert(!(c1 == c2));
- assert( (c1 != c2));
+ assert(testComparisons2(c1, c2, false));
}
{
typedef std::unordered_map<int, std::string> C;
@@ -62,8 +63,7 @@ int main(int, char**)
};
const C c1(std::begin(a), std::end(a));
const C c2 = c1;
- assert( (c1 == c2));
- assert(!(c1 != c2));
+ assert(testComparisons2(c1, c2, true));
}
{
typedef std::unordered_map<int, std::string> C;
@@ -82,14 +82,32 @@ int main(int, char**)
C c1(std::begin(a), std::end(a));
C c2 = c1;
c2.rehash(30);
- assert( (c1 == c2));
- assert(!(c1 != c2));
+ assert(testComparisons2(c1, c2, true));
c2.insert(P(90, "ninety"));
- assert(!(c1 == c2));
- assert( (c1 != c2));
+ assert(testComparisons2(c1, c2, false));
+ c1.insert(P(90, "ninety"));
+ assert(testComparisons2(c1, c2, true));
+ }
+ {
+ typedef std::unordered_map<int, std::string> C;
+ typedef std::pair<int, std::string> P;
+ P a[] =
+ {
+ P(10, "ten"),
+ P(20, "twenty"),
+ P(30, "thirty"),
+ P(40, "forty"),
+ P(50, "fifty"),
+ P(60, "sixty"),
+ P(70, "seventy"),
+ P(80, "eighty"),
+ };
+ C c1(std::begin(a), std::end(a));
+ C c2 = c1;
+ assert(testComparisons2(c1, c2, true));
c1.insert(P(90, "ninety"));
- assert( (c1 == c2));
- assert(!(c1 != c2));
+ c2.insert(P(100, "onehundred"));
+ assert(testComparisons2(c1, c2, false));
}
#if TEST_STD_VER >= 11
{
@@ -109,8 +127,7 @@ int main(int, char**)
};
const C c1(std::begin(a), std::end(a));
const C c2;
- assert(!(c1 == c2));
- assert( (c1 != c2));
+ assert(testComparisons2(c1, c2, false));
}
{
typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
@@ -129,8 +146,7 @@ int main(int, char**)
};
const C c1(std::begin(a), std::end(a));
const C c2 = c1;
- assert( (c1 == c2));
- assert(!(c1 != c2));
+ assert(testComparisons2(c1, c2, true));
}
{
typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
@@ -150,14 +166,33 @@ int main(int, char**)
C c1(std::begin(a), std::end(a));
C c2 = c1;
c2.rehash(30);
- assert( (c1 == c2));
- assert(!(c1 != c2));
+ assert(testComparisons2(c1, c2, true));
c2.insert(P(90, "ninety"));
- assert(!(c1 == c2));
- assert( (c1 != c2));
+ assert(testComparisons2(c1, c2, false));
+ c1.insert(P(90, "ninety"));
+ assert(testComparisons2(c1, c2, true));
+ }
+ {
+ typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
+ min_allocator<std::pair<const int, std::string>>> C;
+ typedef std::pair<int, std::string> P;
+ P a[] =
+ {
+ P(10, "ten"),
+ P(20, "twenty"),
+ P(30, "thirty"),
+ P(40, "forty"),
+ P(50, "fifty"),
+ P(60, "sixty"),
+ P(70, "seventy"),
+ P(80, "eighty"),
+ };
+ C c1(std::begin(a), std::end(a));
+ C c2 = c1;
+ assert(testComparisons2(c1, c2, true));
c1.insert(P(90, "ninety"));
- assert( (c1 == c2));
- assert(!(c1 != c2));
+ c2.insert(P(100, "onehundred"));
+ assert(testComparisons2(c1, c2, false));
}
#endif
diff --git a/libcxx/test/std/containers/unord/unord.multimap/eq.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/eq.pass.cpp
index b47fa32529e0e..1ebf1206d9a87 100644
--- a/libcxx/test/std/containers/unord/unord.multimap/eq.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.multimap/eq.pass.cpp
@@ -25,6 +25,8 @@
#include "test_macros.h"
#include "min_allocator.h"
+#include "test_comparisons.h"
+
int main(int, char**)
{
{
@@ -46,8 +48,7 @@ int main(int, char**)
};
const C c1(std::begin(a), std::end(a));
const C c2;
- assert(!(c1 == c2));
- assert( (c1 != c2));
+ assert(testComparisons2(c1, c2, false));
}
{
typedef std::unordered_multimap<int, std::string> C;
@@ -68,8 +69,7 @@ int main(int, char**)
};
const C c1(std::begin(a), std::end(a));
const C c2 = c1;
- assert( (c1 == c2));
- assert(!(c1 != c2));
+ assert(testComparisons2(c1, c2, true));
}
{
typedef std::unordered_multimap<int, std::string> C;
@@ -91,14 +91,35 @@ int main(int, char**)
C c1(std::begin(a), std::end(a));
C c2 = c1;
c2.rehash(30);
- assert( (c1 == c2));
- assert(!(c1 != c2));
+ assert(testComparisons2(c1, c2, true));
c2.insert(P(90, "ninety"));
- assert(!(c1 == c2));
- assert( (c1 != c2));
+ assert(testComparisons2(c1, c2, false));
c1.insert(P(90, "ninety"));
- assert( (c1 == c2));
- assert(!(c1 != c2));
+ assert(testComparisons2(c1, c2, true));
+ }
+ {
+ typedef std::unordered_multimap<int, std::string> C;
+ typedef std::pair<int, std::string> P;
+ P a[] =
+ {
+ P(10, "ten"),
+ P(20, "twenty"),
+ P(20, "twenty 2"),
+ P(30, "thirty"),
+ P(40, "forty"),
+ P(50, "fifty"),
+ P(50, "fifty 2"),
+ P(50, "fifty 3"),
+ P(60, "sixty"),
+ P(70, "seventy"),
+ P(80, "eighty"),
+ };
+ C c1(std::begin(a), std::end(a));
+ C c2 = c1;
+ assert(testComparisons2(c1, c2, true));
+ c1.insert(P(70, "seventy 2"));
+ c2.insert(P(80, "eighty 2"));
+ assert(testComparisons2(c1, c2, false));
}
#if TEST_STD_VER >= 11
{
@@ -121,8 +142,7 @@ int main(int, char**)
};
const C c1(std::begin(a), std::end(a));
const C c2;
- assert(!(c1 == c2));
- assert( (c1 != c2));
+ assert(testComparisons2(c1, c2, false));
}
{
typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
@@ -144,8 +164,7 @@ int main(int, char**)
};
const C c1(std::begin(a), std::end(a));
const C c2 = c1;
- assert( (c1 == c2));
- assert(!(c1 != c2));
+ assert(testComparisons2(c1, c2, true));
}
{
typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
@@ -168,14 +187,36 @@ int main(int, char**)
C c1(std::begin(a), std::end(a));
C c2 = c1;
c2.rehash(30);
- assert( (c1 == c2));
- assert(!(c1 != c2));
+ assert(testComparisons2(c1, c2, true));
c2.insert(P(90, "ninety"));
- assert(!(c1 == c2));
- assert( (c1 != c2));
+ assert(testComparisons2(c1, c2, false));
c1.insert(P(90, "ninety"));
- assert( (c1 == c2));
- assert(!(c1 != c2));
+ assert(testComparisons2(c1, c2, true));
+ }
+ {
+ typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
+ min_allocator<std::pair<const int, std::string>>> C;
+ typedef std::pair<int, std::string> P;
+ P a[] =
+ {
+ P(10, "ten"),
+ P(20, "twenty"),
+ P(20, "twenty 2"),
+ P(30, "thirty"),
+ P(40, "forty"),
+ P(50, "fifty"),
+ P(50, "fifty 2"),
+ P(50, "fifty 3"),
+ P(60, "sixty"),
+ P(70, "seventy"),
+ P(80, "eighty"),
+ };
+ C c1(std::begin(a), std::end(a));
+ C c2 = c1;
+ assert(testComparisons2(c1, c2, true));
+ c1.insert(P(70, "seventy 2"));
+ c2.insert(P(80, "eighty 2"));
+ assert(testComparisons2(c1, c2, false));
}
#endif
diff --git a/libcxx/test/support/test_comparisons.h b/libcxx/test/support/test_comparisons.h
index 9d666545abdf8..90440f4b18d61 100644
--- a/libcxx/test/support/test_comparisons.h
+++ b/libcxx/test/support/test_comparisons.h
@@ -176,13 +176,13 @@ void AssertComparisons2ConvertibleToBool()
struct LessAndEqComp {
int value;
- LessAndEqComp(int v) : value(v) {}
+ TEST_CONSTEXPR_CXX14 LessAndEqComp(int v) : value(v) {}
- friend bool operator<(const LessAndEqComp& lhs, const LessAndEqComp& rhs) {
+ friend TEST_CONSTEXPR_CXX14 bool operator<(const LessAndEqComp& lhs, const LessAndEqComp& rhs) {
return lhs.value < rhs.value;
}
- friend bool operator==(const LessAndEqComp& lhs, const LessAndEqComp& rhs) {
+ friend TEST_CONSTEXPR_CXX14 bool operator==(const LessAndEqComp& lhs, const LessAndEqComp& rhs) {
return lhs.value == rhs.value;
}
};
More information about the libcxx-commits
mailing list