summaryrefslogtreecommitdiff
path: root/test/other
diff options
context:
space:
mode:
Diffstat (limited to 'test/other')
-rw-r--r--test/other/bitOps.cpp6
-rw-r--r--test/other/josephus2.cpp6
-rw-r--r--test/other/josephusK.cpp4
-rw-r--r--test/other/pbs.cpp6
-rw-r--r--test/other/sos.cpp50
5 files changed, 10 insertions, 62 deletions
diff --git a/test/other/bitOps.cpp b/test/other/bitOps.cpp
index 44f6297..2250521 100644
--- a/test/other/bitOps.cpp
+++ b/test/other/bitOps.cpp
@@ -31,9 +31,7 @@ ll naive(ll x) {
bits.push_back(x & 1);
x >>= 1;
}
- reverse(all(bits));
- next_permutation(all(bits));
- reverse(all(bits));
+ ranges::next_permutation(bits | views::reverse);
x = 0;
for (ll i = 0, j = 1; i < 64; i++, j <<= 1) {
if (bits[i] != 0) x |= j;
@@ -56,4 +54,4 @@ void test_nextPerm() {
int main() {
test_subsets();
test_nextPerm();
-} \ No newline at end of file
+}
diff --git a/test/other/josephus2.cpp b/test/other/josephus2.cpp
index 85a9d28..f2c0440 100644
--- a/test/other/josephus2.cpp
+++ b/test/other/josephus2.cpp
@@ -4,8 +4,8 @@
template<ll O>
ll naive(ll n, ll k) {
vector<ll> state(n);
- iota(all(state), O);
- for (ll i = k-1; state.size() > 1; i = (i + k - 1) % sz(state)) {
+ iota(begin(state), end(state), O);
+ for (ll i = k-1; state.size() > 1; i = (i + k - 1) % ssize(state)) {
state.erase(state.begin() + i);
}
return state[0];
@@ -15,7 +15,7 @@ void stress_test() {
ll tests = 0;
for (ll i = 1; i < 2'000; i++) {
auto got = rotateLeft(i);
- auto expected = naive<1>(i, 2);
+ auto expected = naive<0>(i, 2);
if (got != expected) cerr << "error: " << i << FAIL;
tests++;
}
diff --git a/test/other/josephusK.cpp b/test/other/josephusK.cpp
index e837640..1a5aa9d 100644
--- a/test/other/josephusK.cpp
+++ b/test/other/josephusK.cpp
@@ -5,8 +5,8 @@
template<ll O>
ll naive(ll n, ll k) {
vector<ll> state(n);
- iota(all(state), O);
- for (ll i = k-1; state.size() > 1; i = (i + k - 1) % sz(state)) {
+ iota(begin(state), end(state), O);
+ for (ll i = k-1; state.size() > 1; i = (i + k - 1) % ssize(state)) {
state.erase(state.begin() + i);
}
return state[0];
diff --git a/test/other/pbs.cpp b/test/other/pbs.cpp
index ba3b9d0..e1dfea0 100644
--- a/test/other/pbs.cpp
+++ b/test/other/pbs.cpp
@@ -49,7 +49,7 @@ void stress_test() {
for (int i=1; i<n; i++) {
edges.emplace_back(Random::integer(0, i), i);
}
- shuffle(all(edges), Random::rng);
+ ranges::shuffle(edges, Random::rng);
queries.clear();
for (int i=0; i<Q; i++) {
auto x = Random::distinct(2, n);
@@ -80,7 +80,7 @@ void performance_test() {
for (int i=1; i<n; i++) {
edges.emplace_back(Random::integer(0, i), i);
}
- shuffle(all(edges), Random::rng);
+ ranges::shuffle(edges, Random::rng);
queries.clear();
for (int i=0; i<Q; i++) {
auto x = Random::distinct(2, n);
@@ -91,7 +91,7 @@ void performance_test() {
t.start();
vector<int> ans = pbs(Q, MAX_OPERATIONS);
t.stop();
- ll hash = accumulate(all(ans), 0LL);
+ ll hash = accumulate(begin(ans), end(ans), 0LL);
if (t.time > 700) cerr << "too slow: " << t.time << FAIL;
cerr << "tested performance: " << t.time << "ms (hash: " << hash << ")" << endl;
diff --git a/test/other/sos.cpp b/test/other/sos.cpp
deleted file mode 100644
index f3a6109..0000000
--- a/test/other/sos.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-#include "../util.h"
-
-vector<ll> sos(const vector<ll>& in) {
- #include <other/sos.cpp>
- return res;
-}
-
-vector<ll> naive(const vector<ll>& in) {
- vector<ll> res(sz(in));
- for (ll i = 0; i < sz(in); i++) {
- for (ll j = 0; j <= i; j++) {
- if ((i | j) == i) {
- res[i] += in[j];
- }
- }
- }
- return res;
-}
-
-void stress_test() {
- ll tests = 0;
- for (ll i = 0; i < 1000; i++) {
- int n = Random::integer<int>(1, 100);
- auto in = Random::integers<ll>(n, -1000, 1000);
- auto got = sos(in);
- auto expected = naive(in);
- if (got != expected) cerr << "error: " << i << FAIL;
- tests += n;
- }
- cerr << "tested random queries: " << tests << endl;
-}
-
-constexpr int N = 10'000'000;
-void performance_test() {
- timer t;
- auto in = Random::integers<ll>(N, -1000, 1000);
- t.start();
- auto res = sos(in);
- t.stop();
- hash_t hash = 0;
- for (ll x : res) hash += x;
- if (t.time > 500) cerr << "too slow: " << t.time << FAIL;
- cerr << "tested performance: " << t.time << "ms (hash: " << hash << ")" << endl;
-}
-
-int main() {
- stress_test();
- performance_test();
-}
-