diff options
| author | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-11-16 01:24:14 +0100 |
|---|---|---|
| committer | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-11-16 01:24:14 +0100 |
| commit | 98567ec798aa8ca2cfbcb85c774dd470f30e30d4 (patch) | |
| tree | 5113d5cc24d1ad5f93810b6442ce584a36950dc8 /test/other/sos.cpp | |
| parent | ad3856a6b766087df0036de0b556f4700a6498c9 (diff) | |
| parent | 8d11c6c8213f46f0fa19826917c255edd5d43cb1 (diff) | |
mzuenni tests
Diffstat (limited to 'test/other/sos.cpp')
| -rw-r--r-- | test/other/sos.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/other/sos.cpp b/test/other/sos.cpp new file mode 100644 index 0000000..f3a6109 --- /dev/null +++ b/test/other/sos.cpp @@ -0,0 +1,50 @@ +#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(); +} + |
