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/string/deBruijn.cpp | |
| parent | ad3856a6b766087df0036de0b556f4700a6498c9 (diff) | |
| parent | 8d11c6c8213f46f0fa19826917c255edd5d43cb1 (diff) | |
mzuenni tests
Diffstat (limited to 'test/string/deBruijn.cpp')
| -rw-r--r-- | test/string/deBruijn.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/string/deBruijn.cpp b/test/string/deBruijn.cpp new file mode 100644 index 0000000..6b3fea4 --- /dev/null +++ b/test/string/deBruijn.cpp @@ -0,0 +1,43 @@ +#include "../util.h" +#include <string/lyndon.cpp> +#include <string/deBruijn.cpp> + +bool isDeBruijn(string s, int n, int k) { + ll expected = 1; + for (ll i = 0; i < n; i++) expected *= k; + if (expected != sz(s)) return false; + s += s; + set<string_view> seen; + for (ll i = 0; 2*i < sz(s); i++) { + seen.insert(string_view(s).substr(i, n)); + } + return sz(seen) == expected; +} + +void stress_test() { + ll queries = 0; + for (ll i = 0; i < 1000; i++) { + int n = Random::integer<int>(1, 9); + auto [l, r] = Random::pair<char>('b', 'f'); + auto got = deBruijn(n, l, r); + if (!isDeBruijn(got, n, r - l + 1)) cerr << "error" << FAIL; + queries += sz(got); + } + cerr << "tested random queries: " << queries << endl; +} + +constexpr int N = 26; +void performance_test() { + timer t; + t.start(); + auto res = deBruijn(N, '0', '1'); + t.stop(); + hash_t hash = sz(res); + 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(); +} |
