mirror of
https://github.com/boostorg/histogram.git
synced 2025-05-09 23:04:07 +00:00
more tests, added missing libm to linker
This commit is contained in:
parent
ae026af085
commit
fbea37a0af
@ -12,7 +12,7 @@ find_package(Numpy) # optional
|
||||
|
||||
include_directories(include ${Boost_INCLUDE_DIRS})
|
||||
add_definitions(-DBOOST_TEST_DYN_LINK) # for unit_test_framework
|
||||
set(LIBRARIES stdc++ ${Boost_LIBRARIES})
|
||||
set(LIBRARIES stdc++ m ${Boost_LIBRARIES})
|
||||
|
||||
if(Boost_PYTHON_FOUND AND PYTHONLIBS_FOUND)
|
||||
set(USE_PYTHON True)
|
||||
@ -75,6 +75,11 @@ add_executable(zero_suppression_test
|
||||
target_link_libraries(zero_suppression_test histogram ${LIBRARIES})
|
||||
add_test(zero_suppression_test zero_suppression_test)
|
||||
|
||||
add_executable(histogram_test
|
||||
test/histogram_test.cpp)
|
||||
target_link_libraries(histogram_test histogram ${LIBRARIES})
|
||||
add_test(histogram_test histogram_test)
|
||||
|
||||
if(Boost_PYTHON_FOUND)
|
||||
add_custom_target(python_suite_test ALL
|
||||
cp ${CMAKE_SOURCE_DIR}/test/python_suite_test.py .)
|
||||
|
@ -124,13 +124,13 @@ void compare_6d(unsigned n)
|
||||
regular_axis(10, 0, 1),
|
||||
regular_axis(10, 0, 1),
|
||||
regular_axis(10, 0, 1));
|
||||
boost::array<double, 6> y;
|
||||
double y[6];
|
||||
|
||||
t = clock();
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
for (unsigned k = 0; k < 6; ++k)
|
||||
y[k] = r[6 * i + k];
|
||||
h.fill(y);
|
||||
h.fill(6, y);
|
||||
}
|
||||
t = clock() - t;
|
||||
best_boost = std::min(best_boost, double(t) / CLOCKS_PER_SEC);
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <boost/preprocessor.hpp>
|
||||
#include <boost/serialization/access.hpp>
|
||||
#include <boost/serialization/base_object.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
@ -28,15 +30,16 @@ public:
|
||||
// generates constructors taking 1 to AXIS_LIMIT arguments
|
||||
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_CTOR, nil)
|
||||
|
||||
template <typename Container>
|
||||
inline
|
||||
void fill(const Container& v)
|
||||
{
|
||||
BOOST_ASSERT(v.size() == dim());
|
||||
const size_type k = pos(v);
|
||||
if (k != uintmax_t(-1))
|
||||
data_.increase(k);
|
||||
}
|
||||
// template <typename C>
|
||||
// inline
|
||||
// void
|
||||
// fill(const C& v)
|
||||
// {
|
||||
// BOOST_ASSERT(v.size() == dim());
|
||||
// const size_type k = pos(v);
|
||||
// if (k != uintmax_t(-1))
|
||||
// data_.increase(k);
|
||||
// }
|
||||
|
||||
// C-style call
|
||||
inline
|
||||
@ -59,15 +62,15 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_CTOR, nil
|
||||
// generates fill functions taking 1 to AXIS_LIMT arguments
|
||||
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_FILL, nil)
|
||||
|
||||
template <typename Container>
|
||||
inline
|
||||
void wfill(const Container& v, double w)
|
||||
{
|
||||
BOOST_ASSERT(v.size() == dim());
|
||||
const size_type k = pos(v);
|
||||
if (k != uintmax_t(-1))
|
||||
data_.increase(k, w);
|
||||
}
|
||||
// template <typename Container>
|
||||
// inline
|
||||
// void wfill(const Container& v, double w)
|
||||
// {
|
||||
// BOOST_ASSERT(v.size() == dim());
|
||||
// const size_type k = pos(v);
|
||||
// if (k != uintmax_t(-1))
|
||||
// data_.increase(k, w);
|
||||
// }
|
||||
|
||||
// C-style call
|
||||
inline
|
||||
@ -90,14 +93,14 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_FILL, nil
|
||||
// generates wfill functions taking 1 to AXIS_LIMT arguments
|
||||
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_WFILL, nil)
|
||||
|
||||
template <typename Container>
|
||||
inline
|
||||
double value(const Container& idx)
|
||||
const
|
||||
{
|
||||
BOOST_ASSERT(idx.size() == dim());
|
||||
return data_.value(linearize(idx));
|
||||
}
|
||||
// template <typename Container>
|
||||
// inline
|
||||
// double value(const Container& idx)
|
||||
// const
|
||||
// {
|
||||
// BOOST_ASSERT(idx.size() == dim());
|
||||
// return data_.value(linearize(idx));
|
||||
// }
|
||||
|
||||
// C-style call
|
||||
inline
|
||||
@ -120,14 +123,14 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_WFILL, ni
|
||||
// generates value functions taking 1 to AXIS_LIMT arguments
|
||||
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_VALUE, nil)
|
||||
|
||||
template <typename Container>
|
||||
inline
|
||||
double variance(const Container& idx)
|
||||
const
|
||||
{
|
||||
BOOST_ASSERT(idx.size() == dim());
|
||||
return data_.variance(linearize(idx));
|
||||
}
|
||||
// template <typename Container>
|
||||
// inline
|
||||
// double variance(const Container& idx)
|
||||
// const
|
||||
// {
|
||||
// BOOST_ASSERT(idx.size() == dim());
|
||||
// return data_.variance(linearize(idx));
|
||||
// }
|
||||
|
||||
// C-style call
|
||||
inline
|
||||
|
81
test/histogram_test.cpp
Normal file
81
test/histogram_test.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include <boost/histogram/histogram.hpp>
|
||||
#define BOOST_TEST_MODULE histogram_test
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/assign/std/vector.hpp>
|
||||
using namespace boost::assign;
|
||||
using namespace boost::histogram;
|
||||
namespace tt = boost::test_tools;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(init_0)
|
||||
{
|
||||
histogram();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(init_1)
|
||||
{
|
||||
histogram(regular_axis(3, -1, 1));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(init_2)
|
||||
{
|
||||
histogram(regular_axis(3, -1, 1),
|
||||
integer_axis(-1, 1));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(init_3)
|
||||
{
|
||||
histogram(regular_axis(3, -1, 1),
|
||||
integer_axis(-1, 1),
|
||||
polar_axis(3));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(init_4)
|
||||
{
|
||||
std::vector<double> x;
|
||||
x += -1, 0, 1;
|
||||
histogram(regular_axis(3, -1, 1),
|
||||
integer_axis(-1, 1),
|
||||
polar_axis(3),
|
||||
variable_axis(x));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(init_5)
|
||||
{
|
||||
std::vector<double> x;
|
||||
x += -1, 0, 1;
|
||||
histogram(regular_axis(3, -1, 1),
|
||||
integer_axis(-1, 1),
|
||||
polar_axis(3),
|
||||
variable_axis(x),
|
||||
category_axis("A;B;C"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(init_15)
|
||||
{
|
||||
std::vector<double> x;
|
||||
x += -1, 0, 1, 2, 3;
|
||||
histogram(regular_axis(1, -1, 1),
|
||||
regular_axis(1, -1, 1),
|
||||
regular_axis(1, -1, 1),
|
||||
regular_axis(1, -1, 1),
|
||||
regular_axis(1, -1, 1),
|
||||
|
||||
regular_axis(1, -1, 1),
|
||||
regular_axis(1, -1, 1),
|
||||
regular_axis(1, -1, 1),
|
||||
regular_axis(1, -1, 1),
|
||||
regular_axis(1, -1, 1),
|
||||
|
||||
regular_axis(1, -1, 1),
|
||||
regular_axis(1, -1, 1),
|
||||
regular_axis(1, -1, 1),
|
||||
regular_axis(1, -1, 1),
|
||||
regular_axis(1, -1, 1));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(fill_1)
|
||||
{
|
||||
histogram h(regular_axis(3, -1, 1));
|
||||
h.fill(1);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user