MCPcopy Create free account
hub / github.com/apache/arrow / VerifyDist

Method VerifyDist

cpp/src/arrow/testing/random_test.cc:698–723  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

696class UniformRealTest : public ::testing::Test {
697 protected:
698 void VerifyDist(int seed, T a, T b) {
699 pcg32_fast rng(seed);
700 ::arrow::random::uniform_real_distribution<T> dist(a, b);
701
702 const int kCount = 5000;
703 T min = std::numeric_limits<T>::max();
704 T max = std::numeric_limits<T>::lowest();
705 double sum = 0;
706 double square_sum = 0;
707 for (int i = 0; i < kCount; ++i) {
708 const T v = dist(rng);
709 min = std::min(min, v);
710 max = std::max(max, v);
711 sum += v;
712 square_sum += static_cast<double>(v) * v;
713 }
714
715 ASSERT_GE(min, a);
716 ASSERT_LT(max, b);
717
718 // verify E(X), E(X^2) is near theory
719 const double E_X = (a + b) / 2.0;
720 const double E_X2 = 1.0 / 12 * (a - b) * (a - b) + E_X * E_X;
721 ASSERT_NEAR(sum / kCount, E_X, std::abs(E_X) * 0.02);
722 ASSERT_NEAR(square_sum / kCount, E_X2, E_X2 * 0.02);
723 }
724};
725
726using RealCTypes = ::testing::Types<float, double>;

Callers 1

TYPED_TESTFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected