diff options
author | Jack Lloyd <[email protected]> | 2018-09-15 15:52:47 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-09-15 15:54:22 -0400 |
commit | 62b00c20b3eb6d0a5e5add2d099b9e3286baa4cf (patch) | |
tree | c490a2e26d06200929db2756b612cf716e0e5cb9 /src/tests/test_bigint.cpp | |
parent | d265425180d3e6eb1dc9c7c718329e21711369b3 (diff) |
Simplify BigInt::get_substring a bit
And forbid 0 length substrings, which did not work correctly anyway.
Diffstat (limited to 'src/tests/test_bigint.cpp')
-rw-r--r-- | src/tests/test_bigint.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp index ad0af03f4..33c617239 100644 --- a/src/tests/test_bigint.cpp +++ b/src/tests/test_bigint.cpp @@ -36,6 +36,7 @@ class BigInt_Unit_Tests final : public Test results.push_back(test_random_prime()); results.push_back(test_encode()); results.push_back(test_bigint_io()); + results.push_back(test_get_substring()); return results; } @@ -206,6 +207,34 @@ class BigInt_Unit_Tests final : public Test return result; } + Test::Result test_get_substring() + { + const size_t trials = 1000; + + Test::Result result("BigInt get_substring"); + + const Botan::BigInt r(Test::rng(), 250); + + for(size_t s = 1; s <= 32; ++s) + { + for(size_t trial = 0; trial != trials; ++trial) + { + const size_t offset = Test::rng().next_byte(); + + const uint32_t val = r.get_substring(offset, s); + + Botan::BigInt t = r >> offset; + t.mask_bits(s); + + const uint32_t cmp = t.to_u32bit(); + + result.test_eq("Same value", size_t(val), size_t(cmp)); + } + } + + return result; + } + Test::Result test_bigint_io() { Test::Result result("BigInt IO operators"); |