aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-06-05 13:48:30 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-06-05 13:48:30 +0000
commit48b9d9508ad9944d63c7369d153ad4d842721a1b (patch)
tree6224a9c296d85f8a1f9dd52a4e0f90f28e793aaa
parent9d562f59ada1bdcfb86dea66f443cfac59c8d71c (diff)
downloadpaludis-48b9d9508ad9944d63c7369d153ad4d842721a1b.tar.gz
paludis-48b9d9508ad9944d63c7369d153ad4d842721a1b.tar.xz
Make chi squared test less prone to occasional random failures
-rw-r--r--paludis/util/random_TEST.cc26
1 files changed, 17 insertions, 9 deletions
diff --git a/paludis/util/random_TEST.cc b/paludis/util/random_TEST.cc
index 6dc2f4a..ef4489d 100644
--- a/paludis/util/random_TEST.cc
+++ b/paludis/util/random_TEST.cc
@@ -96,17 +96,25 @@ namespace test_cases
void run()
{
- std::vector<int> v;
- v.reserve(10000);
- std::generate_n(std::back_inserter(v), 10000, RandomUpTo(Random(), 10));
+ int failures(0);
- double a(0);
- for (int i(0) ; i <= 9 ; ++i)
- a += (square(std::count(v.begin(), v.end(), i) - (10000 / 10)) / (10000 / 10));
+ for (int attempts(0) ; attempts < 3 ; ++ attempts)
+ {
+ std::vector<int> v;
+ v.reserve(10000);
+ std::generate_n(std::back_inserter(v), 10000, RandomUpTo(Random(), 10));
+
+ double a(0);
+ for (int i(0) ; i <= 9 ; ++i)
+ a += (square(std::count(v.begin(), v.end(), i) - (10000 / 10)) / (10000 / 10));
+
+ TestMessageSuffix suffix("a=" + stringify(a), true);
+ TEST_CHECK(true);
+ if ((a < 2.088) || (a > 21.67))
+ ++failures;
+ }
- TestMessageSuffix suffix("a=" + stringify(a), true);
- TEST_CHECK(a >= 2.088);
- TEST_CHECK(a <= 21.67);
+ TEST_CHECK(failures <= 1);
}
} test_random_chi_square;
}