Skip to content

Commit 97b3339

Browse files
committed
Move keyed_binary_search tests to their own file
1 parent 82d8085 commit 97b3339

File tree

3 files changed

+125
-116
lines changed

3 files changed

+125
-116
lines changed

source/containers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ target_sources(containers_test PRIVATE
230230
test/algorithms/erase.cpp
231231
test/algorithms/filter.cpp
232232
test/algorithms/join.cpp
233+
test/algorithms/keyed_binary_search.cpp
233234
test/algorithms/set.cpp
234235
test/algorithms/split.cpp
235236
test/algorithms/zip.cpp

source/containers/algorithms/keyed_binary_search.cpp

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ export module containers.algorithms.keyed_binary_search;
1111

1212
import containers.algorithms.binary_search;
1313
import containers.associative_container;
14-
import containers.array;
15-
import containers.begin_end;
16-
import containers.c_array;
17-
import containers.map_value_type;
18-
19-
import bounded;
20-
import std_module;
2114

2215
namespace containers {
2316

@@ -46,112 +39,3 @@ export constexpr auto keyed_equal_range(associative_range auto && map, auto && k
4639
}
4740

4841
} // namespace containers
49-
50-
using namespace bounded::literal;
51-
52-
struct compare_t {
53-
static constexpr auto operator()(containers::map_value_type<int, int> const lhs, int const rhs) -> bool {
54-
return lhs.key < rhs;
55-
}
56-
static constexpr auto operator()(int const lhs, containers::map_value_type<int, int> const rhs) -> bool {
57-
return lhs < rhs.key;
58-
}
59-
static constexpr auto operator()(int const lhs, int const rhs) -> bool {
60-
return lhs < rhs;
61-
}
62-
};
63-
64-
template<auto size_>
65-
struct map_type {
66-
using key_type = int;
67-
using mapped_type = int;
68-
69-
map_type() = default;
70-
template<std::size_t size> requires(bounded::constant<size> == size_)
71-
explicit constexpr map_type(containers::c_array<containers::map_value_type<int, int>, size> && source):
72-
m_data(to_array(source))
73-
{
74-
}
75-
76-
constexpr auto begin() const {
77-
return containers::begin(m_data);
78-
}
79-
static constexpr auto size() {
80-
return size_;
81-
}
82-
static constexpr auto compare() {
83-
return compare_t();
84-
}
85-
86-
containers::array<containers::map_value_type<int, int>, size_> m_data;
87-
};
88-
89-
constexpr auto zero = map_type<0_bi>();
90-
static_assert(containers::keyed_lower_bound(zero, 0) == containers::end(zero));
91-
static_assert(containers::keyed_upper_bound(zero, 0) == containers::end(zero));
92-
93-
constexpr auto one = map_type<1_bi>({{1, 0}});
94-
static_assert(containers::keyed_lower_bound(one, 0) == containers::begin(one));
95-
static_assert(containers::keyed_lower_bound(one, 1) == containers::begin(one));
96-
static_assert(containers::keyed_lower_bound(one, 2) == containers::end(one));
97-
static_assert(containers::keyed_upper_bound(one, 0) == containers::begin(one));
98-
static_assert(containers::keyed_upper_bound(one, 1) == containers::end(one));
99-
static_assert(containers::keyed_upper_bound(one, 2) == containers::end(one));
100-
101-
constexpr auto two = map_type<2_bi>({{1, 0}, {2, 0}});
102-
static_assert(containers::keyed_lower_bound(two, 0) == containers::begin(two) + 0_bi);
103-
static_assert(containers::keyed_lower_bound(two, 1) == containers::begin(two) + 0_bi);
104-
static_assert(containers::keyed_lower_bound(two, 2) == containers::begin(two) + 1_bi);
105-
static_assert(containers::keyed_lower_bound(two, 3) == containers::end(two));
106-
static_assert(containers::keyed_upper_bound(two, 0) == containers::begin(two) + 0_bi);
107-
static_assert(containers::keyed_upper_bound(two, 1) == containers::begin(two) + 1_bi);
108-
static_assert(containers::keyed_upper_bound(two, 2) == containers::begin(two) + 2_bi);
109-
static_assert(containers::keyed_upper_bound(two, 3) == containers::end(two));
110-
111-
constexpr auto three = map_type<3_bi>({{1, 0}, {2, 0}, {3, 0}});
112-
static_assert(containers::keyed_lower_bound(three, 0) == containers::begin(three) + 0_bi);
113-
static_assert(containers::keyed_lower_bound(three, 1) == containers::begin(three) + 0_bi);
114-
static_assert(containers::keyed_lower_bound(three, 2) == containers::begin(three) + 1_bi);
115-
static_assert(containers::keyed_lower_bound(three, 3) == containers::begin(three) + 2_bi);
116-
static_assert(containers::keyed_lower_bound(three, 4) == containers::end(three));
117-
static_assert(containers::keyed_upper_bound(three, 0) == containers::begin(three) + 0_bi);
118-
static_assert(containers::keyed_upper_bound(three, 1) == containers::begin(three) + 1_bi);
119-
static_assert(containers::keyed_upper_bound(three, 2) == containers::begin(three) + 2_bi);
120-
static_assert(containers::keyed_upper_bound(three, 3) == containers::begin(three) + 3_bi);
121-
static_assert(containers::keyed_upper_bound(three, 4) == containers::end(three));
122-
123-
constexpr auto two_duplicates = map_type<2_bi>({{1, 0}, {1, 0}});
124-
static_assert(containers::keyed_lower_bound(two_duplicates, 0) == containers::begin(two_duplicates) + 0_bi);
125-
static_assert(containers::keyed_lower_bound(two_duplicates, 1) == containers::begin(two_duplicates) + 0_bi);
126-
static_assert(containers::keyed_lower_bound(two_duplicates, 2) == containers::end(two_duplicates));
127-
static_assert(containers::keyed_upper_bound(two_duplicates, 0) == containers::begin(two_duplicates) + 0_bi);
128-
static_assert(containers::keyed_upper_bound(two_duplicates, 1) == containers::end(two_duplicates));
129-
static_assert(containers::keyed_upper_bound(two_duplicates, 2) == containers::end(two_duplicates));
130-
131-
constexpr auto three_duplicates = map_type<3_bi>({{1, 0}, {1, 0}, {1, 0}});
132-
static_assert(containers::keyed_lower_bound(three_duplicates, 0) == containers::begin(three_duplicates) + 0_bi);
133-
static_assert(containers::keyed_lower_bound(three_duplicates, 1) == containers::begin(three_duplicates) + 0_bi);
134-
static_assert(containers::keyed_lower_bound(three_duplicates, 2) == containers::end(three_duplicates));
135-
static_assert(containers::keyed_upper_bound(three_duplicates, 0) == containers::begin(three_duplicates) + 0_bi);
136-
static_assert(containers::keyed_upper_bound(three_duplicates, 1) == containers::end(three_duplicates));
137-
static_assert(containers::keyed_upper_bound(three_duplicates, 2) == containers::end(three_duplicates));
138-
139-
constexpr auto three_two_duplicates_first = map_type<3_bi>({{1, 0}, {1, 0}, {2, 0}});
140-
static_assert(containers::keyed_lower_bound(three_two_duplicates_first, 0) == containers::begin(three_two_duplicates_first) + 0_bi);
141-
static_assert(containers::keyed_lower_bound(three_two_duplicates_first, 1) == containers::begin(three_two_duplicates_first) + 0_bi);
142-
static_assert(containers::keyed_lower_bound(three_two_duplicates_first, 2) == containers::begin(three_two_duplicates_first) + 2_bi);
143-
static_assert(containers::keyed_lower_bound(three_two_duplicates_first, 3) == containers::end(three_two_duplicates_first));
144-
static_assert(containers::keyed_upper_bound(three_two_duplicates_first, 0) == containers::begin(three_two_duplicates_first) + 0_bi);
145-
static_assert(containers::keyed_upper_bound(three_two_duplicates_first, 1) == containers::begin(three_two_duplicates_first) + 2_bi);
146-
static_assert(containers::keyed_upper_bound(three_two_duplicates_first, 2) == containers::begin(three_two_duplicates_first) + 3_bi);
147-
static_assert(containers::keyed_upper_bound(three_two_duplicates_first, 3) == containers::end(three_two_duplicates_first));
148-
149-
constexpr auto three_two_duplicates_last = map_type<3_bi>({{1, 0}, {2, 0}, {2, 0}});
150-
static_assert(containers::keyed_lower_bound(three_two_duplicates_last, 0) == containers::begin(three_two_duplicates_last) + 0_bi);
151-
static_assert(containers::keyed_lower_bound(three_two_duplicates_last, 1) == containers::begin(three_two_duplicates_last) + 0_bi);
152-
static_assert(containers::keyed_lower_bound(three_two_duplicates_last, 2) == containers::begin(three_two_duplicates_last) + 1_bi);
153-
static_assert(containers::keyed_lower_bound(three_two_duplicates_last, 3) == containers::end(three_two_duplicates_last));
154-
static_assert(containers::keyed_upper_bound(three_two_duplicates_last, 0) == containers::begin(three_two_duplicates_last) + 0_bi);
155-
static_assert(containers::keyed_upper_bound(three_two_duplicates_last, 1) == containers::begin(three_two_duplicates_last) + 1_bi);
156-
static_assert(containers::keyed_upper_bound(three_two_duplicates_last, 2) == containers::begin(three_two_duplicates_last) + 3_bi);
157-
static_assert(containers::keyed_upper_bound(three_two_duplicates_last, 3) == containers::end(three_two_duplicates_last));
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright David Stone 2024.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
export module containers.algorithms.test.keyed_binary_search;
7+
8+
import containers.algorithms.keyed_binary_search;
9+
import containers.array;
10+
import containers.begin_end;
11+
import containers.c_array;
12+
import containers.map_value_type;
13+
14+
import bounded;
15+
import std_module;
16+
17+
using namespace bounded::literal;
18+
19+
struct compare_t {
20+
static constexpr auto operator()(containers::map_value_type<int, int> const lhs, int const rhs) -> bool {
21+
return lhs.key < rhs;
22+
}
23+
static constexpr auto operator()(int const lhs, containers::map_value_type<int, int> const rhs) -> bool {
24+
return lhs < rhs.key;
25+
}
26+
static constexpr auto operator()(int const lhs, int const rhs) -> bool {
27+
return lhs < rhs;
28+
}
29+
};
30+
31+
template<auto size_>
32+
struct map_type {
33+
using key_type = int;
34+
using mapped_type = int;
35+
36+
map_type() = default;
37+
template<std::size_t size> requires(bounded::constant<size> == size_)
38+
explicit constexpr map_type(containers::c_array<containers::map_value_type<int, int>, size> && source):
39+
m_data(to_array(source))
40+
{
41+
}
42+
43+
constexpr auto begin() const {
44+
return containers::begin(m_data);
45+
}
46+
static constexpr auto size() {
47+
return size_;
48+
}
49+
static constexpr auto compare() {
50+
return compare_t();
51+
}
52+
53+
containers::array<containers::map_value_type<int, int>, size_> m_data;
54+
};
55+
56+
constexpr auto zero = map_type<0_bi>();
57+
static_assert(containers::keyed_lower_bound(zero, 0) == containers::end(zero));
58+
static_assert(containers::keyed_upper_bound(zero, 0) == containers::end(zero));
59+
60+
constexpr auto one = map_type<1_bi>({{1, 0}});
61+
static_assert(containers::keyed_lower_bound(one, 0) == containers::begin(one));
62+
static_assert(containers::keyed_lower_bound(one, 1) == containers::begin(one));
63+
static_assert(containers::keyed_lower_bound(one, 2) == containers::end(one));
64+
static_assert(containers::keyed_upper_bound(one, 0) == containers::begin(one));
65+
static_assert(containers::keyed_upper_bound(one, 1) == containers::end(one));
66+
static_assert(containers::keyed_upper_bound(one, 2) == containers::end(one));
67+
68+
constexpr auto two = map_type<2_bi>({{1, 0}, {2, 0}});
69+
static_assert(containers::keyed_lower_bound(two, 0) == containers::begin(two) + 0_bi);
70+
static_assert(containers::keyed_lower_bound(two, 1) == containers::begin(two) + 0_bi);
71+
static_assert(containers::keyed_lower_bound(two, 2) == containers::begin(two) + 1_bi);
72+
static_assert(containers::keyed_lower_bound(two, 3) == containers::end(two));
73+
static_assert(containers::keyed_upper_bound(two, 0) == containers::begin(two) + 0_bi);
74+
static_assert(containers::keyed_upper_bound(two, 1) == containers::begin(two) + 1_bi);
75+
static_assert(containers::keyed_upper_bound(two, 2) == containers::begin(two) + 2_bi);
76+
static_assert(containers::keyed_upper_bound(two, 3) == containers::end(two));
77+
78+
constexpr auto three = map_type<3_bi>({{1, 0}, {2, 0}, {3, 0}});
79+
static_assert(containers::keyed_lower_bound(three, 0) == containers::begin(three) + 0_bi);
80+
static_assert(containers::keyed_lower_bound(three, 1) == containers::begin(three) + 0_bi);
81+
static_assert(containers::keyed_lower_bound(three, 2) == containers::begin(three) + 1_bi);
82+
static_assert(containers::keyed_lower_bound(three, 3) == containers::begin(three) + 2_bi);
83+
static_assert(containers::keyed_lower_bound(three, 4) == containers::end(three));
84+
static_assert(containers::keyed_upper_bound(three, 0) == containers::begin(three) + 0_bi);
85+
static_assert(containers::keyed_upper_bound(three, 1) == containers::begin(three) + 1_bi);
86+
static_assert(containers::keyed_upper_bound(three, 2) == containers::begin(three) + 2_bi);
87+
static_assert(containers::keyed_upper_bound(three, 3) == containers::begin(three) + 3_bi);
88+
static_assert(containers::keyed_upper_bound(three, 4) == containers::end(three));
89+
90+
constexpr auto two_duplicates = map_type<2_bi>({{1, 0}, {1, 0}});
91+
static_assert(containers::keyed_lower_bound(two_duplicates, 0) == containers::begin(two_duplicates) + 0_bi);
92+
static_assert(containers::keyed_lower_bound(two_duplicates, 1) == containers::begin(two_duplicates) + 0_bi);
93+
static_assert(containers::keyed_lower_bound(two_duplicates, 2) == containers::end(two_duplicates));
94+
static_assert(containers::keyed_upper_bound(two_duplicates, 0) == containers::begin(two_duplicates) + 0_bi);
95+
static_assert(containers::keyed_upper_bound(two_duplicates, 1) == containers::end(two_duplicates));
96+
static_assert(containers::keyed_upper_bound(two_duplicates, 2) == containers::end(two_duplicates));
97+
98+
constexpr auto three_duplicates = map_type<3_bi>({{1, 0}, {1, 0}, {1, 0}});
99+
static_assert(containers::keyed_lower_bound(three_duplicates, 0) == containers::begin(three_duplicates) + 0_bi);
100+
static_assert(containers::keyed_lower_bound(three_duplicates, 1) == containers::begin(three_duplicates) + 0_bi);
101+
static_assert(containers::keyed_lower_bound(three_duplicates, 2) == containers::end(three_duplicates));
102+
static_assert(containers::keyed_upper_bound(three_duplicates, 0) == containers::begin(three_duplicates) + 0_bi);
103+
static_assert(containers::keyed_upper_bound(three_duplicates, 1) == containers::end(three_duplicates));
104+
static_assert(containers::keyed_upper_bound(three_duplicates, 2) == containers::end(three_duplicates));
105+
106+
constexpr auto three_two_duplicates_first = map_type<3_bi>({{1, 0}, {1, 0}, {2, 0}});
107+
static_assert(containers::keyed_lower_bound(three_two_duplicates_first, 0) == containers::begin(three_two_duplicates_first) + 0_bi);
108+
static_assert(containers::keyed_lower_bound(three_two_duplicates_first, 1) == containers::begin(three_two_duplicates_first) + 0_bi);
109+
static_assert(containers::keyed_lower_bound(three_two_duplicates_first, 2) == containers::begin(three_two_duplicates_first) + 2_bi);
110+
static_assert(containers::keyed_lower_bound(three_two_duplicates_first, 3) == containers::end(three_two_duplicates_first));
111+
static_assert(containers::keyed_upper_bound(three_two_duplicates_first, 0) == containers::begin(three_two_duplicates_first) + 0_bi);
112+
static_assert(containers::keyed_upper_bound(three_two_duplicates_first, 1) == containers::begin(three_two_duplicates_first) + 2_bi);
113+
static_assert(containers::keyed_upper_bound(three_two_duplicates_first, 2) == containers::begin(three_two_duplicates_first) + 3_bi);
114+
static_assert(containers::keyed_upper_bound(three_two_duplicates_first, 3) == containers::end(three_two_duplicates_first));
115+
116+
constexpr auto three_two_duplicates_last = map_type<3_bi>({{1, 0}, {2, 0}, {2, 0}});
117+
static_assert(containers::keyed_lower_bound(three_two_duplicates_last, 0) == containers::begin(three_two_duplicates_last) + 0_bi);
118+
static_assert(containers::keyed_lower_bound(three_two_duplicates_last, 1) == containers::begin(three_two_duplicates_last) + 0_bi);
119+
static_assert(containers::keyed_lower_bound(three_two_duplicates_last, 2) == containers::begin(three_two_duplicates_last) + 1_bi);
120+
static_assert(containers::keyed_lower_bound(three_two_duplicates_last, 3) == containers::end(three_two_duplicates_last));
121+
static_assert(containers::keyed_upper_bound(three_two_duplicates_last, 0) == containers::begin(three_two_duplicates_last) + 0_bi);
122+
static_assert(containers::keyed_upper_bound(three_two_duplicates_last, 1) == containers::begin(three_two_duplicates_last) + 1_bi);
123+
static_assert(containers::keyed_upper_bound(three_two_duplicates_last, 2) == containers::begin(three_two_duplicates_last) + 3_bi);
124+
static_assert(containers::keyed_upper_bound(three_two_duplicates_last, 3) == containers::end(three_two_duplicates_last));

0 commit comments

Comments
 (0)