]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add basic test for dns_random_uint32
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 13 Jun 2023 09:17:45 +0000 (11:17 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 13 Jun 2023 10:59:31 +0000 (12:59 +0200)
pdns/test-dns_random_hh.cc

index 2d3af18c7f8e65b50300fce33680d7ff29f4fa9e..e0211f720f25cb22f8fa1ad2838d63c18105cc38 100644 (file)
@@ -28,6 +28,25 @@ typedef accumulator_set<
 
 BOOST_AUTO_TEST_SUITE(test_dns_random_hh)
 
+BOOST_AUTO_TEST_CASE(test_dns_random_uint32_auto_average)
+{
+
+  ::arg().set("rng") = "auto";
+  ::arg().set("entropy-source") = "/dev/urandom";
+
+  dns_random_init("", true);
+
+  acc_t acc;
+
+  for (unsigned int n = 0; n < 100000; ++n) {
+    acc(dns_random_unint32() / static_cast<double>(pdns::dns_random_engine::max() + 1));
+  }
+  BOOST_CHECK_CLOSE(0.5, median(acc), 2.0); // within 2%
+  BOOST_CHECK_CLOSE(0.5, mean(acc), 2.0);
+
+  // please add covariance tests, chi-square, Kolmogorov-Smirnov
+}
+
 BOOST_AUTO_TEST_CASE(test_dns_random_auto_average)
 {