// (C) Copyright Matt Borland 2021. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // Module build check for boost::math::statistics::one_sample_z_test and // two_sample_z_test. It exercises the exported z-test entry points when the // test is built against the boost.math module. The double/float expected // values mirror the corresponding assertions in test_z_test.cpp. #ifndef BOOST_MATH_BUILD_MODULE #include #else import boost.math; #endif #ifndef BOOST_MATH_BUILD_MODULE #include #include #include #include #endif #include "math_unit_test.hpp" // Summary-statistic overload: statistic = (sample_mean - assumed_mean) / (sample_variance / sqrt(n)). template void test_one_sample_z() { // Equal means give a zero statistic; the resulting p-value underflows to zero. std::pair temp {boost::math::statistics::one_sample_z_test(static_cast(10), static_cast(2), static_cast(100), static_cast(10))}; Real computed_statistic {std::get<0>(temp)}; Real computed_pvalue {std::get<1>(temp)}; CHECK_ULP_CLOSE(static_cast(0), computed_statistic, 5); CHECK_MOLLIFIED_CLOSE(static_cast(0), computed_pvalue, 5 * std::numeric_limits::epsilon()); // (10 - 5) / (2 / sqrt(100)) = 25. temp = boost::math::statistics::one_sample_z_test(static_cast(10), static_cast(2), static_cast(100), static_cast(5)); Real computed_statistic_2 {std::get<0>(temp)}; CHECK_ULP_CLOSE(static_cast(25), computed_statistic_2, 5); // (1/2 - 1/3) / (10 / sqrt(100)) = 1/6. temp = boost::math::statistics::one_sample_z_test(static_cast(1) / 2, static_cast(10), static_cast(100), static_cast(1) / 3); Real computed_statistic_3 {std::get<0>(temp)}; CHECK_ULP_CLOSE(static_cast(1) / 6, computed_statistic_3, 5); } // Container overload: two unit-shifted samples of equal variance give a statistic of exactly 1. template void test_two_sample_z() { std::vector set_1 {1, 2, 3, 4, 5}; std::vector set_2 {2, 3, 4, 5, 6}; std::pair temp {boost::math::statistics::two_sample_z_test(set_2, set_1)}; Real computed_statistic {std::get<0>(temp)}; Real computed_pvalue {std::get<1>(temp)}; CHECK_ULP_CLOSE(static_cast(1), computed_statistic, 5); CHECK_MOLLIFIED_CLOSE(static_cast(0), computed_pvalue, std::sqrt(std::numeric_limits::epsilon())); } int main() { test_one_sample_z(); test_two_sample_z(); test_one_sample_z(); test_two_sample_z(); return boost::math::test::report_errors(); }