Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
595 changes: 40 additions & 555 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ run test_const_mod.cpp /boost/test//boost_unit_test_framework ;
run test_generate_canonical.cpp /boost/test//boost_unit_test_framework ;
run test_random_number_generator.cpp /boost/test//boost_unit_test_framework ;
run ../example/random_demo.cpp ;
run test_random_device.cpp /boost/random//boost_random /boost/test//included : : : <link>static : test_random_device ;
run test_random_device.cpp /boost/random//boost_random /boost/test//included : : : <link>shared : test_random_device_dll ;
run test_random_device.cpp /boost/test//boost_unit_test_framework ;

run test_minstd_rand0.cpp /boost/test//boost_unit_test_framework ;
run test_minstd_rand.cpp /boost/test//boost_unit_test_framework ;
Expand Down
52 changes: 52 additions & 0 deletions test/cmake_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2021-2026 Alexander Grund
# Distributed under 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

cmake_minimum_required(VERSION 3.5...3.31)

project(cmake_subdir_test LANGUAGES CXX)

# Those 2 should work the same
# while using find_package for the installed Boost avoids the need to manually specify dependencies
if(BOOST_CI_INSTALL_TEST)
# Regular usage:
# Provides target Boost::random
find_package(Boost COMPONENTS random REQUIRED)
else()
add_subdirectory(../.. boostorg/random)

set(deps
# Primary dependencies
assert
config
core
dynamic_bitset
integer
io
system
throw_exception
type_traits
utility
# Secondary dependencies
compat
container_hash
describe
mp11
predef
preprocessor
variant2
winapi
)

foreach(dep IN LISTS deps)
add_subdirectory(../../../${dep} boostorg/${dep})
endforeach()
endif()

add_executable(main main.cpp)
target_link_libraries(main Boost::random)

enable_testing()
add_test(NAME main COMMAND main)

add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
9 changes: 9 additions & 0 deletions test/cmake_test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <boost/random.hpp>

int main()
{
boost::mt19937 rng;
boost::uniform_int<> six(1,6);
int x = six(rng);
return (x >= 1 && x <= 6) ? 0 : 1;
}
72 changes: 36 additions & 36 deletions test/multiprecision_float_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,43 @@ typedef boost::mpl::list <
boost::random::weibull_distribution<big_float>
> distributions;

template<class T>
void check_result(const T& result, const T& min_val, const T& max_val)
{

BOOST_CHECK(boost::math::isfinite(result));
BOOST_TEST(result >= min_val);
BOOST_TEST(result <= max_val);
}

template<class T>
void check_result(const std::vector<T>& result, const std::vector<T>& min_val, const std::vector<T>& max_val)
{
for(size_t i = 0; i < result.size(); i++)
{
BOOST_CHECK(boost::math::isfinite(result[i]));
}
BOOST_TEST(result >= min_val);
BOOST_TEST(result <= max_val);
}

template<class TDist, class TGen>
void do_check_distribution(TDist& d, TGen& gen)
{
typedef typename TDist::result_type result_type;
const result_type min_val = (d.min)();
const result_type max_val = (d.max)();
for(unsigned i = 0; i < 200; ++i)
{
result_type r = d(gen);
check_result(r, min_val, max_val);
}
}

BOOST_AUTO_TEST_CASE_TEMPLATE(distributions_test, dist_type, distributions)
{
typedef typename dist_type::result_type result_type;
dist_type d;
result_type a = (d.min)();
result_type b = (d.max)();
typename dist_type::param_type p = d.param();
boost::ignore_unused(p);
d.reset();
Expand All @@ -106,46 +136,16 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(distributions_test, dist_type, distributions)
BOOST_CHECK(d == d2);

boost::random::mt19937 int_gen;
do_check_distribution(d, int_gen);

for(unsigned i = 0; i < 200; ++i)
{
result_type r = d(int_gen);
BOOST_CHECK((boost::math::isfinite)(r));
BOOST_CHECK(r >= a);
BOOST_CHECK(r <= b);
}

#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
large_int_generator big_int_gen;

for(unsigned i = 0; i < 200; ++i)
{
result_type r = d(big_int_gen);
BOOST_CHECK((boost::math::isfinite)(r));
BOOST_CHECK(r >= a);
BOOST_CHECK(r <= b);
}
do_check_distribution(d, big_int_gen);

boost::random::discard_block_engine< ranlux_big_base_01, 389, 24 > big_float_gen;

for(unsigned i = 0; i < 200; ++i)
{
result_type r = d(big_float_gen);
BOOST_CHECK((boost::math::isfinite)(r));
BOOST_CHECK(r >= a);
BOOST_CHECK(r <= b);
}
#endif
do_check_distribution(d, big_float_gen);

boost::random::ranlux64_4_01 float_gen;

for(unsigned i = 0; i < 200; ++i)
{
result_type r = d(float_gen);
BOOST_CHECK((boost::math::isfinite)(r));
BOOST_CHECK(r >= a);
BOOST_CHECK(r <= b);
}
do_check_distribution(d, float_gen);
}


Expand Down
2 changes: 2 additions & 0 deletions test/multiprecision_int_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(discrete_distributions, distribution_type, other_d
for(unsigned i = 0; i < 200; ++i)
{
result_type r = d(gen);
boost::ignore_unused(r);
}

std::stringstream ss;
Expand All @@ -223,6 +224,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(discrete_distributions, distribution_type, other_d
for(unsigned i = 0; i < 200; ++i)
{
result_type r = d(big_random);
boost::ignore_unused(r);
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/statistic_tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <cmath>

#include <boost/config.hpp>
#include <boost/bind.hpp>
#include <boost/bind/bind.hpp>
#include <boost/random/uniform_01.hpp>
#include <boost/random/variate_generator.hpp>

Expand Down Expand Up @@ -491,6 +491,7 @@ inline double cdf(const kolmogorov_smirnov_probability& dist, double val)

inline double quantile(const kolmogorov_smirnov_probability& dist, double val)
{
using namespace boost::placeholders;
return invert_monotone_inc(boost::bind(&cdf, dist, _1), val, 0.0, 1000.0);
}

Expand Down
12 changes: 8 additions & 4 deletions test/test_random_device.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* boost random_test.cpp various tests
*
* Copyright (c) 2010 Steven Watanabe
* Copyright (c) 2016 Alexander Grund
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENCE_1_0.txt)
Expand All @@ -10,15 +11,19 @@

#include <boost/random/random_device.hpp>

#include <boost/test/test_tools.hpp>
#include <boost/test/included/test_exec_monitor.hpp>
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>

#ifndef BOOST_NO_CXX11_CONSTEXPR
constexpr boost::random_device::result_type const_min = (boost::random_device::min)();
constexpr boost::random_device::result_type const_max = (boost::random_device::max)();
#endif

int test_main(int, char**) {
BOOST_AUTO_TEST_CASE(test_random_device)
{
boost::ignore_unused(const_min);
boost::ignore_unused(const_max);

boost::random_device rng;
double entropy = rng.entropy();
BOOST_CHECK_GE(entropy, 0);
Expand All @@ -30,5 +35,4 @@ int test_main(int, char**) {

boost::uint32_t a[10];
rng.generate(a, a + 10);
return 0;
}
Loading