Skip to content

Commit 648f126

Browse files
committed
tests: match previous formatting
1 parent 61cc660 commit 648f126

File tree

1 file changed

+96
-89
lines changed

1 file changed

+96
-89
lines changed

libcxx/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp

Lines changed: 96 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -80,112 +80,119 @@ test_sort_()
8080
}
8181

8282
template <int N, int M>
83-
TEST_CONSTEXPR_CXX26 void test_larger_sorts() {
84-
static_assert(N != 0);
85-
static_assert(M != 0);
86-
87-
// create array length N filled with M different numbers
88-
std::array<int, N> array_;
89-
int* const array = array_.data();
90-
int x = 0;
91-
for (int i = 0; i < N; ++i) {
92-
array[i] = x;
93-
if (++x == M)
94-
x = 0;
95-
}
96-
// test saw tooth pattern
97-
std::stable_sort(array, array + N);
98-
assert(std::is_sorted(array, array + N));
99-
// test random pattern
83+
TEST_CONSTEXPR_CXX26
84+
void
85+
test_larger_sorts()
86+
{
87+
static_assert(N != 0);
88+
static_assert(M != 0);
89+
// create array length N filled with M different numbers
90+
std::array<int, N> array_;
91+
int* array = array_.data();
92+
int x = 0;
93+
for (int i = 0; i < N; ++i)
94+
{
95+
array[i] = x;
96+
if (++x == M)
97+
x = 0;
98+
}
99+
// test saw tooth pattern
100+
std::stable_sort(array, array+N);
101+
assert(std::is_sorted(array, array+N));
102+
// test random pattern
100103
#if TEST_STD_VER >= 26
101-
if !consteval // random-number generators not constexpr-friendly
104+
if !consteval // random-number generators not constexpr-friendly
102105
#endif
103-
{
104-
static std::mt19937 randomness;
105-
std::shuffle(array, array + N, randomness);
106-
std::stable_sort(array, array + N);
107-
assert(std::is_sorted(array, array + N));
108-
}
109-
// test sorted pattern
110-
std::stable_sort(array, array + N);
111-
assert(std::is_sorted(array, array + N));
112-
// test reverse sorted pattern
113-
std::reverse(array, array + N);
114-
std::stable_sort(array, array + N);
115-
assert(std::is_sorted(array, array + N));
116-
// test swap ranges 2 pattern
117-
std::swap_ranges(array, array + N / 2, array + N / 2);
118-
std::stable_sort(array, array + N);
119-
assert(std::is_sorted(array, array + N));
120-
// test reverse swap ranges 2 pattern
121-
std::reverse(array, array + N);
122-
std::swap_ranges(array, array + N / 2, array + N / 2);
123-
std::stable_sort(array, array + N);
124-
assert(std::is_sorted(array, array + N));
106+
{
107+
static std::mt19937 randomness;
108+
std::shuffle(array, array+N, randomness);
109+
std::stable_sort(array, array+N);
110+
assert(std::is_sorted(array, array+N));
111+
}
112+
// test sorted pattern
113+
std::stable_sort(array, array+N);
114+
assert(std::is_sorted(array, array+N));
115+
// test reverse sorted pattern
116+
std::reverse(array, array+N);
117+
std::stable_sort(array, array+N);
118+
assert(std::is_sorted(array, array+N));
119+
// test swap ranges 2 pattern
120+
std::swap_ranges(array, array+N/2, array+N/2);
121+
std::stable_sort(array, array+N);
122+
assert(std::is_sorted(array, array+N));
123+
// test reverse swap ranges 2 pattern
124+
std::reverse(array, array+N);
125+
std::swap_ranges(array, array+N/2, array+N/2);
126+
std::stable_sort(array, array+N);
127+
assert(std::is_sorted(array, array+N));
125128
}
126129

127130
template <int N>
128-
TEST_CONSTEXPR_CXX26 void test_larger_sorts() {
129-
test_larger_sorts<N, 1>();
130-
test_larger_sorts<N, 2>();
131-
test_larger_sorts<N, 3>();
132-
test_larger_sorts<N, N / 2 - 1>();
133-
test_larger_sorts<N, N / 2>();
134-
test_larger_sorts<N, N / 2 + 1>();
135-
test_larger_sorts<N, N - 2>();
136-
test_larger_sorts<N, N - 1>();
137-
test_larger_sorts<N, N>();
131+
TEST_CONSTEXPR_CXX26
132+
void
133+
test_larger_sorts()
134+
{
135+
test_larger_sorts<N, 1>();
136+
test_larger_sorts<N, 2>();
137+
test_larger_sorts<N, 3>();
138+
test_larger_sorts<N, N/2-1>();
139+
test_larger_sorts<N, N/2>();
140+
test_larger_sorts<N, N/2+1>();
141+
test_larger_sorts<N, N-2>();
142+
test_larger_sorts<N, N-1>();
143+
test_larger_sorts<N, N>();
138144
}
139145

140-
TEST_CONSTEXPR_CXX26 void test() {
141-
// test null range
142-
int d = 0;
143-
std::stable_sort(&d, &d);
144-
145-
// exhaustively test all possibilities up to length 8
146+
TEST_CONSTEXPR_CXX26 void test()
147+
{
148+
// test null range
149+
int d = 0;
150+
std::stable_sort(&d, &d);
151+
152+
// exhaustively test all possibilities up to length 8
146153
#if TEST_STD_VER >= 26
147-
if !consteval
154+
if !consteval
148155
#endif
149-
{
150-
test_sort_<1>();
151-
test_sort_<2>();
152-
test_sort_<3>();
153-
test_sort_<4>();
154-
test_sort_<5>();
155-
test_sort_<6>();
156-
test_sort_<7>();
157-
test_sort_<8>();
158-
}
159-
160-
test_larger_sorts<256>();
161-
test_larger_sorts<257>();
162-
test_larger_sorts<499>();
163-
test_larger_sorts<500>();
164-
test_larger_sorts<997>();
156+
{
157+
test_sort_<1>();
158+
test_sort_<2>();
159+
test_sort_<3>();
160+
test_sort_<4>();
161+
test_sort_<5>();
162+
test_sort_<6>();
163+
test_sort_<7>();
164+
test_sort_<8>();
165+
}
166+
167+
test_larger_sorts<256>();
168+
test_larger_sorts<257>();
169+
test_larger_sorts<499>();
170+
test_larger_sorts<500>();
171+
test_larger_sorts<997>();
165172
#if TEST_STD_VER >= 26
166-
if !consteval // only runtime tests bc. error: "constexpr evaluation hit maximum step limit"
173+
if !consteval // only runtime tests bc. error: "constexpr evaluation hit maximum step limit"
167174
#endif
168-
{
169-
test_larger_sorts<1000>();
170-
test_larger_sorts<1009>();
171-
}
175+
{
176+
test_larger_sorts<1000>();
177+
test_larger_sorts<1009>();
178+
}
172179

173180
#if !defined(TEST_HAS_NO_EXCEPTIONS)
174-
# if TEST_STD_VER >= 26
175-
if !consteval
176-
# endif
177-
{ // check that the algorithm works without memory
178-
std::vector<int> vec(150, 3);
179-
getGlobalMemCounter()->throw_after = 0;
180-
std::stable_sort(vec.begin(), vec.end());
181-
}
181+
#if TEST_STD_VER >= 26
182+
if !consteval
183+
#endif
184+
{ // check that the algorithm works without memory
185+
std::vector<int> vec(150, 3);
186+
getGlobalMemCounter()->throw_after = 0;
187+
std::stable_sort(vec.begin(), vec.end());
188+
}
182189
#endif // !defined(TEST_HAS_NO_EXCEPTIONS)
183190
}
184191

185192
int main(int, char**) {
186-
test();
193+
test();
187194
#if TEST_STD_VER >= 26
188-
static_assert((test(), true));
195+
static_assert((test(), true));
189196
#endif
190-
return 0;
197+
return 0;
191198
}

0 commit comments

Comments
 (0)