Exemple #1
0
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));
}
Exemple #2
0
 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());
 }
Exemple #3
0
 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());
 }
Exemple #4
0
 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());
 }
Exemple #5
0
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);
}
Exemple #6
0
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);
}
Exemple #7
0
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);
}
Exemple #8
0
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);
}
Exemple #9
0
        void handle_receive(const boost::system::error_code& e,
                std::size_t bytes_transferred) {
            std::cout << "received message: '" << std::string(recv_buffer_.begin(), recv_buffer_.begin() + bytes_transferred) << "'\n";

            // TRYING TO CHECK FOR TRUNCATION, NOT WORKING
            // std::cout << e << std::endl;
            // if (!e || e == boost::asio::error::message_size) {
            //     std::cout << "wat?\n";
            // }

            // restart receive
            start_receive();
        }
Exemple #10
0
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()));
}
Exemple #11
0
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);
}
Exemple #12
0
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);
}
Exemple #13
0
    //--------------------------------------------------------------------------
    //! 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; }
        }

    }
Exemple #14
0
	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);
		}
	}
Exemple #15
0
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> >()));
}
Exemple #16
0
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);
}
Exemple #17
0
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);
}
Exemple #18
0
/** @brief Get a view of the main data array, including padding  */
Tracker::array_type_r Tracker::get_padded_image(const boost::array<size_t,3>& ordering)
{
	boost::array<size_t,3> paddedExt;
	for(size_t d=0;d<3;++d)
		paddedExt[ordering[d]] = (d==2) ? 2*FFTmask.shape()[d] : centersMap.shape()[d];

	bool ascending[] = {true,true,true};
	return array_type_r(data, paddedExt, boost::general_storage_order<3>(ordering.begin(),ascending));
}
Exemple #19
0
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));
}
Exemple #20
0
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( copy_stepper_iterator , Stepper , dummy_steppers )
{
    typedef times_iterator< Stepper , empty_system , state_type , time_iterator_type > iterator_type;
    state_type x = {{ 1.0 }};
    iterator_type iter1 = iterator_type( Stepper() , empty_system() , x , times.begin() , times.end() , 0.1 );
    iterator_type iter2 = iter1;
    BOOST_CHECK_EQUAL( &(*iter1) , &(*iter2) );
    BOOST_CHECK_EQUAL( &(*iter1) , &x );
    BOOST_CHECK( iter1.same( iter2 ) );
}
Exemple #22
0
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);
}
BOOST_AUTO_TEST_CASE_TEMPLATE( stepper_range , Stepper , dummy_steppers )
{
    std::cout << "range" << std::endl;
    Stepper stepper;
    empty_system system;
    state_type x = {{ 1.0 }};

    boost::for_each( make_times_range( stepper , boost::ref( system ) , x , times.begin() , times.end() , 0.1 ) ,
                     dummy_observer() );

    BOOST_CHECK_CLOSE( x[0] , 1.75 , 1.0e-13 );
}
Exemple #24
0
		~FiberControl(){
			AUTO(it, g_stack_pool.begin());
			for(;;){
				if(it == g_stack_pool.end()){
					stack.reset();
					break;
				}
				if(!*it){
					stack.swap(*it);
					break;
				}
				++it;
			}
		}
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 );
}
BOOST_AUTO_TEST_CASE_TEMPLATE( assignment_stepper_iterator , Stepper , dummy_steppers )
{
    std::cout << "assignment" << std::endl;
    typedef times_iterator< Stepper , empty_system , state_type , time_iterator_type> iterator_type;
    state_type x1 = {{ 1.0 }} , x2 = {{ 2.0 }};
    iterator_type iter1 = iterator_type( Stepper() , empty_system() , x1 , times.begin() , times.end() , 0.1 );
    iterator_type iter2 = iterator_type( Stepper() , empty_system() , x2 , times.begin() , times.end() , 0.2 );
    BOOST_CHECK_EQUAL( &(*iter1) , &x1 );
    BOOST_CHECK_EQUAL( &(*iter2) , &x2 );
    BOOST_CHECK( !iter1.same( iter2 ) );
    iter2 = iter1;
    BOOST_CHECK_EQUAL( &(*iter1) , &x1 );
    BOOST_CHECK_EQUAL( &(*iter2) , &x1 );
    BOOST_CHECK( iter1.same( iter2 ) );
}
BOOST_AUTO_TEST_CASE_TEMPLATE( copy_algorithm_with_range_factory , Stepper , dummy_steppers )
{
    state_type x = {{ 1.0 }};
    std::vector< state_type > res;
    boost::range::copy( make_times_range( Stepper() , empty_system() , x , times.begin() , times.end() , 0.1 ) ,
                        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 );
}
Exemple #28
0
// 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);
}
Exemple #29
0
		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;
			}
		}
Exemple #30
0
    sAudioReceiver(boost::asio::io_service& io_service, sAudioBuffer* audiobuf, char* host, int port) : audiobuf(audiobuf), socket(io_service), ping_interval(boost::posix_time::seconds(1)) {
        printf("Creating sAudioReceiver on %s:%d\n", host, port);
        socket.open(boost::asio::ip::udp::v4());

        receiver_endpoint = boost::asio::ip::udp::endpoint(boost::asio::ip::address::from_string(host), port);


        std::string thx("ihazo");
        std::copy(thx.begin(), thx.end(), send_arr.begin());
        printf("Created sAudioReceiver\n");
        send_request();
        start_receive();
        printf("Sent request\n");

        ping_timer = new boost::asio::deadline_timer(socket.get_io_service(), ping_interval);
        start_timer();
    }