more tests, added missing libm to linker

This commit is contained in:
Hans Dembinski 2016-04-09 19:02:39 -04:00
parent ae026af085
commit fbea37a0af
4 changed files with 126 additions and 37 deletions

View File

@ -12,7 +12,7 @@ find_package(Numpy) # optional
include_directories(include ${Boost_INCLUDE_DIRS}) include_directories(include ${Boost_INCLUDE_DIRS})
add_definitions(-DBOOST_TEST_DYN_LINK) # for unit_test_framework 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) if(Boost_PYTHON_FOUND AND PYTHONLIBS_FOUND)
set(USE_PYTHON True) set(USE_PYTHON True)
@ -75,6 +75,11 @@ add_executable(zero_suppression_test
target_link_libraries(zero_suppression_test histogram ${LIBRARIES}) target_link_libraries(zero_suppression_test histogram ${LIBRARIES})
add_test(zero_suppression_test zero_suppression_test) 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) if(Boost_PYTHON_FOUND)
add_custom_target(python_suite_test ALL add_custom_target(python_suite_test ALL
cp ${CMAKE_SOURCE_DIR}/test/python_suite_test.py .) cp ${CMAKE_SOURCE_DIR}/test/python_suite_test.py .)

View File

@ -124,13 +124,13 @@ void compare_6d(unsigned n)
regular_axis(10, 0, 1), regular_axis(10, 0, 1),
regular_axis(10, 0, 1), 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(); t = clock();
for (unsigned i = 0; i < n; ++i) { for (unsigned i = 0; i < n; ++i) {
for (unsigned k = 0; k < 6; ++k) for (unsigned k = 0; k < 6; ++k)
y[k] = r[6 * i + k]; y[k] = r[6 * i + k];
h.fill(y); h.fill(6, y);
} }
t = clock() - t; t = clock() - t;
best_boost = std::min(best_boost, double(t) / CLOCKS_PER_SEC); best_boost = std::min(best_boost, double(t) / CLOCKS_PER_SEC);

View File

@ -7,6 +7,8 @@
#include <boost/preprocessor.hpp> #include <boost/preprocessor.hpp>
#include <boost/serialization/access.hpp> #include <boost/serialization/access.hpp>
#include <boost/serialization/base_object.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/shared_ptr.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -28,15 +30,16 @@ public:
// generates constructors taking 1 to AXIS_LIMIT arguments // generates constructors taking 1 to AXIS_LIMIT arguments
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_CTOR, nil) BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_CTOR, nil)
template <typename Container> // template <typename C>
inline // inline
void fill(const Container& v) // void
{ // fill(const C& v)
BOOST_ASSERT(v.size() == dim()); // {
const size_type k = pos(v); // BOOST_ASSERT(v.size() == dim());
if (k != uintmax_t(-1)) // const size_type k = pos(v);
data_.increase(k); // if (k != uintmax_t(-1))
} // data_.increase(k);
// }
// C-style call // C-style call
inline 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 // generates fill functions taking 1 to AXIS_LIMT arguments
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_FILL, nil) BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_FILL, nil)
template <typename Container> // template <typename Container>
inline // inline
void wfill(const Container& v, double w) // void wfill(const Container& v, double w)
{ // {
BOOST_ASSERT(v.size() == dim()); // BOOST_ASSERT(v.size() == dim());
const size_type k = pos(v); // const size_type k = pos(v);
if (k != uintmax_t(-1)) // if (k != uintmax_t(-1))
data_.increase(k, w); // data_.increase(k, w);
} // }
// C-style call // C-style call
inline 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 // generates wfill functions taking 1 to AXIS_LIMT arguments
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_WFILL, nil) BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_WFILL, nil)
template <typename Container> // template <typename Container>
inline // inline
double value(const Container& idx) // double value(const Container& idx)
const // const
{ // {
BOOST_ASSERT(idx.size() == dim()); // BOOST_ASSERT(idx.size() == dim());
return data_.value(linearize(idx)); // return data_.value(linearize(idx));
} // }
// C-style call // C-style call
inline 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 // generates value functions taking 1 to AXIS_LIMT arguments
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_VALUE, nil) BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_VALUE, nil)
template <typename Container> // template <typename Container>
inline // inline
double variance(const Container& idx) // double variance(const Container& idx)
const // const
{ // {
BOOST_ASSERT(idx.size() == dim()); // BOOST_ASSERT(idx.size() == dim());
return data_.variance(linearize(idx)); // return data_.variance(linearize(idx));
} // }
// C-style call // C-style call
inline inline

81
test/histogram_test.cpp Normal file
View 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);
}