BOOST_AUTO_TEST_CASE_TEMPLATE(test_non_integral_arithmetic_relations, T, non_integral_test_types ) { polynomial<T> const a(d8b.begin(), d8b.end()); polynomial<T> const b(d1a.begin(), d1a.end()); BOOST_CHECK_EQUAL(a * T(0.5), a / T(2)); }
FM2GP_Ex_8_3__2() { boost::array<T, 5> const x_data = {{1, -6, -8, 6, 7}}; boost::array<T, 5> const y_data = {{1, -5, -2, 15, 11}}; boost::array<T, 3> const z_data = {{1, 2, 1}}; x = polynomial<T>(x_data.begin(), x_data.end()); y = polynomial<T>(y_data.begin(), y_data.end()); z = polynomial<T>(z_data.begin(), z_data.end()); }
FM2GP_Ex_8_3__1() { boost::array<T, 5> const x_data = {{105, 278, -88, -56, 16}}; boost::array<T, 5> const y_data = {{70, 232, -44, -64, 16}}; boost::array<T, 3> const z_data = {{35, -24, 4}}; x = polynomial<T>(x_data.begin(), x_data.end()); y = polynomial<T>(y_data.begin(), y_data.end()); z = polynomial<T>(z_data.begin(), z_data.end()); }
FM2GP_trivial() { boost::array<T, 4> const x_data = {{-2, -3, 0, 1}}; boost::array<T, 3> const y_data = {{-4, 0, 1}}; boost::array<T, 2> const z_data= {{-2, 1}}; x = polynomial<T>(x_data.begin(), x_data.end()); y = polynomial<T>(y_data.begin(), y_data.end()); z = polynomial<T>(z_data.begin(), z_data.end()); }
BOOST_AUTO_TEST_CASE_TEMPLATE( test_arithmetic_relations, T, all_test_types ) { polynomial<T> const a(d8b.begin(), d8b.end()); polynomial<T> const b(d1a.begin(), d1a.end()); BOOST_CHECK_EQUAL(a * T(2), a + a); BOOST_CHECK_EQUAL(a - b, -b + a); BOOST_CHECK_EQUAL(a, (a * a) / a); BOOST_CHECK_EQUAL(a, (a / a) * a); }
BOOST_AUTO_TEST_CASE_TEMPLATE(test_odd_even, T, all_test_types) { polynomial<T> const zero; BOOST_CHECK_EQUAL(odd(zero), false); BOOST_CHECK_EQUAL(even(zero), true); polynomial<T> const a(d0a.begin(), d0a.end()); BOOST_CHECK_EQUAL(odd(a), true); BOOST_CHECK_EQUAL(even(a), false); polynomial<T> const b(d0a1.begin(), d0a1.end()); BOOST_CHECK_EQUAL(odd(b), false); BOOST_CHECK_EQUAL(even(b), true); }
BOOST_AUTO_TEST_CASE_TEMPLATE(test_right_shift, T, all_test_types ) { polynomial<T> a(d8b.begin(), d8b.end()); polynomial<T> const aa(a); polynomial<T> const b(d8b.begin() + 1, d8b.end()); polynomial<T> const c(d8b.begin() + 5, d8b.end()); a >>= 0u; BOOST_CHECK_EQUAL(a, aa); a >>= 1u; BOOST_CHECK_EQUAL(a, b); a = a >> 4u; BOOST_CHECK_EQUAL(a, c); }
BOOST_AUTO_TEST_CASE_TEMPLATE( test_addition, T, all_test_types ) { polynomial<T> const a(d3a.begin(), d3a.end()); polynomial<T> const b(d1a.begin(), d1a.end()); polynomial<T> const zero; polynomial<T> result = a + b; // different degree boost::array<T, 4> tmp = {{8, -5, -4, 3}}; polynomial<T> expected(tmp.begin(), tmp.end()); BOOST_CHECK_EQUAL(result, expected); BOOST_CHECK_EQUAL(a + zero, a); BOOST_CHECK_EQUAL(a + b, b + a); }
BOOST_AUTO_TEST_CASE_TEMPLATE( test_self_multiply_assign, T, all_test_types ) { polynomial<T> a(d3a.begin(), d3a.end()); polynomial<T> const b(a); boost::array<double, 7> const d3a_sq = {{100, -120, -44, 108, -20, -24, 9}}; polynomial<T> const asq(d3a_sq.begin(), d3a_sq.end()); a *= a; BOOST_CHECK_EQUAL(a, b*b); BOOST_CHECK_EQUAL(a, asq); a *= a; BOOST_CHECK_EQUAL(a, b*b*b*b); }
BOOST_AUTO_TEST_CASE_TEMPLATE(test_bool, T, all_test_types) { polynomial<T> const zero; polynomial<T> const a(d0a.begin(), d0a.end()); BOOST_CHECK_EQUAL(bool(zero), false); BOOST_CHECK_EQUAL(bool(a), true); }
BOOST_AUTO_TEST_CASE_TEMPLATE(test_leading_coefficient, T, all_test_types) { polynomial<T> const zero; BOOST_CHECK_EQUAL(leading_coefficient(zero), T(0)); polynomial<T> a(d0a.begin(), d0a.end()); BOOST_CHECK_EQUAL(leading_coefficient(a), T(d0a.back())); }
//-------------------------------------------------------------------------- //! Construct with signed distance function values of the vertices void create( const boost::array<double,numElementNodes>& signedDistances ) { // Minimal value of signed distances const double distMin = *(std::min_element( signedDistances.begin(), signedDistances.end() ) ); // Maximal value of signed distances const double distMax = *(std::max_element( signedDistances.begin(), signedDistances.end() ) ); // Change of signs implies a cut cell if ( (distMin * distMax) <= 0. ) { isCut_ = true; isInside_ = false; isOutside_ = false; // get the vertices of the shape boost::array<VecDim,LinearLagrange::numFun> vertexCoordinates; LinearLagrange::supportPoints( vertexCoordinates ); boost::array<unsigned,LinearLagrange::numFun> vertexIndices; // fill nodes with the vertices of this shape for ( unsigned v = 0; v < vertexCoordinates.size(); v++ ) { nodes_.push_back( vertexCoordinates[v] ); vertexIndices[v] = v; } // create the internal structure of the cut cell std::map<base::cut::Edge,unsigned> uniqueNodes; base::cut::MarchingProxy<shape,geomDegree>::apply( signedDistances, vertexIndices, nodes_, uniqueNodes, surface_, volumeIn_, volumeOut_, false ); } else { isCut_ = false; // decide location of cell which is not cut if ( distMax < 0. ) { isInside_ = false; isOutside_ = true; } else { isInside_ = true; isOutside_ = false; } } }
BOOST_AUTO_TEST_CASE_TEMPLATE(test_left_shift, T, all_test_types ) { polynomial<T> a(d0a.begin(), d0a.end()); polynomial<T> const aa(a); polynomial<T> const b(d0a1.begin(), d0a1.end()); polynomial<T> const c(d0a5.begin(), d0a5.end()); a <<= 0u; BOOST_CHECK_EQUAL(a, aa); a <<= 1u; BOOST_CHECK_EQUAL(a, b); a = a << 4u; BOOST_CHECK_EQUAL(a, c); polynomial<T> zero; // Multiplying zero by x should still be zero. zero <<= 1u; BOOST_CHECK_EQUAL(zero, zero_element(multiplies< polynomial<T> >())); }
void setup_covariance(boost::array<double, 9> &cov, double stdev) { std::fill(cov.begin(), cov.end(), 0.0); if (stdev == 0.0) cov[0] = -1.0; else { cov[0+0] = cov[3+1] = cov[6+2] = std::pow(stdev, 2); } }
BOOST_AUTO_TEST_CASE_TEMPLATE(test_cont_and_pp, T, integral_test_types) { boost::array<polynomial<T>, 4> const q={{ polynomial<T>(d8.begin(), d8.end()), polynomial<T>(d8b.begin(), d8b.end()), polynomial<T>(d3a.begin(), d3a.end()), polynomial<T>(d3b.begin(), d3b.end()) }}; for (std::size_t i = 0; i < q.size(); i++) { BOOST_CHECK_EQUAL(q[i], content(q[i]) * primitive_part(q[i])); BOOST_CHECK_EQUAL(primitive_part(q[i]), primitive_part(q[i], content(q[i]))); } polynomial<T> const zero; BOOST_CHECK_EQUAL(primitive_part(zero), zero); BOOST_CHECK_EQUAL(content(zero), T(0)); }
BOOST_AUTO_TEST_CASE_TEMPLATE( transitivity1 , Stepper , dummy_steppers ) { typedef times_iterator< Stepper , empty_system , state_type , time_iterator_type > stepper_iterator; std::cout << "transitivity1" << std::endl; state_type x = {{ 1.0 }}; stepper_iterator first1( Stepper() , empty_system() , x , times.end() , times.end() , 0.1 ); stepper_iterator last1( Stepper() , empty_system() , x ); stepper_iterator last2( Stepper() , empty_system() , x ); BOOST_CHECK( first1 == last1 ); BOOST_CHECK( first1 == last2 ); BOOST_CHECK( last1 == last2 ); first1 = stepper_iterator( Stepper() , empty_system() , x , times.end()-1 , times.end() , 0.1 ); last1 = stepper_iterator( Stepper() , empty_system() , x ); BOOST_CHECK( first1 != last1 ); BOOST_CHECK( ++first1 == last1 ); }
void DiscoveryServer::HandleReceive(const boost::system::error_code& error) { if (!error && std::string(m_recv_buffer.begin(), m_recv_buffer.end()) == DISCOVERY_QUESTION) { m_socket.send_to( boost::asio::buffer(DISCOVERY_ANSWER + boost::asio::ip::host_name()), m_remote_endpoint); } Listen(); }
BOOST_AUTO_TEST_CASE_TEMPLATE( test_multiplication, T, all_test_types ) { polynomial<T> const a(d3a.begin(), d3a.end()); polynomial<T> const b(d1a.begin(), d1a.end()); polynomial<T> const zero; boost::array<T, 7> const d3a_sq = {{100, -120, -44, 108, -20, -24, 9}}; polynomial<T> const a_sq(d3a_sq.begin(), d3a_sq.end()); BOOST_CHECK_EQUAL(a * T(0), zero); BOOST_CHECK_EQUAL(a * zero, zero); BOOST_CHECK_EQUAL(zero * T(0), zero); BOOST_CHECK_EQUAL(zero * zero, zero); BOOST_CHECK_EQUAL(a * b, b * a); polynomial<T> aa(a); aa *= aa; BOOST_CHECK_EQUAL(aa, a_sq); BOOST_CHECK_EQUAL(aa, a * a); }
BOOST_AUTO_TEST_CASE_TEMPLATE(test_set_zero, T, all_test_types) { polynomial<T> const zero; polynomial<T> a(d0a.begin(), d0a.end()); a.set_zero(); BOOST_CHECK_EQUAL(a, zero); a.set_zero(); // Ensure that setting zero to zero is a no-op. BOOST_CHECK_EQUAL(a, zero); }
BOOST_AUTO_TEST_CASE_TEMPLATE( test_subtraction, T, all_test_types ) { polynomial<T> const a(d3a.begin(), d3a.end()); polynomial<T> const zero; BOOST_CHECK_EQUAL(a - T(0), a); BOOST_CHECK_EQUAL(T(0) - a, -a); BOOST_CHECK_EQUAL(a - zero, a); BOOST_CHECK_EQUAL(zero - a, -a); BOOST_CHECK_EQUAL(a - a, zero); }
~FiberControl(){ AUTO(it, g_stack_pool.begin()); for(;;){ if(it == g_stack_pool.end()){ stack.reset(); break; } if(!*it){ stack.swap(*it); break; } ++it; } }
// NOTE: Slightly unexpected: this unit test passes even when T = char. BOOST_AUTO_TEST_CASE_TEMPLATE( test_pow, T, all_test_types ) { if (std::numeric_limits<T>::digits < 32) return; // Invokes undefined behaviour polynomial<T> a(d3a.begin(), d3a.end()); polynomial<T> const one(T(1)); boost::array<double, 7> const d3a_sqr = {{100, -120, -44, 108, -20, -24, 9}}; boost::array<double, 10> const d3a_cub = {{1000, -1800, -120, 2124, -1032, -684, 638, -18, -108, 27}}; polynomial<T> const asqr(d3a_sqr.begin(), d3a_sqr.end()); polynomial<T> const acub(d3a_cub.begin(), d3a_cub.end()); BOOST_CHECK_EQUAL(pow(a, 0), one); BOOST_CHECK_EQUAL(pow(a, 1), a); BOOST_CHECK_EQUAL(pow(a, 2), asqr); BOOST_CHECK_EQUAL(pow(a, 3), acub); BOOST_CHECK_EQUAL(pow(a, 4), pow(asqr, 2)); BOOST_CHECK_EQUAL(pow(a, 5), asqr * acub); BOOST_CHECK_EQUAL(pow(a, 6), pow(acub, 2)); BOOST_CHECK_EQUAL(pow(a, 7), acub * acub * a); BOOST_CHECK_THROW(pow(a, -1), std::domain_error); BOOST_CHECK_EQUAL(pow(one, 137), one); }
explicit FiberControl(Initializer) : state(FS_READY) { AUTO(it, g_stack_pool.begin()); for(;;){ if(it == g_stack_pool.end()){ stack.reset(new StackStorage); break; } if(*it){ stack.swap(*it); break; } ++it; } }
BOOST_AUTO_TEST_CASE_TEMPLATE( copy_algorithm , Stepper , dummy_steppers ) { typedef times_iterator< Stepper , empty_system , state_type , time_iterator_type> stepper_iterator; state_type x = {{ 1.0 }}; std::vector< state_type > res; stepper_iterator first( Stepper() , empty_system() , x , times.begin() , times.end() , 0.1 ); stepper_iterator last( Stepper() , empty_system() , x ); std::copy( first , last , std::back_insert_iterator< std::vector< state_type > >( res ) ); BOOST_CHECK_EQUAL( res.size() , size_t( 4 ) ); BOOST_CHECK_CLOSE( res[0][0] , 1.0 , 1.0e-13 ); BOOST_CHECK_CLOSE( res[1][0] , 1.25 , 1.0e-13 ); BOOST_CHECK_CLOSE( res[2][0] , 1.5 , 1.0e-13 ); BOOST_CHECK_CLOSE( res[3][0] , 1.75 , 1.0e-13 ); BOOST_CHECK_CLOSE( x[0] , 1.75 , 1.0e-13 ); // the iterator should not iterate over the end }
/** @brief Set the dimensions of the image, allocate memory, etc. \param dims Sizes of each non trival dimension (min=1, max=3), supposed in row major order. n[0] varies slower than n[1], itself variing slower that n[3] For a 3D image scanned with x faster than y faster than z, the dimensions must be given in reverse order n[0]=dimz, n[1]=dimy, n[2]=dimx */ void Tracker::setDimensions(const boost::array<size_t,3> &dims) { //allocate main memory block for FFT. // Last dimension has to be padded with extra values to allow real2complex and c2r fft boost::array<size_t,3> paddedDims = dims; paddedDims.back()= 2*(paddedDims.back()/2+1); size_t memsize = 1; memsize = accumulate(paddedDims.begin(),paddedDims.end(),1,multiplies<size_t>()); cout<<"Allocating a block of "<<sizeof(float) * memsize<<" bytes ... "; data = (float*)fftwf_malloc(sizeof(float)* memsize); assert(data); //allocate memory. centersMap.resize(dims); paddedDims.back() = dims.back()/2 + 1; FFTmask.resize(paddedDims); //planning fft. int n[3]; copy(dims.begin(),dims.end(),&(n[0])); forward_plan = fftwf_plan_dft_r2c(dims.size(), &(n[0]), data, (fftwf_complex *)data, flags); //n[2] = 2*(n[2]/2 +1); backward_plan = fftwf_plan_dft_c2r(dims.size(), &(n[0]), (fftwf_complex *)data, data, flags); }
const_iterator end() const { return values.end(); }
iterator end() { return values.end(); }
Bools toBools( boost::array<bool,nb> const & t ) { Bools b; b.insert (b.end(), t.begin(), t.end()); return b; }
typedef std::vector<std::string> Strings; typedef std::vector<Strings> VStrings; typedef std::vector<bool> Bools; typedef std::vector<Bools> VBools; // Name all our paths. We have as many paths as there are trigger // bits. size_t const num_trig_paths = 8; boost::array<char const*, num_trig_paths> cpaths = {{ "ap1", "ap2", "aq1", "aq2", "bp1", "bp2", "bq1", "bq2", }}; Strings trigger_path_names(cpaths.begin(),cpaths.end()); struct PathSpecifiers { Strings path; PathSpecifiers (std::string const & s0, std::string const & s1 = "", std::string const & s2 = "", std::string const & s3 = "", std::string const & s4 = "", std::string const & s5 = "", std::string const & s6 = "", std::string const & s7 = "", std::string const & s8 = "", std::string const & s9 = "" ) : path() {
BOOST_AUTO_TEST_CASE_TEMPLATE( stepper_iterator_factory , Stepper , dummy_steppers ) { std::cout << "factory" << std::endl; Stepper stepper; empty_system system; state_type x = {{ 1.0 }}; std::for_each( make_times_iterator_begin( stepper , boost::ref( system ) , x , times.begin(), times.end() , 0.1 ) , make_times_iterator_end<time_iterator_type>( stepper , boost::ref( system ) , x ) , dummy_observer() ); // dummy_steppers just add 0.25 at each step, the above for_each leads to 3 do_step calls so x should be 1.75 BOOST_CHECK_CLOSE( x[0] , 1.75 , 1.0e-13 ); }