From 8387b027dcee25002842f83903b1f5190eaecd58 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 2 Jan 2017 20:04:02 +0100 Subject: Rename ITERATIONS -> ITERATIONS_PER_POSSIBLE_VALUE --- src/tests/test_bigint.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp index 1d442a8bb..802e22ff8 100644 --- a/src/tests/test_bigint.cpp +++ b/src/tests/test_bigint.cpp @@ -133,7 +133,7 @@ class BigInt_Unit_Tests : public Test result.start_timer(); - const size_t ITERATIONS = 500; + const size_t ITERATIONS_PER_POSSIBLE_VALUE = 500; std::vector min_ranges{ 0 }; std::vector max_ranges{ 10 }; @@ -154,7 +154,7 @@ class BigInt_Unit_Tests : public Test std::vector counts(range_max - range_min); - for(size_t i = 0; i != counts.size() * ITERATIONS; ++i) + for(size_t i = 0; i != counts.size() * ITERATIONS_PER_POSSIBLE_VALUE; ++i) { uint32_t r = BigInt::random_integer(Test::rng(), range_min, range_max).to_u32bit(); result.test_gte("random_integer", r, range_min); @@ -164,7 +164,7 @@ class BigInt_Unit_Tests : public Test for(size_t i = 0; i != counts.size(); ++i) { - double ratio = static_cast(counts[i]) / ITERATIONS; + double ratio = static_cast(counts[i]) / ITERATIONS_PER_POSSIBLE_VALUE; double dev = std::min(ratio, std::fabs(1.0 - ratio)); if(dev < .15) -- cgit v1.2.3 From cc760f3a67cc136a30f707e19f1e9d2f01297959 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 2 Jan 2017 20:54:54 +0100 Subject: Fix math in test_random_integer() Removes complicated extra variable "dev", which was calculated incorrectly: if ratio = 0.0 then dev = 0.0, resulting in a test success. --- src/tests/test_bigint.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp index 802e22ff8..f07c82330 100644 --- a/src/tests/test_bigint.cpp +++ b/src/tests/test_bigint.cpp @@ -165,17 +165,15 @@ class BigInt_Unit_Tests : public Test for(size_t i = 0; i != counts.size(); ++i) { double ratio = static_cast(counts[i]) / ITERATIONS_PER_POSSIBLE_VALUE; - double dev = std::min(ratio, std::fabs(1.0 - ratio)); - if(dev < .15) + if(ratio >= 0.85 && ratio <= 1.15) // +/-15 % { result.test_success("distribution within expected range"); } else { - result.test_failure("distribution " + std::to_string(dev) + - " outside expected range with count" + - std::to_string(counts[i])); + result.test_failure("distribution ratio outside expected range (+/-15 %): " + + std::to_string(ratio)); } } } -- cgit v1.2.3 From 4b54b03df9103909e45873d93dd081d202e00c43 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 2 Jan 2017 20:56:21 +0100 Subject: Simplify loop to foreach in test_random_integer() --- src/tests/test_bigint.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp index f07c82330..e23f50055 100644 --- a/src/tests/test_bigint.cpp +++ b/src/tests/test_bigint.cpp @@ -162,9 +162,9 @@ class BigInt_Unit_Tests : public Test counts[r - range_min] += 1; } - for(size_t i = 0; i != counts.size(); ++i) + for(const auto count : counts) { - double ratio = static_cast(counts[i]) / ITERATIONS_PER_POSSIBLE_VALUE; + double ratio = static_cast(count) / ITERATIONS_PER_POSSIBLE_VALUE; if(ratio >= 0.85 && ratio <= 1.15) // +/-15 % { -- cgit v1.2.3 From 18de2e7df2479aad8c6c94933197ccb295f0f61b Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 2 Jan 2017 21:00:43 +0100 Subject: Increase value of ITERATIONS_PER_POSSIBLE_VALUE to 750 to avoid test failures --- src/tests/test_bigint.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp index e23f50055..901cd8039 100644 --- a/src/tests/test_bigint.cpp +++ b/src/tests/test_bigint.cpp @@ -133,7 +133,8 @@ class BigInt_Unit_Tests : public Test result.start_timer(); - const size_t ITERATIONS_PER_POSSIBLE_VALUE = 500; + // A value of 500 caused a non-negligible amount of test failures + const size_t ITERATIONS_PER_POSSIBLE_VALUE = 750; std::vector min_ranges{ 0 }; std::vector max_ranges{ 10 }; -- cgit v1.2.3