void test_one_lp(std::string const& caseid, std::string const& wkt1, std::string const& wkt2, std::size_t expected_count, int expected_point_count, double expected_length) { G1 g1; bg::read_wkt(wkt1, g1); G2 g2; bg::read_wkt(wkt2, g2); bg::correct(g1); std::vector<OutputType> pieces; bg::difference(g1, g2, pieces); typename bg::default_length_result<G1>::type length = 0; std::size_t n = 0; std::size_t piece_count = 0; for (typename std::vector<OutputType>::iterator it = pieces.begin(); it != pieces.end(); ++it) { if (expected_point_count >= 0) { n += bg::num_points(*it); } piece_count++; length += bg::length(*it); } BOOST_CHECK_MESSAGE(piece_count == expected_count, "difference: " << caseid << " #outputs expected: " << expected_count << " detected: " << pieces.size() ); if (expected_point_count >= 0) { BOOST_CHECK_EQUAL(n, std::size_t(expected_point_count)); } BOOST_CHECK_CLOSE(length, expected_length, 0.001); std::string lp = "lp_"; difference_output(lp + caseid, g1, g2, pieces); }
void test_boxes(std::string const& wkt1, std::string const& wkt2, double expected_area, bool expected_result) { Box box1, box2; bg::read_wkt(wkt1, box1); bg::read_wkt(wkt2, box2); Box box_out; bool detected = bg::intersection(box1, box2, box_out); typename bg::default_area_result<Box>::type area = bg::area(box_out); BOOST_CHECK_EQUAL(detected, expected_result); if (detected && expected_result) { BOOST_CHECK_CLOSE(area, expected_area, 0.01); } }
BOOST_AUTO_TEST_CASE_TEMPLATE(slerp, T, float_types) { vmath::core::Quaternion<T> H1( vmath::core::Vector<T, 3>(static_cast<T>(1.0), static_cast<T>(0.0), static_cast<T>(0.0)), vmath::radians(static_cast<T>(20.0))); vmath::core::Quaternion<T> H2( vmath::core::Vector<T, 3>(static_cast<T>(1.0), static_cast<T>(0.0), static_cast<T>(0.0)), vmath::radians(static_cast<T>(40.0))); vmath::core::Quaternion<T> Hs = vmath::core::Quaternion<T>::slerp(H1, H2, static_cast<T>(0.0)); BOOST_CHECK_CLOSE(Hs.x, H1.x, 1e-4f); BOOST_CHECK_CLOSE(Hs.y, H1.y, 1e-4f); BOOST_CHECK_CLOSE(Hs.z, H1.z, 1e-4f); BOOST_CHECK_CLOSE(Hs.w, H1.w, 1e-4f); Hs = vmath::core::Quaternion<T>::slerp(H1, H2, static_cast<T>(1.0)); BOOST_CHECK_CLOSE(Hs.x, H2.x, 1e-4f); BOOST_CHECK_CLOSE(Hs.y, H2.y, 1e-4f); BOOST_CHECK_CLOSE(Hs.z, H2.z, 1e-4f); BOOST_CHECK_CLOSE(Hs.w, H2.w, 1e-4f); }
BOOST_AUTO_TEST_CASE_TEMPLATE(inverse, T, float_types) { vmath::core::Matrix<T, 3> M; M[0][0] = static_cast<T>(1.0); M[0][1] = static_cast<T>(2.0); M[0][2] = static_cast<T>(3.0); M[1][0] = static_cast<T>(3.0); M[1][1] = static_cast<T>(1.0); M[1][2] = static_cast<T>(2.0); M[2][0] = static_cast<T>(2.0); M[2][1] = static_cast<T>(3.0); M[2][2] = static_cast<T>(1.0); vmath::core::Matrix<T, 3> M_inv = M.inverse(); BOOST_CHECK_CLOSE(M_inv[0][0], static_cast<T>(-0.277777791), 1e-4f); BOOST_CHECK_CLOSE(M_inv[0][1], static_cast<T>(0.388888896), 1e-4f); BOOST_CHECK_CLOSE(M_inv[0][2], static_cast<T>(0.055555556), 1e-4f); BOOST_CHECK_CLOSE(M_inv[1][0], static_cast<T>(0.055555556), 1e-4f); BOOST_CHECK_CLOSE(M_inv[1][1], static_cast<T>(-0.277777791), 1e-4f); BOOST_CHECK_CLOSE(M_inv[1][2], static_cast<T>(0.388888896), 1e-4f); BOOST_CHECK_CLOSE(M_inv[2][0], static_cast<T>(0.388888896), 1e-4f); BOOST_CHECK_CLOSE(M_inv[2][1], static_cast<T>(0.055555556), 1e-4f); BOOST_CHECK_CLOSE(M_inv[2][2], static_cast<T>(-0.277777791), 1e-4f); }
BOOST_AUTO_TEST_CASE_TEMPLATE(move, T, float_types) { vmath::core::Matrix<T, 3> M; M[0][0] = static_cast<T>(1.0); M[0][1] = static_cast<T>(2.0); M[0][2] = static_cast<T>(3.0); M[1][0] = static_cast<T>(4.0); M[1][1] = static_cast<T>(5.0); M[1][2] = static_cast<T>(6.0); M[2][0] = static_cast<T>(7.0); M[2][1] = static_cast<T>(8.0); M[2][2] = static_cast<T>(9.0); vmath::core::Matrix<T, 3> M_move(std::move(M)); BOOST_CHECK_CLOSE(M_move[0][0], static_cast<T>(1.0), 1e-4f); BOOST_CHECK_CLOSE(M_move[0][1], static_cast<T>(2.0), 1e-4f); BOOST_CHECK_CLOSE(M_move[0][2], static_cast<T>(3.0), 1e-4f); BOOST_CHECK_CLOSE(M_move[1][0], static_cast<T>(4.0), 1e-4f); BOOST_CHECK_CLOSE(M_move[1][1], static_cast<T>(5.0), 1e-4f); BOOST_CHECK_CLOSE(M_move[1][2], static_cast<T>(6.0), 1e-4f); BOOST_CHECK_CLOSE(M_move[2][0], static_cast<T>(7.0), 1e-4f); BOOST_CHECK_CLOSE(M_move[2][1], static_cast<T>(8.0), 1e-4f); BOOST_CHECK_CLOSE(M_move[2][2], static_cast<T>(9.0), 1e-4f); }
BOOST_AUTO_TEST_CASE_TEMPLATE(adjugate, T, float_types) { vmath::core::Matrix<T, 3> M; M[0][0] = static_cast<T>(1.0); M[0][1] = static_cast<T>(2.0); M[0][2] = static_cast<T>(3.0); M[1][0] = static_cast<T>(3.0); M[1][1] = static_cast<T>(1.0); M[1][2] = static_cast<T>(2.0); M[2][0] = static_cast<T>(2.0); M[2][1] = static_cast<T>(3.0); M[2][2] = static_cast<T>(1.0); vmath::core::Matrix<T, 3> M_adj = M.adjugate(); BOOST_CHECK_CLOSE(M_adj[0][0], static_cast<T>(-5.0), 1e-4f); BOOST_CHECK_CLOSE(M_adj[0][1], static_cast<T>(7.0), 1e-4f); BOOST_CHECK_CLOSE(M_adj[0][2], static_cast<T>(1.0), 1e-4f); BOOST_CHECK_CLOSE(M_adj[1][0], static_cast<T>(1.0), 1e-4f); BOOST_CHECK_CLOSE(M_adj[1][1], static_cast<T>(-5.0), 1e-4f); BOOST_CHECK_CLOSE(M_adj[1][2], static_cast<T>(7.0), 1e-4f); BOOST_CHECK_CLOSE(M_adj[2][0], static_cast<T>(7.0), 1e-4f); BOOST_CHECK_CLOSE(M_adj[2][1], static_cast<T>(1.0), 1e-4f); BOOST_CHECK_CLOSE(M_adj[2][2], static_cast<T>(-5.0), 1e-4f); }
static void apply(Box const& b, const type& x1, const type& y1, const type& z1, const type& x2, const type& y2, const type& z2) { BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 0>(b)), x1, 0.001); BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 1>(b)), y1, 0.001); BOOST_CHECK_CLOSE((bg::get<bg::min_corner, 2>(b)), z1, 0.001); BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 0>(b)), x2, 0.001); BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 1>(b)), y2, 0.001); BOOST_CHECK_CLOSE((bg::get<bg::max_corner, 2>(b)), z2, 0.001); }
void test_perimeter(Geometry const& geometry, long double expected_perimeter) { typename bg::default_distance_result<Geometry>::type perimeter = bg::perimeter(geometry); #ifdef GEOMETRY_TEST_DEBUG std::ostringstream out; out << typeid(typename bg::coordinate_type<Geometry>::type).name() << std::endl << typeid(typename bg::perimeter_result<Geometry>::type).name() << std::endl << "perimeter : " << bg::perimeter(geometry) << std::endl; std::cout << out.str(); #endif BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001); }
BOOST_FIXTURE_TEST_CASE(proportional_plus_integral_cooling, PidTest) { pid->setConstants(10.0, 600, 0); pid->setActuatorIsNegative(true); sp->write(19.0); sensor->setTemp(20.0); // update for 10 minutes for(int i = 0; i < 600; i++){ pid->update(); act->update(); } // integrator result is error / Ti * time, So 600 * 1 degree error / 60 = 10.0 BOOST_CHECK_CLOSE(double(act->getValue()), 20.0, 2); }
void test_spots(T) { // // Basic sanity checks, tolerance is 20 epsilon expressed as a percentage: // T tolerance = boost::math::tools::epsilon<T>() * 20 * 100; T small = boost::math::tools::epsilon<T>() / 1024; BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(1), static_cast<T>(1)), static_cast<T>(1), tolerance); BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(1), static_cast<T>(4)), static_cast<T>(0.25), tolerance); BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(4), static_cast<T>(1)), static_cast<T>(0.25), tolerance); BOOST_CHECK_CLOSE(::boost::math::beta(small, static_cast<T>(4)), 1/small, tolerance); BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(4), small), 1/small, tolerance); BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(4), static_cast<T>(20)), static_cast<T>(0.00002823263692828910220214568040654997176736L), tolerance); BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(0.0125L), static_cast<T>(0.000023L)), static_cast<T>(43558.24045647538375006349016083320744662L), tolerance); }
BOOST_FIXTURE_TEST_CASE(proportional_plus_derivative_cooling, PidTest) { pid->setConstants(10.0, 0, 60); pid->setActuatorIsNegative(true); sp->write(5.0); // update for 10 minutes for(int i = 0; i <= 600; i++){ sensor->setTemp(temp_t(20.0) - temp_t(i*0.015625)); pid->update(); act->update(); } BOOST_CHECK_EQUAL(sensor->read(), temp_t(10.625)); // sensor value should have gone up 9.375 degrees BOOST_CHECK_CLOSE(double(act->getValue()), 10.0*(10.625-5.0) - 10*0.015625*60, 5); }
BOOST_FIXTURE_TEST_CASE(proportional_plus_integral, PidTest) { pid->setConstants(10.0, 600, 0); sp->write(21.0); sensor->setTemp(20.0); // update for 10 minutes for(int i = 0; i < 600; i++){ pid->update(); act->update(); } // integrator result is Kp * error * 1 / Ti, So 10* 600 * 1 degree error / 600 = 10.0 // proportional gain is 10, total is 20 BOOST_CHECK_CLOSE(double(act->getValue()), 20.0, 2); }
void test_large_integers() { typedef bg::model::point<int, 2, bg::cs::cartesian> int_point_type; typedef bg::model::point<double, 2, bg::cs::cartesian> double_point_type; bg::model::box<int_point_type> int_box; bg::model::box<double_point_type> double_box; std::string const box_li = "POLYGON((1536119 192000, 1872000 528000))"; bg::read_wkt(box_li, int_box); bg::read_wkt(box_li, double_box); double int_value = bgi::detail::comparable_margin(int_box); double double_value = bgi::detail::comparable_margin(double_box); BOOST_CHECK_CLOSE(int_value, double_value, 0.0001); }
void test_length(Geometry const& geometry, long double expected_length) { typename bg::default_length_result<Geometry>::type length = bg::length(geometry); #ifdef GEOMETRY_TEST_DEBUG std::ostringstream out; out << typeid(typename bg::coordinate_type<Geometry>::type).name() << std::endl << typeid(typename bg::default_length_result<Geometry>::type).name() << std::endl << "length : " << bg::length(geometry) << std::endl; std::cout << out.str(); #endif BOOST_CHECK_CLOSE(length, expected_length, 0.0001); }
BOOST_AUTO_TEST_CASE_TEMPLATE(transpose, T, float_types) { vmath::core::Matrix<T, 3> M; M[0][0] = static_cast<T>(1.0); M[0][1] = static_cast<T>(2.0); M[0][2] = static_cast<T>(3.0); M[1][0] = static_cast<T>(4.0); M[1][1] = static_cast<T>(5.0); M[1][2] = static_cast<T>(6.0); M[2][0] = static_cast<T>(7.0); M[2][1] = static_cast<T>(8.0); M[2][2] = static_cast<T>(9.0); vmath::core::Matrix<T, 3> M_trans; M_trans = M.transpose(); BOOST_CHECK_CLOSE(M_trans[0][0], static_cast<T>(1.0), 1e-4f); BOOST_CHECK_CLOSE(M_trans[0][1], static_cast<T>(4.0), 1e-4f); BOOST_CHECK_CLOSE(M_trans[0][2], static_cast<T>(7.0), 1e-4f); BOOST_CHECK_CLOSE(M_trans[1][0], static_cast<T>(2.0), 1e-4f); BOOST_CHECK_CLOSE(M_trans[1][1], static_cast<T>(5.0), 1e-4f); BOOST_CHECK_CLOSE(M_trans[1][2], static_cast<T>(8.0), 1e-4f); BOOST_CHECK_CLOSE(M_trans[2][0], static_cast<T>(3.0), 1e-4f); BOOST_CHECK_CLOSE(M_trans[2][1], static_cast<T>(6.0), 1e-4f); BOOST_CHECK_CLOSE(M_trans[2][2], static_cast<T>(9.0), 1e-4f); }
BOOST_AUTO_TEST_CASE_TEMPLATE(cofactor, T, float_types) { vmath::core::Matrix<T, 3> M; M[0][0] = static_cast<T>(1.0); M[0][1] = static_cast<T>(2.0); M[0][2] = static_cast<T>(3.0); M[1][0] = static_cast<T>(4.0); M[1][1] = static_cast<T>(5.0); M[1][2] = static_cast<T>(6.0); M[2][0] = static_cast<T>(7.0); M[2][1] = static_cast<T>(8.0); M[2][2] = static_cast<T>(9.0); vmath::core::Matrix<T, 3> M_cofactor; M_cofactor = M.cofactor(); BOOST_CHECK_CLOSE(M_cofactor[0][0], static_cast<T>(-3.0), 1e-4f); BOOST_CHECK_CLOSE(M_cofactor[0][1], static_cast<T>(6.0), 1e-4f); BOOST_CHECK_CLOSE(M_cofactor[0][2], static_cast<T>(-3.0), 1e-4f); BOOST_CHECK_CLOSE(M_cofactor[1][0], static_cast<T>(6.0), 1e-4f); BOOST_CHECK_CLOSE(M_cofactor[1][1], static_cast<T>(-12.0), 1e-4f); BOOST_CHECK_CLOSE(M_cofactor[1][2], static_cast<T>(6.0), 1e-4f); BOOST_CHECK_CLOSE(M_cofactor[2][0], static_cast<T>(-3.0), 1e-4f); BOOST_CHECK_CLOSE(M_cofactor[2][1], static_cast<T>(6.0), 1e-4f); BOOST_CHECK_CLOSE(M_cofactor[2][2], static_cast<T>(-3.0), 1e-4f); }
BOOST_AUTO_TEST_CASE_TEMPLATE(assign_op, T, float_types) { vmath::core::Matrix<T, 3> M; M[0][0] = static_cast<T>(1.0); M[0][1] = static_cast<T>(2.0); M[0][2] = static_cast<T>(3.0); M[1][0] = static_cast<T>(4.0); M[1][1] = static_cast<T>(5.0); M[1][2] = static_cast<T>(6.0); M[2][0] = static_cast<T>(7.0); M[2][1] = static_cast<T>(8.0); M[2][2] = static_cast<T>(9.0); vmath::core::Matrix<T, 3> M_assign; M_assign = M; BOOST_CHECK_CLOSE(M_assign[0][0], static_cast<T>(1.0), 1e-4f); BOOST_CHECK_CLOSE(M_assign[0][1], static_cast<T>(2.0), 1e-4f); BOOST_CHECK_CLOSE(M_assign[0][2], static_cast<T>(3.0), 1e-4f); BOOST_CHECK_CLOSE(M_assign[1][0], static_cast<T>(4.0), 1e-4f); BOOST_CHECK_CLOSE(M_assign[1][1], static_cast<T>(5.0), 1e-4f); BOOST_CHECK_CLOSE(M_assign[1][2], static_cast<T>(6.0), 1e-4f); BOOST_CHECK_CLOSE(M_assign[2][0], static_cast<T>(7.0), 1e-4f); BOOST_CHECK_CLOSE(M_assign[2][1], static_cast<T>(8.0), 1e-4f); BOOST_CHECK_CLOSE(M_assign[2][2], static_cast<T>(9.0), 1e-4f); }
BOOST_AUTO_TEST_CASE_TEMPLATE(minors, T, float_types) { vmath::core::Matrix<T, 3> M; M[0][0] = static_cast<T>(1.0); M[0][1] = static_cast<T>(2.0); M[0][2] = static_cast<T>(3.0); M[1][0] = static_cast<T>(4.0); M[1][1] = static_cast<T>(5.0); M[1][2] = static_cast<T>(6.0); M[2][0] = static_cast<T>(7.0); M[2][1] = static_cast<T>(8.0); M[2][2] = static_cast<T>(9.0); vmath::core::Matrix<T, 3> M_minors; M_minors = M.minors(); BOOST_CHECK_CLOSE(M_minors[0][0], static_cast<T>(-3.0), 1e-4f); BOOST_CHECK_CLOSE(M_minors[0][1], static_cast<T>(-6.0), 1e-4f); BOOST_CHECK_CLOSE(M_minors[0][2], static_cast<T>(-3.0), 1e-4f); BOOST_CHECK_CLOSE(M_minors[1][0], static_cast<T>(-6.0), 1e-4f); BOOST_CHECK_CLOSE(M_minors[1][1], static_cast<T>(-12.0), 1e-4f); BOOST_CHECK_CLOSE(M_minors[1][2], static_cast<T>(-6.0), 1e-4f); BOOST_CHECK_CLOSE(M_minors[2][0], static_cast<T>(-3.0), 1e-4f); BOOST_CHECK_CLOSE(M_minors[2][1], static_cast<T>(-6.0), 1e-4f); BOOST_CHECK_CLOSE(M_minors[2][2], static_cast<T>(-3.0), 1e-4f); }
BOOST_AUTO_TEST_CASE_TEMPLATE(negate_op, T, float_types) { vmath::core::Matrix<T, 3> M; M[0][0] = static_cast<T>(1.0); M[0][1] = static_cast<T>(2.0); M[0][2] = static_cast<T>(3.0); M[1][0] = static_cast<T>(4.0); M[1][1] = static_cast<T>(5.0); M[1][2] = static_cast<T>(6.0); M[2][0] = static_cast<T>(7.0); M[2][1] = static_cast<T>(8.0); M[2][2] = static_cast<T>(9.0); vmath::core::Matrix<T, 3> M_neg; M_neg = -M; BOOST_CHECK_CLOSE(M_neg[0][0], static_cast<T>(-1.0), 1e-4f); BOOST_CHECK_CLOSE(M_neg[0][1], static_cast<T>(-2.0), 1e-4f); BOOST_CHECK_CLOSE(M_neg[0][2], static_cast<T>(-3.0), 1e-4f); BOOST_CHECK_CLOSE(M_neg[1][0], static_cast<T>(-4.0), 1e-4f); BOOST_CHECK_CLOSE(M_neg[1][1], static_cast<T>(-5.0), 1e-4f); BOOST_CHECK_CLOSE(M_neg[1][2], static_cast<T>(-6.0), 1e-4f); BOOST_CHECK_CLOSE(M_neg[2][0], static_cast<T>(-7.0), 1e-4f); BOOST_CHECK_CLOSE(M_neg[2][1], static_cast<T>(-8.0), 1e-4f); BOOST_CHECK_CLOSE(M_neg[2][2], static_cast<T>(-9.0), 1e-4f); }
void test_content(Geometry const& geometry, typename bgi::detail::default_content_result<Geometry>::type expected_value) { typename bgi::detail::default_content_result<Geometry>::type value = bgi::detail::content(geometry); #ifdef BOOST_GEOMETRY_TEST_DEBUG std::ostringstream out; out << typeid(typename bg::coordinate_type<Geometry>::type).name() << " " << typeid(typename bgi::detail::default_content_result<Geometry>::type).name() << " " << "content : " << value << std::endl; std::cout << out.str(); #endif BOOST_CHECK_CLOSE(value, expected_value, 0.0001); }
BOOST_AUTO_TEST_CASE_TEMPLATE(copy, T, float_types) { vmath::core::Matrix<T, 4, 2> M; M[0][0] = static_cast<T>(1.0); M[0][1] = static_cast<T>(2.0); M[0][2] = static_cast<T>(3.0); M[0][3] = static_cast<T>(4.0); M[1][0] = static_cast<T>(5.0); M[1][1] = static_cast<T>(6.0); M[1][2] = static_cast<T>(7.0); M[1][3] = static_cast<T>(8.0); vmath::core::Matrix<T, 4, 2> M_copy(M); BOOST_CHECK_CLOSE(M_copy[0][0], static_cast<T>(1.0), 1e-4f); BOOST_CHECK_CLOSE(M_copy[0][1], static_cast<T>(2.0), 1e-4f); BOOST_CHECK_CLOSE(M_copy[0][2], static_cast<T>(3.0), 1e-4f); BOOST_CHECK_CLOSE(M_copy[0][3], static_cast<T>(4.0), 1e-4f); BOOST_CHECK_CLOSE(M_copy[1][0], static_cast<T>(5.0), 1e-4f); BOOST_CHECK_CLOSE(M_copy[1][1], static_cast<T>(6.0), 1e-4f); BOOST_CHECK_CLOSE(M_copy[1][2], static_cast<T>(7.0), 1e-4f); BOOST_CHECK_CLOSE(M_copy[1][3], static_cast<T>(8.0), 1e-4f); }
void test_structs_minimal() { std::random_device rd; std::mt19937 gen(rd()); for(int ii=0; ii<100; ++ii) { TestStruct o_struct = { random_basic_string<char>(gen), random_value<double>(gen), random_value<std::uint32_t>(gen), random_value<uint8_t>(gen) % 2 ? true : false }; Issue79Struct o_struct2 = { random_value<std::int32_t>(gen) }; Issue79StructInternal o_struct3 = { random_value<std::int32_t>(gen) }; std::ostringstream os; { OArchive oar(os); oar( o_struct ); oar( o_struct2 ); oar( o_struct3 ); } decltype(o_struct) i_struct; decltype(o_struct2) i_struct2; decltype(o_struct3) i_struct3; std::istringstream is(os.str()); { IArchive iar(is); iar( i_struct ); iar( i_struct2 ); iar( i_struct3 ); } BOOST_CHECK(o_struct.mm.x == i_struct.mm.x); BOOST_CHECK_CLOSE(o_struct.mmv.x, i_struct.mmv.x, 1e-5); BOOST_CHECK(o_struct.nmm.x == i_struct.nmm.x); BOOST_CHECK(o_struct.nmmv.x == i_struct.nmmv.x); BOOST_CHECK(o_struct2.x == i_struct2.x); BOOST_CHECK(o_struct3.x == i_struct3.x); } }
BOOST_AUTO_TEST_CASE_TEMPLATE(scalar_div_eq_op, T, float_types) { vmath::core::Matrix<T, 3> M; M[0][0] = static_cast<T>(2.0); M[0][1] = static_cast<T>(4.0); M[0][2] = static_cast<T>(6.0); M[1][0] = static_cast<T>(8.0); M[1][1] = static_cast<T>(10.0); M[1][2] = static_cast<T>(12.0); M[2][0] = static_cast<T>(14.0); M[2][1] = static_cast<T>(16.0); M[2][2] = static_cast<T>(18.0); T s = static_cast<T>(2.0); vmath::core::Matrix<T, 3> M_div = M; M_div /= s; BOOST_CHECK_CLOSE(M_div[0][0], static_cast<T>(1.0), 1e-4f); BOOST_CHECK_CLOSE(M_div[0][1], static_cast<T>(2.0), 1e-4f); BOOST_CHECK_CLOSE(M_div[0][2], static_cast<T>(3.0), 1e-4f); BOOST_CHECK_CLOSE(M_div[1][0], static_cast<T>(4.0), 1e-4f); BOOST_CHECK_CLOSE(M_div[1][1], static_cast<T>(5.0), 1e-4f); BOOST_CHECK_CLOSE(M_div[1][2], static_cast<T>(6.0), 1e-4f); BOOST_CHECK_CLOSE(M_div[2][0], static_cast<T>(7.0), 1e-4f); BOOST_CHECK_CLOSE(M_div[2][1], static_cast<T>(8.0), 1e-4f); BOOST_CHECK_CLOSE(M_div[2][2], static_cast<T>(9.0), 1e-4f); }
BOOST_AUTO_TEST_CASE_TEMPLATE(invert, T, float_types) { vmath::core::Quaternion<T> H; H.x = static_cast<T>(2.0); H.y = static_cast<T>(4.0); H.z = static_cast<T>(2.0); H.w = static_cast<T>(4.0); H.invert(); BOOST_CHECK_CLOSE(H.x, static_cast<T>(-0.05), 1e-4); BOOST_CHECK_CLOSE(H.y, static_cast<T>(-0.1), 1e-4f); BOOST_CHECK_CLOSE(H.z, static_cast<T>(-0.05), 1e-4f); BOOST_CHECK_CLOSE(H.w, static_cast<T>(0.1), 1e-4f); H.x = static_cast<T>(0.5); H.y = static_cast<T>(0.5); H.z = static_cast<T>(0.5); H.w = static_cast<T>(0.5); vmath::core::Quaternion<T> H_inv = H.invert(); BOOST_CHECK_CLOSE(H_inv.x, static_cast<T>(-0.5), 1e-4); BOOST_CHECK_CLOSE(H_inv.y, static_cast<T>(-0.5), 1e-4f); BOOST_CHECK_CLOSE(H_inv.z, static_cast<T>(-0.5), 1e-4f); BOOST_CHECK_CLOSE(H_inv.w, static_cast<T>(0.5), 1e-4f); }
void check_controls_epoch1( struct WellControls ** ctrls) { // The injector { const struct WellControls * ctrls0 = ctrls[0]; BOOST_CHECK_EQUAL( 3 , well_controls_get_num(ctrls0)); // The number of controls for the injector == 3?? BOOST_CHECK_EQUAL( SURFACE_RATE , well_controls_iget_type(ctrls0 , 0 )); BOOST_CHECK_EQUAL( RESERVOIR_RATE , well_controls_iget_type(ctrls0 , 1 )); BOOST_CHECK_EQUAL( BHP , well_controls_iget_type(ctrls0 , 2 )); // The different targets BOOST_CHECK_CLOSE( 10.0 / 86400 , well_controls_iget_target(ctrls0 , 0) , 0.001); BOOST_CHECK_CLOSE( 20.0 / 86400 , well_controls_iget_target(ctrls0 , 1) , 0.001); BOOST_CHECK_CLOSE( 40 * 100000 , well_controls_iget_target(ctrls0 , 2) , 0.001); // Which control is active BOOST_CHECK_EQUAL( 1 , well_controls_get_current(ctrls0)); { const double * distr = well_controls_iget_distr( ctrls0 , 1 ); BOOST_CHECK_EQUAL( 1 , distr[0] ); // Water BOOST_CHECK_EQUAL( 0 , distr[1] ); // Oil BOOST_CHECK_EQUAL( 0 , distr[2] ); // Gas } } // The producer { const struct WellControls * ctrls1 = ctrls[1]; BOOST_CHECK_EQUAL( 3 , well_controls_get_num(ctrls1)); // The number of controls for the producer - now 3. BOOST_CHECK_EQUAL( SURFACE_RATE , well_controls_iget_type(ctrls1 , 0) ); BOOST_CHECK_EQUAL( RESERVOIR_RATE , well_controls_iget_type(ctrls1 , 1) ); BOOST_CHECK_EQUAL( BHP , well_controls_iget_type(ctrls1 , 2) ); // The different targets BOOST_CHECK_CLOSE( -999.0 / 86400 , well_controls_iget_target(ctrls1 , 0), 0.001); BOOST_CHECK_CLOSE( -123.0 / 86400 , well_controls_iget_target(ctrls1 , 1), 0.001); BOOST_CHECK_CLOSE( 100 * 100000 , well_controls_iget_target(ctrls1 , 2), 0.001); // Which control is active BOOST_CHECK_EQUAL( 1 , well_controls_get_current(ctrls1) ); { const double * distr = well_controls_iget_distr( ctrls1 , 1 ); BOOST_CHECK_EQUAL( 1 , distr[0] ); // Water BOOST_CHECK_EQUAL( 1 , distr[1] ); // Oil BOOST_CHECK_EQUAL( 1 , distr[2] ); // Gas } } }
BOOST_AUTO_TEST_CASE_TEMPLATE(members, T, float_types) { vmath::core::Matrix<T, 3, 2> M; M[0] = vmath::core::Vector<T, 3>(static_cast<T>(1.0), static_cast<T>(2.0), static_cast<T>(3.0)); M[1] = vmath::core::Vector<T, 3>(static_cast<T>(4.0), static_cast<T>(5.0), static_cast<T>(6.0)); BOOST_CHECK_CLOSE(M[0][0], static_cast<T>(1.0), 1e-4f); BOOST_CHECK_CLOSE(M[0][1], static_cast<T>(2.0), 1e-4f); BOOST_CHECK_CLOSE(M[0][2], static_cast<T>(3.0), 1e-4f); BOOST_CHECK_CLOSE(M[1][0], static_cast<T>(4.0), 1e-4f); BOOST_CHECK_CLOSE(M[1][1], static_cast<T>(5.0), 1e-4f); BOOST_CHECK_CLOSE(M[1][2], static_cast<T>(6.0), 1e-4f); // invalid index BOOST_CHECK_THROW(M[2], std::out_of_range); BOOST_CHECK_THROW((M[2] = vmath::core::Vector<T, 3>()), std::out_of_range); }
void test_large_integers() { typedef bg::model::point<int, 2, bg::cs::cartesian> int_point_type; typedef bg::model::point<double, 2, bg::cs::cartesian> double_point_type; bg::model::box<int_point_type> int_box1, int_box2; bg::model::box<double_point_type> double_box1, double_box2; std::string const box_li1 = "POLYGON((1536119 192000, 1872000 528000))"; std::string const box_li2 = "POLYGON((1701234 368250, 2673400 777400))"; bg::read_wkt(box_li1, int_box1); bg::read_wkt(box_li1, double_box1); bg::read_wkt(box_li2, int_box2); bg::read_wkt(box_li2, double_box2); double int_value = bgi::detail::union_content(int_box1, int_box2); double double_value = bgi::detail::union_content(double_box1, double_box2); BOOST_CHECK_CLOSE(int_value, double_value, 0.0001); }
BOOST_FIXTURE_TEST_CASE_TEMPLATE(trivial_convolveImageLocalMem, T, Fixtures, T) { const float* image = T::image_.data(); anyfold::image_stack expected(T::image_); float* kernel = new float[T::kernel_size_]; std::fill(kernel, kernel+T::kernel_size_,0.f); anyfold::opencl::convolve_3dImageLocalMem(image, &T::image_shape_[0], kernel,&T::kernel_dims_[0], T::output_.data()); float sum = std::accumulate(T::output_.data(), T::output_.data() + T::output_.num_elements(),0.f); BOOST_CHECK_CLOSE(sum, 0.f, .00001); delete [] kernel; }
void test(Point const& pt, Indexable const& indexable, typename bg::default_distance_result<Point, Indexable>::type expected_value) { typename bg::default_distance_result<Point, Indexable>::type value = bgi::detail::minmaxdist(pt, indexable); #ifdef GEOMETRY_TEST_DEBUG std::ostringstream out; out << typeid(typename bg::coordinate_type<Point>::type).name() << " " << typeid(typename bg::coordinate_type<Indexable>::type).name() << " " << typeid(bg::default_distance_result<Point, Indexable>::type).name() << " " << "minmaxdist : " << value << std::endl; std::cout << out.str(); #endif BOOST_CHECK_CLOSE(value, expected_value, 0.0001); }
BOOST_AUTO_TEST_CASE_TEMPLATE(members, T, float_types) { vmath::core::Quaternion<T> H; H.x = static_cast<T>(20.12); H.y = static_cast<T>(100.89); H.z = static_cast<T>(-18.2); H.w = static_cast<T>(35.62); BOOST_CHECK_CLOSE(H[0], H.x, 1e-4f); BOOST_CHECK_CLOSE(H[1], H.y, 1e-4f); BOOST_CHECK_CLOSE(H[2], H.z, 1e-4f); BOOST_CHECK_CLOSE(H[3], H.w, 1e-4f); H[0] = static_cast<T>(100.89); H[1] = static_cast<T>(-18.2); H[2] = static_cast<T>(35.62); H[3] = static_cast<T>(20.12); BOOST_CHECK_CLOSE(H[0], H.x, 1e-4f); BOOST_CHECK_CLOSE(H[1], H.y, 1e-4f); BOOST_CHECK_CLOSE(H[2], H.z, 1e-4f); BOOST_CHECK_CLOSE(H[3], H.w, 1e-4f); // invalid index BOOST_CHECK_THROW(H[4], std::out_of_range); BOOST_CHECK_THROW(H[4] = static_cast<T>(0.0), std::out_of_range); }