Skip to content

Commit 69ac3da

Browse files
committed
use ranges algorithms in tests for full-range std calls
Apply the same "prefer ranges" convention to the test suite: - iota(all(x), v) -> ranges::iota(x, v) - unique(all(x)) -> begin(ranges::unique(x)) (erase / == end idiom) - remove_if(all(x), pred) -> begin(ranges::remove_if(x, pred)) (erase idiom) - next_permutation(all(x)) -> ranges::next_permutation(x).found accumulate(all(x), ...) is left as-is: there is no ranges::accumulate in C++23 (ranges::fold_left would change the idiom), matching how partial_sum is left in the library.
1 parent 1dbbe8f commit 69ac3da

10 files changed

Lines changed: 15 additions & 15 deletions

tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main() {
1717
compress.push_back(x);
1818
}
1919
ranges::sort(compress);
20-
compress.erase(unique(all(compress)), end(compress));
20+
compress.erase(begin(ranges::unique(compress)), end(compress));
2121
BIT bit(sz(compress));
2222
auto get_compressed_idx = [&](int val) -> int {
2323
int l = 0, r = sz(compress);

tests/library_checker_aizu_tests/data_structures/kth_smallest_pst.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int main() {
1010
rep(i, 0, n) cin >> arr[i];
1111
vi sorted(arr);
1212
ranges::sort(sorted);
13-
sorted.erase(unique(all(sorted)), end(sorted));
13+
sorted.erase(begin(ranges::unique(sorted)), end(sorted));
1414
for (int& val : arr) {
1515
int start = 0, end = sz(sorted);
1616
while (start + 1 < end) {

tests/library_checker_aizu_tests/data_structures/mode_query.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int main() {
1010
rep(i, 0, n) cin >> a[i];
1111
vi comp(a);
1212
ranges::sort(comp);
13-
comp.erase(unique(all(comp)), end(comp));
13+
comp.erase(begin(ranges::unique(comp)), end(comp));
1414
for (int& val : a) {
1515
int start = 0, end = sz(comp);
1616
while (start + 1 < end) {

tests/library_checker_aizu_tests/graphs/offline_incremental_scc.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main() {
1717
rep(t, 0, m)
1818
assert((eds[t][0] == eds[t][1]) == (joins[t] == -1));
1919
vi order(m);
20-
iota(all(order), 0);
20+
ranges::iota(order, 0);
2121
ranges::sort(order, {}, [&](int i) { return joins[i]; });
2222
DSU dsu(n);
2323
int sum = 0;

tests/library_checker_aizu_tests/handmade_tests/permutation_tree_small.test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ int main() {
77
cin.tie(0)->sync_with_stdio(0);
88
for (int n = 1; n <= 8; n++) {
99
vi a(n);
10-
iota(all(a), 0);
10+
ranges::iota(a, 0);
1111
do {
1212
perm_tree pt = perm_tree_asserts(a);
13-
} while (next_permutation(all(a)));
13+
} while (ranges::next_permutation(a).found);
1414
}
1515
cout << "Hello World\n";
1616
return 0;

tests/library_checker_aizu_tests/handmade_tests/rmq_small_n.test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ int main() {
2020
cin.tie(0)->sync_with_stdio(0);
2121
for (int n = 1; n <= 8; n++) {
2222
vi perm(n);
23-
iota(all(perm), 0);
23+
ranges::iota(perm, 0);
2424
do {
2525
test_all_subarrays(perm);
26-
} while (next_permutation(all(perm)));
26+
} while (ranges::next_permutation(perm).found);
2727
}
2828
for (int n = 1; n <= 100; n++) {
2929
rep(times, 0, 40) {

tests/library_checker_aizu_tests/handmade_tests/seg_tree_find.test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int main() {
5151
else assert(cur_le == prv_ri);
5252
}
5353
ranges::sort(rngs);
54-
assert(unique(all(rngs)) == end(rngs));
54+
assert(begin(ranges::unique(rngs)) == end(rngs));
5555
reset();
5656
assert(
5757
pos == rv(rev.find_last(rv(r - 1), rv(l) + 1, f)));
@@ -67,7 +67,7 @@ int main() {
6767
else assert(prv_le == cur_ri);
6868
}
6969
ranges::sort(rngs);
70-
assert(unique(all(rngs)) == end(rngs));
70+
assert(begin(ranges::unique(rngs)) == end(rngs));
7171
}
7272
cout << "Hello World\n";
7373
return 0;

tests/library_checker_aizu_tests/mono_st_asserts.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tuple<int, vector<vi>, vi> min_cartesian_tree(const vi& a,
1111
return r[i] == n || a[r[i]] < a[i];
1212
};
1313
vi to_min(n);
14-
iota(all(to_min), 0);
14+
ranges::iota(to_min, 0);
1515
for (int i = n - 1; i >= 0; i--)
1616
if (!is_node(i)) to_min[i] = to_min[r[i]];
1717
vector<vi> adj(n);

tests/library_checker_aizu_tests/strings/sa_sort_pairs.test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int main() {
1010
for (int& x : arr) cin >> x;
1111
vi compress(arr);
1212
ranges::sort(compress);
13-
compress.erase(unique(all(compress)), end(compress));
13+
compress.erase(begin(ranges::unique(compress)), end(compress));
1414
for (int& x : arr) {
1515
int l = -1, r = int(sz(compress));
1616
while (r - l > 1) {
@@ -24,7 +24,7 @@ int main() {
2424
auto [sa, sa_inv, lcp] = get_sa(arr, int(sz(compress)));
2525
sa_query lq(arr, sa, sa_inv, lcp);
2626
vi idxs(n);
27-
iota(all(idxs), 0);
27+
ranges::iota(idxs, 0);
2828
ranges::sort(idxs, [&](int i, int j) -> bool {
2929
return lq.cmp_substrs(2 * i, 2 * (i + 1), 2 * j,
3030
2 * (j + 1)) < 0;

tests/library_checker_aizu_tests/strings/single_matching_bs.test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ int main() {
7070
vi matches_other(begin(lq_both.sa) + sa_le2,
7171
begin(lq_both.sa) + sa_ri2);
7272
matches_other.erase(
73-
remove_if(all(matches_other),
74-
[&](int val) { return val >= sz(s) + 1; }),
73+
begin(ranges::remove_if(matches_other,
74+
[&](int val) { return val >= sz(s) + 1; })),
7575
end(matches_other));
7676
ranges::sort(matches_other);
7777
assert(matches == matches_other);

0 commit comments

Comments
 (0)