Skip to content

Commit b625d5a

Browse files
committed
capacity test
1 parent 6f32101 commit b625d5a

File tree

3 files changed

+191
-0
lines changed

3 files changed

+191
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
11+
// <flat_set>
12+
13+
// [[nodiscard]] bool empty() const noexcept;
14+
15+
#include <flat_set>
16+
#include <cassert>
17+
#include <deque>
18+
#include <functional>
19+
#include <utility>
20+
#include <vector>
21+
22+
#include "MinSequenceContainer.h"
23+
#include "test_macros.h"
24+
#include "min_allocator.h"
25+
26+
template <class KeyContainer>
27+
void test_one() {
28+
using Key = typename KeyContainer::value_type;
29+
using M = std::flat_multiset<Key, std::less<int>, KeyContainer>;
30+
M m;
31+
ASSERT_SAME_TYPE(decltype(m.empty()), bool);
32+
ASSERT_NOEXCEPT(m.empty());
33+
assert(m.empty());
34+
assert(std::as_const(m).empty());
35+
m = {1};
36+
assert(!m.empty());
37+
m.clear();
38+
assert(m.empty());
39+
}
40+
41+
void test() {
42+
test_one<std::vector<int>>();
43+
test_one<std::deque<int>>();
44+
test_one<MinSequenceContainer<int>>();
45+
test_one<std::vector<int, min_allocator<int>>>();
46+
}
47+
48+
int main(int, char**) {
49+
test();
50+
51+
return 0;
52+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
11+
// <flat_set>
12+
13+
// size_type max_size() const noexcept;
14+
15+
#include <cassert>
16+
#include <deque>
17+
#include <flat_set>
18+
#include <functional>
19+
#include <limits>
20+
#include <type_traits>
21+
#include <vector>
22+
23+
#include "MinSequenceContainer.h"
24+
#include "test_allocator.h"
25+
#include "test_macros.h"
26+
27+
void test() {
28+
{
29+
using A1 = limited_allocator<int, 10>;
30+
using C = std::flat_multiset<int, std::less<int>, std::vector<int, A1>>;
31+
ASSERT_SAME_TYPE(C::difference_type, std::ptrdiff_t);
32+
ASSERT_SAME_TYPE(C::size_type, std::size_t);
33+
const C c;
34+
ASSERT_NOEXCEPT(c.max_size());
35+
ASSERT_SAME_TYPE(decltype(c.max_size()), C::size_type);
36+
assert(c.max_size() <= 10);
37+
LIBCPP_ASSERT(c.max_size() == 10);
38+
}
39+
{
40+
using A = limited_allocator<int, (size_t)-1>;
41+
using C = std::flat_multiset<int, std::less<int>, std::vector<int, A>>;
42+
ASSERT_SAME_TYPE(C::difference_type, std::ptrdiff_t);
43+
ASSERT_SAME_TYPE(C::size_type, std::size_t);
44+
const C::size_type max_dist = static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max());
45+
const C c;
46+
ASSERT_NOEXCEPT(c.max_size());
47+
ASSERT_SAME_TYPE(decltype(c.max_size()), C::size_type);
48+
assert(c.max_size() <= max_dist);
49+
LIBCPP_ASSERT(c.max_size() == max_dist);
50+
}
51+
{
52+
typedef std::flat_multiset<char> C;
53+
ASSERT_SAME_TYPE(C::difference_type, std::ptrdiff_t);
54+
ASSERT_SAME_TYPE(C::size_type, std::size_t);
55+
const C::size_type max_dist = static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max());
56+
const C c;
57+
ASSERT_NOEXCEPT(c.max_size());
58+
ASSERT_SAME_TYPE(decltype(c.max_size()), C::size_type);
59+
assert(c.max_size() <= max_dist);
60+
assert(c.max_size() <= alloc_max_size(std::allocator<char>()));
61+
}
62+
}
63+
64+
int main(int, char**) {
65+
test();
66+
67+
return 0;
68+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
11+
// <flat_set>
12+
13+
// size_type size() const noexcept;
14+
15+
#include <cassert>
16+
#include <deque>
17+
#include <flat_set>
18+
#include <functional>
19+
#include <vector>
20+
21+
#include "MinSequenceContainer.h"
22+
#include "test_macros.h"
23+
#include "min_allocator.h"
24+
25+
template <class KeyContainer>
26+
void test_one() {
27+
using M = std::flat_multiset<int, std::less<int>, KeyContainer>;
28+
using S = typename M::size_type;
29+
{
30+
const M m = {1, 1, 4, 5, 5};
31+
ASSERT_SAME_TYPE(decltype(m.size()), S);
32+
ASSERT_NOEXCEPT(m.size());
33+
assert(m.size() == 5);
34+
}
35+
{
36+
const M m = {1};
37+
ASSERT_SAME_TYPE(decltype(m.size()), S);
38+
ASSERT_NOEXCEPT(m.size());
39+
assert(m.size() == 1);
40+
}
41+
{
42+
const M m;
43+
ASSERT_SAME_TYPE(decltype(m.size()), S);
44+
ASSERT_NOEXCEPT(m.size());
45+
assert(m.size() == 0);
46+
}
47+
{
48+
M m;
49+
S s = 1000000;
50+
for (auto i = 0u; i < s; ++i) {
51+
m.emplace(i);
52+
m.emplace(i);
53+
}
54+
ASSERT_SAME_TYPE(decltype(m.size()), S);
55+
ASSERT_NOEXCEPT(m.size());
56+
assert(m.size() == 2 * s);
57+
}
58+
}
59+
60+
void test() {
61+
test_one<std::vector<int>>();
62+
test_one<std::deque<int>>();
63+
test_one<MinSequenceContainer<int>>();
64+
test_one<std::vector<int, min_allocator<int>>>();
65+
}
66+
67+
int main(int, char**) {
68+
test();
69+
70+
return 0;
71+
}

0 commit comments

Comments
 (0)