コード例 #1
0
ファイル: test1.c プロジェクト: jkkm/latrace
int main(void)
{
	static const struct st3 a = {1, 2, 3, 4, 5, 6};

	l1(100);
	l2(100, 200);
	l3(100, 200, 300);
	l4(100, 200, 300, 400);
	l5(100, 200, 300, 400, 500);
	l6(100, 200, 300, 400, 500, 600);
	l7(100, 200, 300, 400, 500, 600, 700);
	l8(100, 200, 300, 400, 500, 600, 700, 800);

	d1();
	d2(43);
	d3(100, 200);
	d4(a);
	d5('a', 43, a);
	d6('a', 1);

	c1(44);
	c2(100, 'a', 3.4);
	c3(200, 2.777, 'q');
	c4(200, 1);
	c5(1.1, 2.2);
	c6(1.23, 45.6);
	c7('z', 0x200);

	a1('a');
	a2(10);
	a3(20);
	a4(102030405060LL);

	b1('a', 20);
	b2(30, 'b');
	b3(10, 20, 30, 40, 50, 60);

	s1(sx);
	s1p(&sx);
	s2(sy);
	s3(sz);
	s4(sq);
	s5(sa);
	s6(sb);

	r1();
	r3();
	r4();

	q1(200, sx);
	q2(300, 't', sx);
	q3(400, 410, sy);
	q4(500, 510, sq);
	q5(600, 610, 'z', 'q', sq);

	real1("fresh air");
	real2();

	return 0;
}
コード例 #2
0
    void ordering()
    {
        Category c1 (AUDIO);
        Category c2 (VIDEO);
        Category c3 (EFFECT);
        Category c4 (CODEC);
        Category c5 (STRUCT);
        Category c6 (META);

        CHECK (0 > c1.compare(c2));
        CHECK (0 > c2.compare(c3));
        CHECK (0 > c3.compare(c4));
        CHECK (0 > c4.compare(c5));
        CHECK (0 > c5.compare(c6));

        CHECK (0 ==c1.compare(c1));
        CHECK (0 > c1.compare(c6));

        Category c21 (VIDEO,"bin1");
        Category c22 (VIDEO,"bin2");
        Category c23 (VIDEO,"bin2/sub");

        CHECK (0 > c1.compare(c21));
        CHECK (0 > c2.compare(c21));
        CHECK (0 < c22.compare(c21));
        CHECK (0 < c23.compare(c22));
        CHECK (0 < c23.compare(c21));
        CHECK ( 0==c22.compare(c22));


        CHECK ( c2 == c2 );
        CHECK ( c2 != c22 );
        CHECK ( c2 != c3 );
    }
コード例 #3
0
ファイル: Counter_Test.cpp プロジェクト: binghuo365/BaseLab
static void  TestCounter()
{
#if !defined (ACE_WIN32)
   long l = LONG_MAX, nl = LONG_MIN;  // limits.h
   unsigned long ul = ULONG_MAX, def = 0;
   int i = INT_MAX, ni = INT_MIN;
   unsigned int ui = UINT_MAX;
   unsigned short us = 10;
   short si = static_cast<short> (65535);

   // constructors
   Counter32 c1;
   ACE_ASSERT(c1 == def);
   Counter32 c2(l);
   ACE_ASSERT(c2 == static_cast<unsigned long> (l));
   Counter32 c3(nl);
   ACE_ASSERT(c3 == static_cast<unsigned long> (nl));
   Counter32 c4(ul);
   ACE_ASSERT(c4 == ul);
   Counter32 c5(i);
   ACE_ASSERT(c5 == static_cast<unsigned long> (i));
   Counter32 c6(ni);
   ACE_ASSERT(c6 == static_cast<unsigned long> (ni));
   Counter32 c7(ui);
   ACE_ASSERT(c7 == ui);
   Counter32 *c8 = new Counter32(c5);
   ACE_ASSERT(c8 != 0);
   delete c8;

  ACE_DEBUG ((LM_DEBUG, "(%P|%t) c1(\"\") [%u]\n",
    (unsigned long)c1));
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) c2(\"%u\") [%u]\n",
    l, (unsigned long)c2));
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) c3(\"%u\") [%u]\n",
    nl, (unsigned long)c3));
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) c4(\"%u\") [%u]\n",
    ul, (unsigned long)c4));
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) c5(\"%u\") [%u]\n",
    i, (unsigned long)c5));
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) c6(\"%u\") [%u]\n",
    ni, (unsigned long)c6));
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) c7(\"%u\") [%u]\n",
    ui, (unsigned long)c7));

  // assignent
  c1 = c2;  // obj
  ACE_ASSERT(c1 == c2);
  c1 = c1; // self
  ACE_ASSERT(c1 == c1);
  c1 = def; // unsigned long
  ACE_ASSERT(c1 == def);
  c1 = us; // unsigned short
  ACE_ASSERT(c1 == static_cast<unsigned long> (us));
  c1 = si; // unsigned short
  ACE_ASSERT(c1 == static_cast<unsigned long> (si));
#endif /*ACE_WIN32*/
}
コード例 #4
0
hMatrix Jacobian_hMatrix(double *theta, double *alpha, double *a, double *d) {
	hMatrix T01(4,4), T02(4,4), T03(4,4), T04(4,4), T05(4,4), T06(4,4), T07(4,4);	
	T01 = T_hMatrix(&theta[0], &alpha[0], &a[0], &d[0], 1);
	T02 = T_hMatrix(&theta[0], &alpha[0], &a[0], &d[0], 2);
	T03 = T_hMatrix(&theta[0], &alpha[0], &a[0], &d[0], 3);
	T04 = T_hMatrix(&theta[0], &alpha[0], &a[0], &d[0], 4);
	T05 = T_hMatrix(&theta[0], &alpha[0], &a[0], &d[0], 5);
	T06 = T_hMatrix(&theta[0], &alpha[0], &a[0], &d[0], 6);
	T07 = T_hMatrix(&theta[0], &alpha[0], &a[0], &d[0], 7);

	double k[3] = {0,0,1};
	double z1[3] = { T01.element(0,2),T01.element(1,2), T01.element(2,2)};
	double z2[3] = { T02.element(0,2),T02.element(1,2), T02.element(2,2)};
	double z3[3] = { T03.element(0,2),T03.element(1,2), T03.element(2,2)};
	double z4[3] = { T04.element(0,2),T04.element(1,2), T04.element(2,2)};
	double z5[3] = { T05.element(0,2),T05.element(1,2), T05.element(2,2)};
	double z6[3] = { T06.element(0,2),T06.element(1,2), T06.element(2,2)};

	double o1[3] = {T01.element(0,3), T01.element(1,3), T01.element(2,3)};
	double o2[3] = {T02.element(0,3), T02.element(1,3), T02.element(2,3)};
	double o3[3] = {T03.element(0,3), T03.element(1,3), T03.element(2,3)};
	double o4[3] = {T04.element(0,3), T04.element(1,3), T04.element(2,3)};
	double o5[3] = {T05.element(0,3), T05.element(1,3), T05.element(2,3)};
	double o6[3] = {T06.element(0,3), T06.element(1,3), T06.element(2,3)};
	double o7[3] = {T07.element(0,3), T07.element(1,3), T07.element(2,3)};
 
	double O1[3] ={o7[0],o7[1],o7[2]};
	double O2[3] ={o7[0]-o1[0],o7[1]-o1[1],o7[2]-o1[2]};
	double O3[3] ={o7[0]-o2[0],o7[1]-o2[1],o7[2]-o2[2]};
	double O4[3] ={o7[0]-o3[0],o7[1]-o3[1],o7[2]-o3[2]};
	double O5[3] ={o7[0]-o4[0],o7[1]-o4[1],o7[2]-o4[2]};
	double O6[3] ={o7[0]-o5[0],o7[1]-o5[1],o7[2]-o5[2]};
	double O7[3] ={o7[0]-o6[0],o7[1]-o6[1],o7[2]-o6[2]};
	
	hMatrix c1(1,3),c2(1,3),c3(1,3),c4(1,3),c5(1,3),c6(1,3),c7(1,3);
	c1 =  cross(&k[0],&O1[0]);
	c2 =  cross(&z1[0],&O2[0]);
	c3 =  cross(&z2[0],&O3[0]);
	c4 =  cross(&z3[0],&O4[0]);
	c5 =  cross(&z4[0],&O5[0]);
	c6 =  cross(&z5[0],&O6[0]);
	c7 =  cross(&z6[0],&O7[0]);

	double J[42] = { c1.element(0,0), c2.element(0,0), c3.element(0,0), c4.element(0,0), c5.element(0,0), c6.element(0,0), c7.element(0,0),
					c1.element(0,1), c2.element(0,1), c3.element(0,1), c4.element(0,1), c5.element(0,1), c6.element(0,1), c7.element(0,1),
					c1.element(0,2), c2.element(0,2), c3.element(0,2), c4.element(0,2), c5.element(0,2), c6.element(0,2), c7.element(0,2),
					k[0],z1[0],z2[0],z3[0],z4[0],z5[0],z6[0],
					k[1],z1[1],z2[1],z3[1],z4[1],z5[1],z6[1],
					k[2],z1[2],z2[2],z3[2],z4[2],z5[2],z6[2]};
	hMatrix Jacobian(6,7);
	Jacobian.SET(6,7,&J[0]);
	return Jacobian;
}
コード例 #5
0
ファイル: test_conic_polycurve.cpp プロジェクト: 2php/cgal
void check_split(Curve_type &xcv1, Curve_type &xcv2)
{
  Polycurve_conic_traits_2 traits;

  //split x poly-curves

  Conic_curve_2 c6(1,1,0,6,-26,162,CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(-7), Algebraic(13)),
                   Conic_point_2(Algebraic(-3), Algebraic(9)));
  Conic_curve_2 c7(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(-3), Algebraic(9)),
                   Conic_point_2(Algebraic(0), Algebraic(0)));
  Conic_curve_2 c8(0,1,0,-1,0,0, CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(0), Algebraic(0)),
                   Conic_point_2(Algebraic(4), Algebraic(-2)));

  Conic_x_monotone_curve_2 xc6(c6);
  Conic_x_monotone_curve_2 xc7(c7);
  Conic_x_monotone_curve_2 xc8(c8);
  std::vector<Conic_x_monotone_curve_2> xmono_conic_curves_2;

  xmono_conic_curves_2.push_back(xc6);
  xmono_conic_curves_2.push_back(xc7);
  Pc_x_monotone_curve_2 split_expected_1 =
    traits.construct_x_monotone_curve_2_object()(xmono_conic_curves_2.begin(),
                                                 xmono_conic_curves_2.end());

  xmono_conic_curves_2.clear();
  xmono_conic_curves_2.push_back(xc8);
  Pc_x_monotone_curve_2 split_expected_2 =
    traits.construct_x_monotone_curve_2_object()(xmono_conic_curves_2.begin(),
                                                 xmono_conic_curves_2.end());


  Polycurve_conic_traits_2::X_monotone_curve_2 split_curve_1, split_curve_2;
  Polycurve_conic_traits_2::Point_2
    point_of_split = Polycurve_conic_traits_2::Point_2(0,0);

  //Split functor
  traits.split_2_object()(xcv2, point_of_split, split_curve_1, split_curve_2);

  bool split_1_chk = traits.equal_2_object()(split_curve_1, split_expected_1);
  bool split_2_chk = traits.equal_2_object()(split_curve_2, split_expected_2);

  if(split_1_chk && split_2_chk)
    std::cout << "Split is working fine" << std::endl;
  else
    std::cout << "Something is wrong with split" << std::endl;
}
コード例 #6
0
ファイル: cp_main.cpp プロジェクト: hegek87/cpp_complex_poly
int main(void){
	std::cout << "HI" << std::endl;
	Complex c1(1,2), c2(3,1), c3(4,2), c4(2,2);
	std::vector<Complex> coeff;
	coeff.push_back(c1); coeff.push_back(c2); coeff.push_back(c3);
	ComplexPoly poly(coeff, 2);
	Complex res = poly.evaluate(c4);
	std::cout << res << std::endl;
	
	Complex c5(2,3), c6(3,4), c7(8,2);
	Complex data[3] = {c5,c6,c7};
	ComplexPoly cp(data, 2);
	Complex result = cp.evaluate(c4);
	std::cout << result << std::endl;
	std::cout << cp << std::endl;
	return 0;
}
コード例 #7
0
ファイル: list_cmy.cpp プロジェクト: dmilos/color
int main( int argc, char *argv[] )
 {
  ::color::cmy<std::uint8_t>     c1( { 64, 127 , 192 } );
  ::color::cmy<std::uint16_t>    c2( { 280, 350 , 1000 } );
  ::color::cmy<std::uint32_t>    c3( { 640, 127 , 192 } );
  ::color::cmy<std::uint64_t>    c4( { 64000, 1270 , 1920 } );
  ::color::cmy<float>            c5( { 0.5, 0.6, 0.7} );
  ::color::cmy<double>           c6( { 0.5, 0.6, 0.7} );

  std::cout << c1[0] << ", " << c1[1] << ", " << c1[2] << std::endl;
  std::cout << c2[0] << ", " << c2[1] << ", " << c2[2] << std::endl;
  std::cout << c3[0] << ", " << c3[1] << ", " << c3[2] << std::endl;
  std::cout << c4[0] << ", " << c4[1] << ", " << c4[2] << std::endl;
  std::cout << c5[0] << ", " << c5[1] << ", " << c5[2] << std::endl;
  std::cout << c6[0] << ", " << c6[1] << ", " << c6[2] << std::endl;

  return EXIT_SUCCESS;
 }
コード例 #8
0
ファイル: list_rgb.cpp プロジェクト: dmilos/color
int main( int argc, char *argv[] )
 {
  ::color::rgb<::color::type::split422_t>   c1( { 7, 6 , 3} );
  ::color::rgb<::color::type::split655_t >  c2( { 6, 12 , 19} );
  ::color::rgb<std::uint8_t>                c3( { 64, 127 , 192 } );
  ::color::rgb<std::uint64_t>               c4( { 64000, 1270 , 1920 } );
  ::color::rgb<float>                       c5( { 0.5, 0.6, 0.7} );
  ::color::rgb<double>                      c6( { 0.5, 0.6, 0.7} );

  std::cout << c1[0] << ", " << c1[1] << ", " << c1[2] << std::endl;
  std::cout << c2[0] << ", " << c2[1] << ", " << c2[2] << std::endl;
  std::cout << c3[0] << ", " << c3[1] << ", " << c3[2] << std::endl;
  std::cout << c4[0] << ", " << c4[1] << ", " << c4[2] << std::endl;
  std::cout << c5[0] << ", " << c5[1] << ", " << c5[2] << std::endl;
  std::cout << c6[0] << ", " << c6[1] << ", " << c6[2] << std::endl;

  return EXIT_SUCCESS;
 }
コード例 #9
0
ファイル: Main.cpp プロジェクト: bseznec/TP4INFO
/**
* \fn main
* \brief fonction main permettant de creer les chaines et de tester les fonctions
*
*/
int main (int agc, char* argv[]){
	printf("Debut de la fonction main\n");

	// Creation de tableaux de caractères

	char test[] = "test test";
	char test2[] = "test";
	char test3[] = "ananas";
	char test4[] = "hello world";
	char c = 's';

	// creation de chaines de caractères avec les différents constructeurs
	Chaine c1;
	Chaine c2(test);
	Chaine c3(c2);
	Chaine c4(test2);
	Chaine c5(test3);
	Chaine c6(test4);

	// test des fonctions de chaine.cpp
	c1.afficherChaine(); // empty chaine
	c2.afficherChaine(); // "test test"
	c3.afficherChaine(); // test test"
	cout << (c1 == c3) <<endl;  // false
	cout << (c2 == c3) <<endl;  // true 
	cout << (c4 == c3) <<endl;  // false
	cout << (c4 > c5) <<endl;   // true
	cout << (c4 < c5) <<endl;   // false
	cout << (c5 < c4) <<endl;   // true

	(c4+c5).afficherChaine(); // "testananas"
	(c2 += c5).afficherChaine(); // c2 : "test testananas"
	c2.afficherChaine(); // "test testananas"

	cout << "Indexe du caractere s dans la chaine ";
	c5.afficherChaine();  // "ananas"
	cout << " : " ;
	cout << c5.index_char(c) <<endl; // the first occurence of s is at the position 6

	c6.sous_chaine(6,10).afficherChaine(); // "word"

	printf("fin du main\n");

}
コード例 #10
0
void renderPolygons(void) {
	// set clearing color 
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	// first polygon - triangle - yellow
	Point c1(100,50,0);
	Color fc1(1.0, 1.0, 0.0, 0.0);
	Polygon tri(40, c1, 3, 1, GL_LINE_LOOP, fc1);
	tri.draw();

	// square - hollow - light blue(cyan)
	Point c2(100,150,0);
	Color fc2(0.0, 1.0, 1.0, 0.0);
	Polygon squ(40, c2, 4, 8, GL_LINE_LOOP, fc2);
	squ.draw();

	// pentagon - hollow - gray
	Point c3(100,250,0);
	Color fc3(0.5, 0.5, 0.5, 0.0);
	Polygon pent(40, c3, 5, 3, GL_LINE_LOOP, fc3);
	pent.draw();

	//hexagon - not hollow - red
	Point c4(200,50,0);
	Color fc4(1.0, 0.0, 0.0, 0.0);
	Polygon hex(40, c4, 6, 3, GL_POLYGON, fc4);
	hex.draw();

	// nonagon - hollow - green
	Point c5(200,150,0);
	Color fc5(0.0, 1.0, 0.0, 0.0);
	Polygon nin(40, c5, 9, 5, GL_LINE_LOOP, fc5);
	nin.draw();

	// tridecagon - hollow - purple
	Point c6(300,300,0);
	Color fc6(1.0, 0.0, 1.0, 0.0);
	Polygon thri(90, c6, 13, 3, GL_LINE_LOOP, fc6);
	thri.draw();

	glutSwapBuffers();
}
コード例 #11
0
ファイル: list_gray.cpp プロジェクト: dmilos/color
int main( int argc, char *argv[] )
 {
  color::gray<bool>           c0( { true } );
  color::gray<std::uint8_t>   c1( { 120 } );
  color::gray<std::uint16_t>  c2( { 6 } );
  color::gray<std::uint32_t>  c3( { 64000} );
  color::gray<std::uint64_t>  c4( { 6400000u } );
  color::gray<float>          c5( { 0.5 }  );
  color::gray<double>         c6( { 0.5 }  );
  color::gray<long double>    c7( { 0.5 }  );

  std::cout << c1[0] << std::endl;
  std::cout << c2[0] << std::endl;
  std::cout << c3[0] << std::endl;
  std::cout << c4[0] << std::endl;
  std::cout << c5[0] << std::endl;
  std::cout << c6[0] << std::endl;

  return EXIT_SUCCESS;
 }
コード例 #12
0
ファイル: test02.cpp プロジェクト: een5afr-public/gem5
int
sc_main( int, char*[] )
{
    sc_time t1( 8, SC_NS );
    sc_time t2( 2, SC_NS );


    sc_clock c1( "c1", t1, 0.1, t2 );
    cout <<  "m_cur_val for c1( \"c1\", t1, 0.1, t2 ) is: ";
    c1.print(cout);
    cout << "\n";

    sc_clock c2( "c2", t1, 0.1, t2, false );
    cout <<  "m_cur_val for c2( \"c2\", t1, 0.1, t2, false ) is: ";
    c2.print(cout);
    cout << "\n";


    sc_clock c3( "c3", 8, SC_NS, 0.1 );
    cout <<  "m_cur_val for c3( \"c3\", t1, 0.1, t2 ) is: ";
    c3.print(cout);
    cout << "\n";

    sc_clock c4( "c4", 8, SC_NS, 0.1, false );
    cout <<  "m_cur_val for c4( \"c4\", t1, 0.1, t2, false ) is: ";
    c4.print(cout);
    cout << "\n";

    sc_clock c5( "c5", 8, SC_NS, 0.1, 2, SC_NS );
    cout <<  "m_cur_val for c5( \"c5\", t1, 0.1, t2 ) is: ";
    c5.print(cout);
    cout<< "\n";

    sc_clock c6( "c6", 8, SC_NS, 0.1, 2, SC_NS, false );
    cout <<  "m_cur_val for c6( \"c6\", t1, 0.1, t2, false ) is: ";
    c6.print(cout);
    cout<< "\n";

    return 0;
}
コード例 #13
0
ファイル: HUD.cpp プロジェクト: conorrussomanno/ROB3115
void HUD::setup(){
    
    //Colors for HUDSpinners below
    ofColor c(36,96,150);
    ofColor c2(36,180,150);
    ofColor c3(93,5,255);
    ofColor c4(254,173,69);
    ofColor c5(5,209,245);
    ofColor c6(40,240,60);
    
    spinner1.setup(10 /*count*/, 200.0 /*avgRotSpd*/, 100 /*rotVariation*/, c /*color*/, 30 /*resolution*/, 20 /*minRad*/, 55 /*maxRad*/, 15 /*minWidth*/, 30 /*maxWidth*/);
    spinner2.setup(10 /*count*/, 150 /*avgRotSpd*/, 50 /*rotVariation*/, c2 /*color*/, 40 /*resolution*/, 15 /*minRad*/, 55 /*maxRad*/, 10 /*minWidth*/, 20 /*maxWidth*/);
    spinner3.setup(15 /*count*/, 150 /*avgRotSpd*/, 140 /*rotVariation*/, c3 /*color*/, 40 /*resolution*/, 20 /*minRad*/, 55 /*maxRad*/, 10 /*minWidth*/, 20 /*maxWidth*/);
    spinner4.setup(15 /*count*/, 150 /*avgRotSpd*/, 140 /*rotVariation*/, c4 /*color*/, 40 /*resolution*/, 30 /*minRad*/, 55 /*maxRad*/, 10 /*minWidth*/, 20 /*maxWidth*/);
    spinner5.setup(20 /*count*/, 150 /*avgRotSpd*/, 140 /*rotVariation*/, c5 /*color*/, 40 /*resolution*/, 20 /*minRad*/, 80 /*maxRad*/, 10 /*minWidth*/, 20 /*maxWidth*/);
    spinner6.setup(15 /*count*/, -150 /*avgRotSpd*/, 100 /*rotVariation*/, c6 /*color*/, 40 /*resolution*/, 30 /*minRad*/, 200 /*maxRad*/, 20 /*minWidth*/, 100 /*maxWidth*/);
    
    HUDimg.loadImage("HUD3.png");
    
    singleBlink = false;
    doubleBlink = false;

}
コード例 #14
0
ファイル: test_labymap.cpp プロジェクト: jleung51/labyrinth
int main()
{
  std::cout << std::endl
            << "TESTING LABYRINTH_MAP.CPP IMPLEMENTATION" << std::endl
            << "________________________________________________" << std::endl
            << std::endl;


  const unsigned int l1_xsize = 3;
  const unsigned int l1_ysize = 2;

  std::cout << "Creating a basic, empty Labyrinth with:" << std::endl
            << "  x size = " << l1_xsize << std::endl
            << "  y size = " << l1_ysize << std::endl;

  Labyrinth l1( l1_xsize, l1_ysize );
  std::cout << "Completed." << std::endl;
  std::cout << std::endl;

  std::cout << "________________________________________________"
            << std::endl
            << std::endl;

  std::cout << "Creating and displaying a Map from the Labyrinth:" << std::endl;
  LabyrinthMap l1_map( &l1, l1_xsize, l1_ysize );
  std::cout << "Creation completed." << std::endl << std::endl;
  try
  {
    l1_map.Display();
  }
  catch( const std::exception& e )
  {
    std::cout << e.what();
  }
  std::cout << "Display completed." << std::endl;
  std::cout << std::endl;

  std::cout << "________________________________________________"
            << std::endl
            << std::endl;

  std::cout << "Setting the Labyrinth to be a snake from the top left "
            << "to the bottom right." << std::endl;
  Coordinate c1(0, 0);
  Coordinate c2(0, 1);
  Coordinate c3(1, 1);
  Coordinate c4(1, 0);
  Coordinate c5(2, 0);
  Coordinate c6(2, 1);
  try
  {
    l1.ConnectRooms( c1, c2 );
    l1.ConnectRooms( c2, c3 );
    l1.ConnectRooms( c3, c4 );
    l1.ConnectRooms( c4, c5 );
    l1.ConnectRooms( c5, c6 );
  }
  catch( const std::exception& e )
  {
    std::cout << e.what();
  }
  std::cout << "Completed." << std::endl;
  std::cout << std::endl;


  std::cout << "Displaying the Map of the Labyrinth:" << std::endl << std::endl;
  try
  {
    l1_map.Display();
  }
  catch( const std::exception& e )
  {
    std::cout << e.what();
  }
  std::cout << "Completed." << std::endl;
  std::cout << std::endl;


  std::cout << "________________________________________________"
            << std::endl
            << std::endl;

  std::cout << "Setting the following items and inhabitants:" << std::endl;
  std::cout << "  Top left Coordinate has a Minotaur (live) and a bullet"
            << std::endl
            << "  Bottom left Coordinate has a Minotaur (dead)"
            << std::endl
            << "  Bottom center Coordinate has a Treasure"
            << std::endl
            << "  Top right Coordinate has a mirror (intact)"
            << std::endl
            << "  Bottom right Coordinate has a mirror (cracked)"
            << std::endl;

  try
  {
    l1.SetInhabitant( c1, Inhabitant::kMinotaur );
    l1.SetInhabitant( c2, Inhabitant::kMinotaurDead );
    l1.SetInhabitant( c5, Inhabitant::kMirror );
    l1.SetInhabitant( c6, Inhabitant::kMirrorCracked );

    l1.SetItem( c1, Item::kBullet );
    l1.SetItem( c3, Item::kTreasure );
  }
  catch( const std::exception& e )
  {
    std::cout << e.what();
  }
  std::cout << "Completed." << std::endl;

  std::cout << "Displaying the Map of the Labyrinth:" << std::endl << std::endl;
  try
  {
    l1_map.Display();
  }
  catch( const std::exception& e )
  {
    std::cout << e.what();
  }
  std::cout << "Completed." << std::endl;
  std::cout << std::endl;



  std::cout << "________________________________________________" << std::endl;
  std::cout << std::endl;
  std::cout << "All tests completed." << std::endl;
  std::cout << std::endl;
  std::cout << "Press enter to exit.";
  getchar();
  std::cout << std::endl;

  return 0;
}
コード例 #15
0
ファイル: test_kdtree.cpp プロジェクト: AjinkyaDahale/FreeCAD
int main()
{
   // check that it'll find nodes exactly MAX away
   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 4, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target,2);
      assert(found.first != exact_dist.end());
      assert(found.second == 2);
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << std::endl;
   }

   // do the same test, except use alternate_triplet as the search key
   {
      // NOTE: stores triplet, but we search with alternate_triplet
      typedef KDTree::KDTree<3, triplet, alternate_tac> alt_tree;

      triplet actual_target(7,0,0);

      alt_tree tree;
      tree.insert( triplet(0, 0, 7) );
      tree.insert( triplet(0, 0, 7) );
      tree.insert( triplet(0, 0, 7) );
      tree.insert( triplet(3, 0, 0) );
      tree.insert( actual_target );
      tree.optimise();

      alternate_triplet target( actual_target );

      std::pair<alt_tree::const_iterator,double> found = tree.find_nearest(target);
      assert(found.first != tree.end());
      std::cout << "Test with alternate search type, found: " << *found.first << ", wanted " << actual_target << std::endl;
      assert(found.second == 0);
      assert(*found.first == actual_target);
   }


   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 2, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

        // call find_nearest without a range value - it found a compile error earlier.
      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target);
      assert(found.first != exact_dist.end());
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << " @ " << found.second << " should be " << std::sqrt(8) << std::endl;
      assert(found.second == std::sqrt(8));
   }

   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 2, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target,std::sqrt(8));
      assert(found.first != exact_dist.end());
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << " @ " << found.second << " should be " << std::sqrt(8) << std::endl;
      assert(found.second == std::sqrt(8));
   }

  tree_type src(std::ptr_fun(tac));

  triplet c0(5, 4, 0); src.insert(c0);
  triplet c1(4, 2, 1); src.insert(c1);
  triplet c2(7, 6, 9); src.insert(c2);
  triplet c3(2, 2, 1); src.insert(c3);
  triplet c4(8, 0, 5); src.insert(c4);
  triplet c5(5, 7, 0); src.insert(c5);
  triplet c6(3, 3, 8); src.insert(c6);
  triplet c7(9, 7, 3); src.insert(c7);
  triplet c8(2, 2, 6); src.insert(c8);
  triplet c9(2, 0, 6); src.insert(c9);

  std::cout << src << std::endl;

  src.erase(c0);
  src.erase(c1);
  src.erase(c3);
  src.erase(c5);

  src.optimise();


  // test the efficient_replace_and_optimise()
  tree_type eff_repl = src;
  {
     std::vector<triplet> vec;
     // erased above as part of test vec.push_back(triplet(5, 4, 0));
     // erased above as part of test vec.push_back(triplet(4, 2, 1));
     vec.push_back(triplet(7, 6, 9));
     // erased above as part of test vec.push_back(triplet(2, 2, 1));
     vec.push_back(triplet(8, 0, 5));
     // erased above as part of test vec.push_back(triplet(5, 7, 0));
     vec.push_back(triplet(3, 3, 8));
     vec.push_back(triplet(9, 7, 3));
     vec.push_back(triplet(2, 2, 6));
     vec.push_back(triplet(2, 0, 6));

     eff_repl.clear();
     eff_repl.efficient_replace_and_optimise(vec);
  }


  std::cout << std::endl << src << std::endl;

  tree_type copied(src);
  std::cout << copied << std::endl;
  tree_type assigned;
  assigned = src;
  std::cout << assigned << std::endl;

  for (int loop = 0; loop != 4; ++loop)
    {
      tree_type * target;
      switch (loop)
	{
	case 0: std::cout << "Testing plain construction" << std::endl;
	  target = &src;
	  break;

	case 1: std::cout << "Testing copy-construction" << std::endl;
	  target = &copied;
	  break;

	case 2: std::cout << "Testing assign-construction" << std::endl;
	  target = &assigned;
	  break;

   default:
	case 4: std::cout << "Testing efficient-replace-and-optimise" << std::endl;
	  target = &eff_repl;
	  break;
	}
      tree_type & t = *target;

      int i=0;
      for (tree_type::const_iterator iter=t.begin(); iter!=t.end(); ++iter, ++i);
      std::cout << "iterator walked through " << i << " nodes in total" << std::endl;
      if (i!=6)
	{
	  std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
	  return 1;
	}
      i=0;
      for (tree_type::const_reverse_iterator iter=t.rbegin(); iter!=t.rend(); ++iter, ++i);
      std::cout << "reverse_iterator walked through " << i << " nodes in total" << std::endl;
      if (i!=6)
	{
	  std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
	  return 1;
	}

      triplet s(5, 4, 3);
      std::vector<triplet> v;
      unsigned int const RANGE = 3;

      size_t count = t.count_within_range(s, RANGE);
      std::cout << "counted " << count
		<< " nodes within range " << RANGE << " of " << s << ".\n";
      t.find_within_range(s, RANGE, std::back_inserter(v));

      std::cout << "found   " << v.size() << " nodes within range " << RANGE
		<< " of " << s << ":\n";
      std::vector<triplet>::const_iterator ci = v.begin();
      for (; ci != v.end(); ++ci)
	std::cout << *ci << " ";
      std::cout << "\n" << std::endl;

      std::cout << std::endl << t << std::endl;

      // search for all the nodes at exactly 0 dist away
      for (tree_type::const_iterator target = t.begin(); target != t.end(); ++target)
      {
         std::pair<tree_type::const_iterator,double> found = t.find_nearest(*target,0);
         assert(found.first != t.end());
         assert(*found.first == *target);
         std::cout << "Test find_nearest(), found at exact distance away from " << *target << ", found " << *found.first << std::endl;
      }

      {
         const double small_dist = 0.0001;
         std::pair<tree_type::const_iterator,double> notfound = t.find_nearest(s,small_dist);
         std::cout << "Test find_nearest(), nearest to " << s << " within " << small_dist << " should not be found" << std::endl;

         if (notfound.first != t.end())
         {
            std::cout << "ERROR found a node at dist " << notfound.second << " : " << *notfound.first << std::endl;
            std::cout << "Actual distance = " << s.distance_to(*notfound.first) << std::endl;
         }

         assert(notfound.first == t.end());
      }

      {
         std::pair<tree_type::const_iterator,double> nif = t.find_nearest_if(s,std::numeric_limits<double>::max(),Predicate());
         std::cout << "Test find_nearest_if(), nearest to " << s << " @ " << nif.second << ": " << *nif.first << std::endl;

         std::pair<tree_type::const_iterator,double> cantfind = t.find_nearest_if(s,std::numeric_limits<double>::max(),FalsePredicate());
         std::cout << "Test find_nearest_if(), nearest to " << s << " should never be found (predicate too strong)" << std::endl;
         assert(cantfind.first == t.end());
      }




      {
      std::pair<tree_type::const_iterator,double> found = t.find_nearest(s,std::numeric_limits<double>::max());
      std::cout << "Nearest to " << s << " @ " << found.second << " " << *found.first << std::endl;
      std::cout << "Should be " << found.first->distance_to(s) << std::endl;
      // NOTE: the assert does not check for an exact match, as it is not exact when -O2 or -O3 is
      // switched on.  Some sort of optimisation makes the math inexact.
      assert( fabs(found.second - found.first->distance_to(s)) < std::numeric_limits<double>::epsilon() );
      }

      {
      triplet s2(10, 10, 2);
      std::pair<tree_type::const_iterator,double> found = t.find_nearest(s2,std::numeric_limits<double>::max());
      std::cout << "Nearest to " << s2 << " @ " << found.second << " " << *found.first << std::endl;
      std::cout << "Should be " << found.first->distance_to(s2) << std::endl;
      // NOTE: the assert does not check for an exact match, as it is not exact when -O2 or -O3 is
      // switched on.  Some sort of optimisation makes the math inexact.
      assert( fabs(found.second - found.first->distance_to(s2)) < std::numeric_limits<double>::epsilon() );
      }

      std::cout << std::endl;

      std::cout << t << std::endl;

      // Testing iterators
      {
	std::cout << "Testing iterators" << std::endl;

	t.erase(c2);
	t.erase(c4);
	t.erase(c6);
	t.erase(c7);
	t.erase(c8);
	//    t.erase(c9);

	std::cout << std::endl << t << std::endl;

	std::cout << "Forward iterator test..." << std::endl;
	std::vector<triplet> forwards;
	for (tree_type::iterator i = t.begin(); i != t.end(); ++i)
	  { std::cout << *i << " " << std::flush; forwards.push_back(*i); }
	std::cout << std::endl;
	std::cout << "Reverse iterator test..." << std::endl;
	std::vector<triplet> backwards;
	for (tree_type::reverse_iterator i = t.rbegin(); i != t.rend(); ++i)
	  { std::cout << *i << " " << std::flush; backwards.push_back(*i); }
	std::cout << std::endl;
	std::reverse(backwards.begin(),backwards.end());
	assert(backwards == forwards);
      }
    }


  // Walter reported that the find_within_range() wasn't giving results that were within
  // the specified range... this is the test.
  {
     tree_type tree(std::ptr_fun(tac));
     tree.insert( triplet(28.771200,16.921600,-2.665970) );
     tree.insert( triplet(28.553101,18.649700,-2.155560) );
     tree.insert( triplet(28.107500,20.341400,-1.188940) );
     tree.optimise();

     std::deque< triplet > vectors;
     triplet sv(18.892500,20.341400,-1.188940);
     tree.find_within_range(sv, 10.0f, std::back_inserter(vectors));

     std::cout << std::endl << "Test find_with_range( " << sv << ", 10.0f) found " << vectors.size() << " candidates." << std::endl;

     // double-check the ranges
     for (std::deque<triplet>::iterator v = vectors.begin(); v != vectors.end(); ++v)
     {
        double dist = sv.distance_to(*v);
        std::cout << "  " << *v << " dist=" << dist << std::endl;
        if (dist > 10.0f)
           std::cout << "    This point is too far! But that is by design, its within a 'box' with a 'radius' of 10, not a sphere with a radius of 10" << std::endl;
        // Not a valid test, it can be greater than 10 if the point is in the corners of the box.
        // assert(dist <= 10.0f);
     }
  }


  return 0;
}
コード例 #16
0
ファイル: test_conic_polycurve.cpp プロジェクト: 2php/cgal
int main(int argc, char* argv[])
{
  Polycurve_conic_traits_2 traits;
    //polycurve constructors
  Polycurve_conic_traits_2::Construct_x_monotone_curve_2
    construct_x_mono_polycurve = traits.construct_x_monotone_curve_2_object();
  Polycurve_conic_traits_2::Construct_curve_2  construct_polycurve =
    traits.construct_curve_2_object();

   //create a curve

  Conic_curve_2 c3(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(0), Algebraic(0)),
                   Conic_point_2(Algebraic(3), Algebraic(9)));
  Conic_curve_2 c4(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(3), Algebraic(9)),
                   Conic_point_2(Algebraic(5), Algebraic(25)));
  Conic_curve_2 c5(0,1,0,1,0,0, CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(-25), Algebraic(-5)),
                   Conic_point_2(Algebraic(0), Algebraic(0)));

  Conic_curve_2 c6(1,1,0,6,-26,162,CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(-7), Algebraic(13)),
                   Conic_point_2(Algebraic(-3), Algebraic(9)));
  Conic_curve_2 c7(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(-3), Algebraic(9)),
                   Conic_point_2(Algebraic(0), Algebraic(0)));
  Conic_curve_2 c8(0,1,0,-1,0,0, CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(0), Algebraic(0)),
                   Conic_point_2(Algebraic(4), Algebraic(-2)));

  Conic_curve_2 c9(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
                   Conic_point_2(Algebraic(-5), Algebraic(25)),
                   Conic_point_2(Algebraic(5), Algebraic(25)));
  Conic_curve_2 c10(58, 72, -48, 0, 0, -360);

  //This vector is used to store curves that will be used to create polycurve
  std::vector<Conic_curve_2> conic_curves;
  conic_curves.push_back(c9);

  //construct poly-curve
  Polycurve_conic_traits_2::Curve_2 conic_polycurve =
    construct_polycurve(conic_curves.begin(), conic_curves.end());

  Conic_curve_2 c11(0,1,0,-1,0,0,CGAL::COUNTERCLOCKWISE,
                     Conic_point_2(Algebraic(25), Algebraic(-5)),
                     Conic_point_2(Algebraic(0), Algebraic(0)));
  Conic_curve_2 c12(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
                     Conic_point_2(Algebraic(0), Algebraic(0)),
                     Conic_point_2(Algebraic(5), Algebraic(25)));
  conic_curves.clear();
  conic_curves.push_back(c11);
  conic_curves.push_back(c12);

  //construct poly-curve
  Polycurve_conic_traits_2::Curve_2 conic_polycurve_2 =
    construct_polycurve(conic_curves.begin(), conic_curves.end());

  /* VERY IMPORTANT
   * For efficiency reasons, we recommend users not to construct
   * x-monotone conic arc directly, but rather use the Make_x_monotone_2
   * functor supplied by the conic-arc traits class to convert conic curves
   * to x-monotone curves.
   */
  Conic_x_monotone_curve_2 xc3(c3);
  Conic_x_monotone_curve_2 xc4(c4);
  Conic_x_monotone_curve_2 xc5(c5);
  Conic_x_monotone_curve_2 xc6(c6);
  Conic_x_monotone_curve_2 xc7(c7);
  Conic_x_monotone_curve_2 xc8(c8);


  //This vector is used to store curves that will be used to create
  //X-monotone-polycurve
  std::vector<Conic_x_monotone_curve_2> xmono_conic_curves_2;
  xmono_conic_curves_2.push_back(xc5);
  xmono_conic_curves_2.push_back(xc3);
  xmono_conic_curves_2.push_back(xc4);


  //construct x-monotone poly-curve
  Pc_x_monotone_curve_2 conic_x_mono_polycurve_1 =
    construct_x_mono_polycurve(xmono_conic_curves_2.begin(),
                               xmono_conic_curves_2.end());

  xmono_conic_curves_2.clear();
  xmono_conic_curves_2.push_back(xc6);
  xmono_conic_curves_2.push_back(xc7);
  xmono_conic_curves_2.push_back(xc8);
  //construct x-monotone poly-curve
  Pc_x_monotone_curve_2 conic_x_mono_polycurve_2 =
    construct_x_mono_polycurve(xmono_conic_curves_2.begin(),
                               xmono_conic_curves_2.end());

  xmono_conic_curves_2.clear();
  xmono_conic_curves_2.push_back(xc5);

  Pc_x_monotone_curve_2 x_polycurve_push =
    construct_x_mono_polycurve(xmono_conic_curves_2.begin(),
                               xmono_conic_curves_2.end());
  Polycurve_conic_traits_2::X_monotone_subcurve_2 xcurve_push =
    Polycurve_conic_traits_2::X_monotone_subcurve_2(c5);
  //traits.construct_x_monotone_curve_2_object()(c5);

  xmono_conic_curves_2.clear();
  xmono_conic_curves_2.push_back(xc3);
  xmono_conic_curves_2.push_back(xc4);
  Pc_x_monotone_curve_2 base_curve =
    construct_x_mono_polycurve(xmono_conic_curves_2.begin(),
                               xmono_conic_curves_2.end());

  //curves for push_back
  Conic_curve_2 c13(1,1,0,-50,12,660,CGAL::COUNTERCLOCKWISE,
                    Conic_point_2(Algebraic(25), Algebraic(-7)),
                    Conic_point_2(Algebraic(25), Algebraic(-5)));
  Conic_curve_2 c14(0,1,0,-1,0,0,CGAL::COUNTERCLOCKWISE,
                    Conic_point_2(Algebraic(25), Algebraic(-5)),
                    Conic_point_2(Algebraic(0), Algebraic(0)));
  Conic_curve_2 c15(-1,0,0,0,1,0,CGAL::COUNTERCLOCKWISE,
                    Conic_point_2(Algebraic(0), Algebraic(0)),
                    Conic_point_2(Algebraic(5), Algebraic(25)));
  conic_curves.clear();
  conic_curves.push_back(c13);
  conic_curves.push_back(c14);
  Polycurve_conic_traits_2::Curve_2 base_curve_push_back =
    construct_polycurve(conic_curves.begin(), conic_curves.end());

  conic_curves.push_back(c15);
  Polycurve_conic_traits_2::Curve_2 Expected_push_back_result =
    construct_polycurve(conic_curves.begin(), conic_curves.end());

  // //checking the orientattion consistency
  // Conic_curve_2 c21(0,1,0,1,0,0,CGAL::CLOCKWISE,
  //                  Conic_point_2(Algebraic(9), Algebraic(-3)),
  //                  Conic_point_2(Algebraic(0), Algebraic(0)));
  // Conic_curve_2 c20(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
  //                   Conic_point_2(Algebraic(0), Algebraic(0)),
  //                   Conic_point_2(Algebraic(3), Algebraic(9)));
  //  Conic_x_monotone_curve_2 xc20(c20);
  //  Conic_x_monotone_curve_2 xc21(c21);
  //  xmono_conic_curves_2.clear();
  //  xmono_conic_curves_2.push_back(xc20);
  // xmono_conic_curves_2.push_back(xc21);
  // Pc_x_monotone_curve_2 eric_polycurve =
  //   construct_x_mono_polycurve(xmono_conic_curves_2.begin(),
  //                              xmono_conic_curves_2.end());
  // std::cout << "the polycurve is: " << eric_polycurve << std::endl;

  // std::cout<< std::endl;

  //check_compare_x_2(xc3, xc5);

  // check_equal();
  // std::cout<< std::endl;

   //check_intersect(conic_x_mono_polycurve_1, conic_x_mono_polycurve_2);
   //std::cout<< std::endl;

  // check_compare_end_points_xy_2();
  // std::cout<< std::endl;

  //check_split(conic_x_mono_polycurve_1, conic_x_mono_polycurve_2);
  // std::cout<< std::endl;

  //check_make_x_monotne_curve(conic_polycurve_2);
   //std::cout<< std::endl;

  // check_is_vertical();
  // std::cout<< std::endl;

  //check_compare_y_at_x_2();
  //std::cout<< std::endl;

  //adds the segment to the right.
  //check_push_back(base_curve_push_back, c15);
  //std::cout<< std::endl;

  //adds the segment to the left.
  //check_push_front(base_curve, xcurve_push);
  //std::cout<< std::endl;

  // check_are_mergable();
  // std::cout<< std::endl;

  // check_merge_2();
  // std::cout<< std::endl;

  // check_construct_opposite();
  // std::cout<< std::endl;

  // check_compare_y_at_x_right();
  // std::cout<< std::endl;

  // check_compare_y_at_x_left();
  // std::cout<< std::endl;
  //check_compare_points(conic_x_mono_polycurve_1);

  //number of segments
  //std::cout << "Number of segments: "
  //          << traits.number_of_points_2_object()(base_curve_push_back)
  //          << std::endl;

  check_trim(conic_x_mono_polycurve_1, atoi(argv[1]), atoi(argv[2]),
             atoi(argv[3]), atoi(argv[4]));
  std::cout << std::endl;

  //std::cout << (atoi(argv[1]) + atoi(argv[2])) << std::endl;
  // Conic_traits_2 con_traits;
  // Conic_curve_2 cc3(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE,
  //                   Conic_point_2(Algebraic(0), Algebraic(0)),
  //                   Conic_point_2(Algebraic(3), Algebraic(9)));
  // Conic_x_monotone_curve_2 xcc3(cc3);
  // Conic_point_2       ps2(0, 0);
  // Conic_point_2       pt2(3, 9);
  // std::cout << "conic curve is : " << xcc3 << std::endl;
  // Conic_x_monotone_curve_2 trimmed_curve =
  //   con_traits.trim_2_object()(xc3, ps2, pt2);
  // std::cout << "trimmed conic curve is : " << trimmed_curve << std::endl;

  return 0;
}
コード例 #17
0
ファイル: ClassDecl.cpp プロジェクト: deleisha/neopegasus
void test01()
{
    // class MyClass : YourClass
    // {
    //     string message = "Hello";
    // }
    try
    {
        CIMName a = "A_class1";
        CIMName b = "A_class2";
        CIMClass c0(a, b);
        CIMClass c1(a, CIMName("A_class2"));
        CIMClass c2(CIMName("A_class1"), b);
        CIMClass c3(b, a);
    }
    catch (InvalidNameException & ine)
    {
        if (verbose)
        {
        cout << "Caught unexpected exception: " << ine.getMessage() << endl;
        }
    }
    try
    {
        //
        //  Invalid class name
        //
        CIMClass class0(CIMName ("//localhost/root/cimv2:MyClass"),
            CIMName ("YourClass"));

        PEGASUS_TEST_ASSERT(class0.getPath() ==
            CIMObjectPath("//localhost/root/cimv2:MyClass"));
    }
    catch (InvalidNameException & ine)
    {
        if (verbose)
        {
        cout << "Caught expected exception: " << ine.getMessage() << endl;
        }
    }

    CIMClass class1(CIMName ("MyClass"), CIMName ("YourClass"));

    class1
    .addQualifier(CIMQualifier(CIMName ("association"), true))
    .addQualifier(CIMQualifier(CIMName ("q1"), Uint32(55)))
    .addQualifier(CIMQualifier(CIMName ("q2"), String("Hello")))
    .addProperty(CIMProperty(CIMName ("message"), String("Hello")))
    .addProperty(CIMProperty(CIMName ("count"), Uint32(77), 0, CIMName(),
            CIMName("YourClass"), true))
    .addMethod(CIMMethod(CIMName ("isActive"), CIMTYPE_BOOLEAN)
        .addParameter(CIMParameter(CIMName ("hostname"), CIMTYPE_STRING))
        .addParameter(CIMParameter(CIMName ("port"), CIMTYPE_UINT32)));

    // Test the method count function
    PEGASUS_TEST_ASSERT(class1.getClassName().equal(CIMName ("myclass")));
    PEGASUS_TEST_ASSERT(class1.getSuperClassName() == CIMName ("YourClass"));

    PEGASUS_TEST_ASSERT(class1.getMethodCount() ==1);


    // Test the findMethod and isMethod functions
    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("isActive")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("DoesNotExist")) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("isActive")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("DoesNotExist")) == PEG_NOT_FOUND);

    // Test the manipulation of an embeddedObjectProperty
    CIMClass embedClass(CIMName ("embedObj"), CIMName ());
    class1.addProperty(CIMProperty(CIMName ("embedObj"),
        CIMObject(embedClass), 0, CIMName(),
            CIMName(), false));

    PEGASUS_TEST_ASSERT(class1.findProperty(
                CIMName ("embedObj")) != PEG_NOT_FOUND);
    Uint32  posProp = class1.findProperty(CIMName ("embedObj"));
    CIMConstProperty constprop1 = class1.getProperty(posProp);
    PEGASUS_TEST_ASSERT(constprop1.getClassOrigin() == CIMName());
    PEGASUS_TEST_ASSERT(constprop1.getType() == CIMTYPE_OBJECT);
    class1.removeProperty(posProp);

    // Now add another method and reconfirm.

    class1.addMethod(CIMMethod(CIMName ("makeActive"), CIMTYPE_BOOLEAN)
    .addParameter(CIMParameter(CIMName ("hostname"), CIMTYPE_STRING))
    .addParameter(CIMParameter(CIMName ("port"), CIMTYPE_UINT32)));

    PEGASUS_TEST_ASSERT(class1.getMethodCount() == 2);

    // Test the findMethod and isMethod functions
    // with two methods defined
    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("isActive")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("makeActive")) != PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("DoesNotExist")) == PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("isActive")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("makeActive")) != PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("DoesNotExist")) == PEG_NOT_FOUND);


    // Test RemoveMethod function
    Uint32 posMethod;
    posMethod = class1.findMethod(CIMName ("isActive"));
    PEGASUS_TEST_ASSERT(posMethod != PEG_NOT_FOUND);

    class1.removeMethod(posMethod);

    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("isActive")) == PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.getMethodCount() == 1);

    //ATTN: P3 TODO add tests for different case names

    //Qualifier manipulation tests  (find, remove)

    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("qx")) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findQualifier(
                CIMName ("association")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.isAssociation());

    // Remove middle Qualifier "q2"
    Uint32 posQualifier;
    posQualifier = class1.findQualifier(CIMName ("q2"));
    CIMConstQualifier qconst = class1.getQualifier(posQualifier);

    PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 3);
    PEGASUS_TEST_ASSERT(posQualifier <= class1.getQualifierCount());
    class1.removeQualifier(posQualifier);
    PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 2);

    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) == PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.isAssociation());


    // Remove the first parameter "q1"
    posQualifier = class1.findQualifier(CIMName ("q1"));

    PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 2);
    CIMQualifier cq = class1.getQualifier( class1.findQualifier(
                CIMName ("q1")));
    PEGASUS_TEST_ASSERT(posQualifier <= class1.getQualifierCount());
    class1.removeQualifier(posQualifier);
    PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 1);

    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) == PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) == PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.isAssociation());


    // ATTH: P3 Add tests for try block for outofbounds



    //The property manipulation tests.

    PEGASUS_TEST_ASSERT(class1.findProperty(
                CIMName ("count")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findProperty(
                CIMName ("message")) != PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(class1.findProperty(
                CIMName ("isActive")) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(class1.getPropertyCount() == 2);


    Uint32  posProperty;
    posProperty = class1.findProperty(CIMName ("count"));
    CIMConstProperty constprop = class1.getProperty(posProperty);
    PEGASUS_TEST_ASSERT(constprop.getClassOrigin() == CIMName("YourClass"));
    PEGASUS_TEST_ASSERT(constprop.getPropagated());
    class1.removeProperty(posProperty);
    PEGASUS_TEST_ASSERT(class1.findProperty(
                CIMName ("message")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findProperty(
                CIMName ("count")) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(class1.getPropertyCount() == 1);
    CIMProperty cp = class1.getProperty( class1.findProperty
        (CIMName ("message")));
    PEGASUS_TEST_ASSERT(cp.getClassOrigin().isNull());
    PEGASUS_TEST_ASSERT(!cp.getPropagated());

    if(verbose)
    {
        XmlWriter::printClassElement(class1);
        MofWriter::printClassElement(class1);
    }

    Buffer out;
    MofWriter::appendClassElement(out, class1);
    out.clear();
    XmlWriter::appendClassElement(out, class1);

    PEGASUS_TEST_ASSERT(!class1.isAbstract());

    CIMName squal("q1");
    PEGASUS_TEST_ASSERT(class1.findQualifier(squal) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(!class1.hasKeys());

    Array<CIMName> keyNames;
    class1.getKeyNames(keyNames);

    CIMClass c2(CIMName ("MyClass"));

    PEGASUS_TEST_ASSERT(c2.getClassName().equal(CIMName ("myclass")));


    // Error uninitialized handle
    c2.setSuperClassName(CIMName ("CIM_Element"));
    PEGASUS_TEST_ASSERT(c2.getSuperClassName() == CIMName ("CIM_Element"));

    CIMClass c3 = c2.clone();
    c3 = c2;


    try
    {
        CIMMethod cm = c2.getMethod(0);
    }
    catch(IndexOutOfBoundsException& e)
    {
        if(verbose)
            cout << "Exception: " << e.getMessage() << endl;
    }

    const CIMClass c4(CIMName ("MyClass"), CIMName ("YourClass"));

    CIMConstClass c5(CIMName ("MyClass"), CIMName ("YourClass"));
    CIMConstClass c6(CIMName ("MyClass"));
    CIMConstClass cc7(c6);
    CIMClass c7 = c5.clone();
    const CIMClass c8(class1);

    // Test the findMethod and isMethod functions
    PEGASUS_TEST_ASSERT(c7.findMethod(
                CIMName ("DoesNotExist")) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(c7.findQualifier(CIMName ("dummy")) == PEG_NOT_FOUND);

    try
    {
        CIMConstMethod cm = c8.getMethod(0);
    }
    catch(IndexOutOfBoundsException& e)
    {
        if(verbose)
            cout << "Exception: " << e.getMessage() << endl;
    }

    try
    {
        CIMConstProperty ccp = c8.getProperty(c8.findProperty
            (CIMName ("count")));
    }
    catch(IndexOutOfBoundsException& e)
    {
        if(verbose)
            cout << "Exception: " << e.getMessage() << endl;
    }

    if(verbose)
    {
    XmlWriter::printClassElement(c5);
    }

    try
    {
        CIMConstMethod cm = cc7.getMethod(0);
    }
    catch(IndexOutOfBoundsException& e)
    {
    if(verbose)
        cout << "Exception: " << e.getMessage() << endl;
    }
    // Test the findMethod and isMethod functions
    PEGASUS_TEST_ASSERT(c4.findMethod(
                CIMName ("DoesNotExist")) == PEG_NOT_FOUND);

    //Qualifier manipulation tests  (find, remove)

    PEGASUS_TEST_ASSERT(c4.findQualifier(CIMName ("qx")) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(c4.findQualifier(CIMName ("q1")) == PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(c4.findQualifier(CIMName ("q2")) == PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(c4.findQualifier(
                CIMName ("association")) == PEG_NOT_FOUND);

    posProperty = c4.findProperty(CIMName ("count"));

    try
    {
        CIMConstQualifier ccq = c4.getQualifier(c4.findQualifier
            (CIMName ("q1")));
    }
    catch (IndexOutOfBoundsException& e)
    {
        if(verbose)
            cout << "Exception: " << e.getMessage() << endl;
    }

    PEGASUS_TEST_ASSERT(c4.findProperty(CIMName ("count")) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(c4.getClassName() == CIMName ("MyClass"));
    PEGASUS_TEST_ASSERT(c4.getClassName().equal(CIMName ("MyClass")));
    PEGASUS_TEST_ASSERT(c4.getClassName().equal(CIMName ("MYCLASS")));
    PEGASUS_TEST_ASSERT(c4.getClassName().equal(CIMName ("myclass")));
    PEGASUS_TEST_ASSERT(!c4.getClassName().equal(CIMName ("blob")));


    PEGASUS_TEST_ASSERT(c4.getSuperClassName() == CIMName ("YourClass"));

    // test the setSuperClassName function
    /* ATTN KS 29 April.  This test has problems.  Relook later.
      Think test, not code.
    c4.setSuperClassName(CIMName ("JunkClass"));
    PEGASUS_TEST_ASSERT(c4.getSuperClassName() == CIMName ("JunkClass"));
    c4.setSuperClassName(CIMName ("YourClass"));
    */
    PEGASUS_TEST_ASSERT(c5.getSuperClassName() == CIMName ("YourClass"));

    PEGASUS_TEST_ASSERT(c5.getQualifierCount() == 0);
    posQualifier = c5.findQualifier(CIMName ("q2"));

    // throws out of bounds
    try
    {
        CIMConstQualifier qconst1 = c5.getQualifier(posQualifier);
    }
    catch(IndexOutOfBoundsException& e)
    {
        if(verbose)
            cout << "Exception: " << e.getMessage() << endl;
    }
    if(verbose)
    {
        cout << "All tests" << endl;
    }
}
コード例 #18
0
ファイル: test_kdtree.cpp プロジェクト: CJ456/laserkbd
int main()
{
   // check that it'll find nodes exactly MAX away
   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 4, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target,2);
      assert(found.first != exact_dist.end());
      assert(found.second == 2);
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << std::endl;
   }

   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 2, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

        // call find_nearest without a range value - it found a compile error earlier.
      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target);
      assert(found.first != exact_dist.end());
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << " @ " << found.second << " should be " << sqrt(8) << std::endl;
      assert(found.second == sqrt(8));
   }

   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 2, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target,sqrt(8));
      assert(found.first != exact_dist.end());
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << " @ " << found.second << " should be " << sqrt(8) << std::endl;
      assert(found.second == sqrt(8));
   }

  tree_type src(std::ptr_fun(tac));

  triplet c0(5, 4, 0); src.insert(c0);
  triplet c1(4, 2, 1); src.insert(c1);
  triplet c2(7, 6, 9); src.insert(c2);
  triplet c3(2, 2, 1); src.insert(c3);
  triplet c4(8, 0, 5); src.insert(c4);
  triplet c5(5, 7, 0); src.insert(c5);
  triplet c6(3, 3, 8); src.insert(c6);
  triplet c7(9, 7, 3); src.insert(c7);
  triplet c8(2, 2, 6); src.insert(c8);
  triplet c9(2, 0, 6); src.insert(c9);

  std::cout << src << std::endl;

  src.erase(c0);
  src.erase(c1);
  src.erase(c3);
  src.erase(c5);

  src.optimise();


  // test the efficient_replace_and_optimise()
  tree_type eff_repl = src;
  {
     std::vector<triplet> vec;
     // erased above as part of test vec.push_back(triplet(5, 4, 0));
     // erased above as part of test vec.push_back(triplet(4, 2, 1));
     vec.push_back(triplet(7, 6, 9));
     // erased above as part of test vec.push_back(triplet(2, 2, 1));
     vec.push_back(triplet(8, 0, 5));
     // erased above as part of test vec.push_back(triplet(5, 7, 0));
     vec.push_back(triplet(3, 3, 8));
     vec.push_back(triplet(9, 7, 3));
     vec.push_back(triplet(2, 2, 6));
     vec.push_back(triplet(2, 0, 6));

     eff_repl.clear();
     eff_repl.efficient_replace_and_optimise(vec);
  }


  std::cout << std::endl << src << std::endl;

  tree_type copied(src);
  std::cout << copied << std::endl;
  tree_type assigned;
  assigned = src;
  std::cout << assigned << std::endl;

  for (int loop = 0; loop != 4; ++loop)
    {
      tree_type * target;
      switch (loop)
	{
	case 0: std::cout << "Testing plain construction" << std::endl;
	  target = &src;
	  break;

	case 1: std::cout << "Testing copy-construction" << std::endl;
	  target = &copied;
	  break;

	case 2: std::cout << "Testing assign-construction" << std::endl;
	  target = &assigned;
	  break;

   default:
	case 4: std::cout << "Testing efficient-replace-and-optimise" << std::endl;
	  target = &eff_repl;
	  break;
	}
      tree_type & t = *target;

      int i=0;
      for (tree_type::const_iterator iter=t.begin(); iter!=t.end(); ++iter, ++i);
      std::cout << "iterator walked through " << i << " nodes in total" << std::endl;
      if (i!=6)
	{
	  std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
	  return 1;
	}
      i=0;
      for (tree_type::const_reverse_iterator iter=t.rbegin(); iter!=t.rend(); ++iter, ++i);
      std::cout << "reverse_iterator walked through " << i << " nodes in total" << std::endl;
      if (i!=6)
	{
	  std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
	  return 1;
	}

      triplet s(5, 4, 3);
      std::vector<triplet> v;
      unsigned int const RANGE = 3;

      size_t count = t.count_within_range(s, RANGE);
      std::cout << "counted " << count
		<< " nodes within range " << RANGE << " of " << s << ".\n";
      t.find_within_range(s, RANGE, std::back_inserter(v));

      std::cout << "found   " << v.size() << " nodes within range " << RANGE
		<< " of " << s << ":\n";
      std::vector<triplet>::const_iterator ci = v.begin();
      for (; ci != v.end(); ++ci)
	std::cout << *ci << " ";
      std::cout << "\n" << std::endl;

      std::cout << std::endl << t << std::endl;

      // search for all the nodes at exactly 0 dist away
      for (tree_type::const_iterator target = t.begin(); target != t.end(); ++target)
      {
         std::pair<tree_type::const_iterator,double> found = t.find_nearest(*target,0);
         assert(found.first != t.end());
         assert(*found.first == *target);
         std::cout << "Test find_nearest(), found at exact distance away from " << *target << ", found " << *found.first << std::endl;
      }

      {
         const double small_dist = 0.0001;
         std::pair<tree_type::const_iterator,double> notfound = t.find_nearest(s,small_dist);
         std::cout << "Test find_nearest(), nearest to " << s << " within " << small_dist << " should not be found" << std::endl;

         if (notfound.first != t.end())
         {
            std::cout << "ERROR found a node at dist " << notfound.second << " : " << *notfound.first << std::endl;
            std::cout << "Actual distance = " << s.distance_to(*notfound.first) << std::endl;
         }

         assert(notfound.first == t.end());
      }

      {
         std::pair<tree_type::const_iterator,double> nif = t.find_nearest_if(s,std::numeric_limits<double>::max(),Predicate());
         std::cout << "Test find_nearest_if(), nearest to " << s << " @ " << nif.second << ": " << *nif.first << std::endl;

         std::pair<tree_type::const_iterator,double> cantfind = t.find_nearest_if(s,std::numeric_limits<double>::max(),FalsePredicate());
         std::cout << "Test find_nearest_if(), nearest to " << s << " should never be found (predicate too strong)" << std::endl;
         assert(cantfind.first == t.end());
      }




      {
      std::pair<tree_type::const_iterator,double> found = t.find_nearest(s,std::numeric_limits<double>::max());
      std::cout << "Nearest to " << s << " @ " << found.second << " " << *found.first << std::endl;
      std::cout << "Should be " << found.first->distance_to(s) << std::endl;
      // NOTE: the assert does not check for an exact match, as it is not exact when -O2 or -O3 is
      // switched on.  Some sort of optimisation makes the math inexact.
      assert( fabs(found.second - found.first->distance_to(s)) < std::numeric_limits<double>::epsilon() );
      }

      {
      triplet s2(10, 10, 2);
      std::pair<tree_type::const_iterator,double> found = t.find_nearest(s2,std::numeric_limits<double>::max());
      std::cout << "Nearest to " << s2 << " @ " << found.second << " " << *found.first << std::endl;
      std::cout << "Should be " << found.first->distance_to(s2) << std::endl;
      // NOTE: the assert does not check for an exact match, as it is not exact when -O2 or -O3 is
      // switched on.  Some sort of optimisation makes the math inexact.
      assert( fabs(found.second - found.first->distance_to(s2)) < std::numeric_limits<double>::epsilon() );
      }

      std::cout << std::endl;

      std::cout << t << std::endl;

      // Testing iterators
      {
	std::cout << "Testing iterators" << std::endl;

	t.erase(c2);
	t.erase(c4);
	t.erase(c6);
	t.erase(c7);
	t.erase(c8);
	//    t.erase(c9);

	std::cout << std::endl << t << std::endl;

	std::cout << "Forward iterator test..." << std::endl;
	std::vector<triplet> forwards;
	for (tree_type::iterator i = t.begin(); i != t.end(); ++i)
	  { std::cout << *i << " " << std::flush; forwards.push_back(*i); }
	std::cout << std::endl;
	std::cout << "Reverse iterator test..." << std::endl;
	std::vector<triplet> backwards;
	for (tree_type::reverse_iterator i = t.rbegin(); i != t.rend(); ++i)
	  { std::cout << *i << " " << std::flush; backwards.push_back(*i); }
	std::cout << std::endl;
	std::reverse(backwards.begin(),backwards.end());
	assert(backwards == forwards);
      }
    }

  return 0;
}
コード例 #19
0
ファイル: test.cpp プロジェクト: Endofunctor/noobwerkz-engine
int test0 (void) {
int ret = 0;

	printf ("TEST: CBString constructor\n");

	try {
		printf ("\tCBString c;\n");
		CBString c0;
		ret += (0 != c0.length());
		ret += '\0' != ((const char *)c0)[c0.length()];

		printf ("\tCBString c(\"test\");\n");
		CBString c1 ("test");
		ret += (c1 != "test");
		ret += '\0' != ((const char *)c1)[c1.length()];

		printf ("\tCBString c(25, \"test\");\n");
		CBString c8 (25, "test");
		ret += (c8 != "test");
		ret += c8.mlen < 25;
		ret += '\0' != ((const char *)c8)[c8.length()];

		printf ("\tCBString c('t');\n");
		CBString c2 ('t');
		ret += (c2 != "t");
		ret += '\0' != ((const char *)c2)[c2.length()];

		printf ("\tCBString c('\\0');\n");
		CBString c3 ('\0');
		ret += (1 != c3.length()) || ('\0' != c3[0]);
		ret += '\0' != ((const char *)c3)[c3.length()];

		printf ("\tCBString c(bstr[\"test\"]);\n");
		struct tagbstring t = bsStatic ("test");
		CBString c4 (t);
		ret += (c4 != t.data);
		ret += '\0' != ((const char *)c4)[c4.length()];

		printf ("\tCBString c(CBstr[\"test\"]);\n");
		CBString c5 (c1);
		ret += (c1 != c5);
		ret += '\0' != ((const char *)c5)[c5.length()];

		printf ("\tCBString c('x',5);\n");
		CBString c6 ('x',5);
		ret += (c6 != "xxxxx");
		ret += '\0' != ((const char *)c6)[c6.length()];

		printf ("\tCBString c(\"123456\",4);\n");
		CBString c7 ((void *)"123456",4);
		ret += (c7 != "1234");
		ret += '\0' != ((const char *)c7)[c7.length()];
	}

	catch (struct CBStringException err) {
		printf ("Exception thrown [%d]: %s\n", __LINE__, err.what());
		ret ++;
	}

	printf ("\t# failures: %d\n", ret);
	return ret;
}
コード例 #20
0
void test(const Cont &)
{
  // Testing if all types are provided.

  typename Cont::value_type              t0;
  typename Cont::reference               t1 = t0;      CGAL_USE(t1);
  typename Cont::const_reference         t2 = t0;      CGAL_USE(t2);
  typename Cont::pointer                 t3 = &t0;
  typename Cont::const_pointer           t4 = &t0;     CGAL_USE(t4);
  typename Cont::size_type               t5 = 0;       CGAL_USE(t5);
  typename Cont::difference_type         t6 = t3-t3;   CGAL_USE(t6);
  typename Cont::iterator                t7;           CGAL_USE(t7);
  typename Cont::const_iterator          t8;           CGAL_USE(t8);
  typename Cont::reverse_iterator        t9;           CGAL_USE(t9);
  typename Cont::const_reverse_iterator  t10;          CGAL_USE(t10);
  typename Cont::allocator_type          t15;

  std::cout << "Testing empty containers." << std::endl;

  Cont c0, c1;
  Cont c2(t15);
  Cont c3(c2);
  Cont c4;
  c4 = c2;

  typedef std::vector<typename Cont::value_type> Vect;
  Vect v0;
  const Cont c5(v0.begin(), v0.end());
  Cont c6(c5.begin(), c5.end());
  typename Cont::allocator_type Al;
  Cont c7(c0.begin(), c0.end(), Al);
  Cont c8;
  c8.insert(c0.rbegin(), c0.rend());

  // test conversion iterator-> const_iterator.
  typename Cont::const_iterator t16 = c5.begin();  CGAL_USE(t16);
  assert(t16 == c5.begin());

  assert(c0 == c1);
  assert(! (c0 < c1));

  assert(check_empty(c0));
  assert(check_empty(c1));
  assert(check_empty(c2));
  assert(check_empty(c3));
  assert(check_empty(c4));
  assert(check_empty(c5));
  assert(check_empty(c6));
  assert(check_empty(c7));
  assert(check_empty(c8));

  c1.swap(c0);

  assert(check_empty(c0));
  assert(check_empty(c1));

  c1.merge(c0);

  assert(check_empty(c0));
  assert(check_empty(c1));

  typename Cont::allocator_type  t20 = c0.get_allocator();

  std::cout << "Now filling some containers" << std::endl;

  Vect v1(10000);
  Cont c9(v1.begin(), v1.end());

  assert(c9.size() == v1.size());
  assert(c9.max_size() >= v1.size());
  assert(c9.capacity() >= c9.size());

  Cont c10 = c9;

  assert(c10 == c9);
  assert(c10.size() == v1.size());
  assert(c10.max_size() >= v1.size());
  assert(c10.capacity() >= c10.size());

  c9.clear();

  assert(check_empty(c9));
  assert(c9.capacity() >= c9.size());
  assert(c0 == c9);

  c9.merge(c10);
  c10.swap(c9);

  assert(check_empty(c9));
  assert(c9.capacity() >= c9.size());

  assert(c10.size() == v1.size());
  assert(c10.max_size() >= v1.size());
  assert(c10.capacity() >= c10.size());

  std::cout << "Testing insertion methods" << std::endl;

  c9.assign(c10.begin(), c10.end());

  assert(c9 == c10);

  c10.assign(c9.begin(), c9.end());

  assert(c9 == c10);

  c9.insert(c10.begin(), c10.end());

  assert(c9.size() == 2*v1.size());

  c9.clear();

  assert(c9 != c10);

  c9.insert(c10.begin(), c10.end());

  assert(c9.size() == v1.size());
  assert(c9 == c10);


  typename Cont::iterator it = c9.iterator_to(*c9.begin());
  assert(it == c9.begin());
  typename Cont::const_iterator cit = c9.iterator_to(const_cast<typename Cont::const_reference>(*c9.begin()));
  assert(cit == c9.begin());

  typename Cont::iterator s_it = Cont::s_iterator_to(*c9.begin());
  assert(s_it == c9.begin());
  typename Cont::const_iterator s_cit = Cont::s_iterator_to(const_cast<typename Cont::const_reference>(*c9.begin()));
  assert(s_cit == c9.begin());


  c10 = Cont();

  assert(check_empty(c10));

  for(typename Vect::const_iterator it = v1.begin(); it != v1.end(); ++it)
    c10.insert(*it);

  assert(c10.size() == v1.size());
  assert(c9 == c10);

  c9.erase(c9.begin());
  c9.erase(c9.begin());

  assert(c9.size() == v1.size() - 2);

  // test reserve
  /*Cont c11;
  c11.reserve(v1.size());
  for(typename Vect::const_iterator it = v1.begin(); it != v1.end(); ++it)
    c11.insert(*it);
  
  assert(c11.size() == v1.size());
  assert(c10 == c11);*/

  // owns() and owns_dereferencable().
  for(typename Cont::const_iterator it = c9.begin(), end = c9.end(); it != end; ++it) {
    assert(c9.owns(it));
    assert(c9.owns_dereferencable(it));
    assert(! c10.owns(it));
    assert(! c10.owns_dereferencable(it));
  }
  assert(c9.owns(c9.end()));
  assert(! c9.owns_dereferencable(c9.end()));


  c9.erase(c9.begin(), c9.end());

  assert(check_empty(c9));
  
  std::cout << "Testing parallel insertion" << std::endl;
  {
  Cont c11;
  Vect v11(1000000);
  std::vector<typename Cont::iterator> iterators(v11.size());
  tbb::parallel_for(
    tbb::blocked_range<size_t>( 0, v11.size() ),
    Insert_in_CCC_functor<Vect, Cont>(v11, c11, iterators)
  );
  assert(c11.size() == v11.size());
  
  std::cout << "Testing parallel erasure" << std::endl;
  tbb::parallel_for(
    tbb::blocked_range<size_t>( 0, v11.size() ),
    Erase_in_CCC_functor<Cont>(c11, iterators)
  );
  assert(c11.empty());
  }

  std::cout << "Testing parallel insertion AND erasure" << std::endl;
  {
  Cont c12;
  Vect v12(1000000);
  std::vector<tbb::atomic<bool> > free_elements(v12.size());
  for(typename std::vector<tbb::atomic<bool> >::iterator 
    it = free_elements.begin(), end = free_elements.end(); it != end; ++it) 
  {
    *it = true;
  }
    
  tbb::atomic<unsigned int> num_erasures; 
  num_erasures = 0;
  std::vector<typename Cont::iterator> iterators(v12.size());
  tbb::parallel_for(
    tbb::blocked_range<size_t>( 0, v12.size() ),
    Insert_and_erase_in_CCC_functor<Vect, Cont>(
      v12, c12, iterators, free_elements, num_erasures)
  );
  assert(c12.size() == v12.size() - num_erasures);
  }
}
コード例 #21
0
ファイル: pr57756_2.c プロジェクト: 0day-ci/gcc
int C6 ()
{
  return c6 ();
}
コード例 #22
0
ファイル: RhoToolsTest.C プロジェクト: freekang/rhoframework
void Sputnik::Launch()
{
    cout << "starting RhoToolsTest" << endl;
    
    // the tests are organized as blocks to let variables
    // go out of scope.  In the output, each block is 
    // separated by a lines of ----
    
    
    // start testing OpAdd4
    
    ostream& theStream = cerr; 
    theStream  <<  "Before Testing OpAdd4 " << endl;
    theStream << endl;
    
    
    TOpAdd4 b4;
    {
	cout << "create a pair of objects:" << endl;
	TCandidate c1(TLorentzVector(1,0,0,0),0);
	TCandidate c2(TLorentzVector(0,2,0,0),0);
	TCandidate c3(TLorentzVector(0,0,3,0),0);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	
	cout << "after OpAdd4.Fill(c3, c1, c2); "<<endl;
	b4.Fill(c3,c1,c2);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	
	TCandidate c4(TLorentzVector(0,0,3,0),0);
	cout <<endl<< "c4(); c4 = OpAdd4().combine( c1, c2); "<<endl;
	c4 = TOpAdd4().Combine(c1,c2);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	
	cout << "---------------------------------------------------"<<endl;
    }
    
    {
	cout << "create objects:" << endl;
	TCandidate c1(TLorentzVector(1,0,0,0),0);
	TCandidate c2(TLorentzVector(0,2,0,0),0);
	TCandidate c3(TLorentzVector(0,0,3,0),0);
	TCandidate c4(TLorentzVector(0,0,0,4),0);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	
	cout <<endl<< "OpAdd4.Fill(c4,c1,c2,c3); "<<endl;
	b4.Fill(c4,c3,c2,c1);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	
	cout << "---------------------------------------------------"<<endl;
    }
    
    {
	cout << "create objects:" << endl;
	TCandidate c1(TLorentzVector(1,0,0,0),1);
	TCandidate c2(TLorentzVector(0,2,0,0),-1);
	TCandidate c3(TLorentzVector(0,0,3,0),0);
	TCandidate c4(TLorentzVector(0,0,0,4),0);
	TCandidate c5(TLorentzVector(0,0,0,0),5);
	TCandidate c6(TLorentzVector(0,0,0,0),6);
	TCandidate c7(TLorentzVector(0,0,0,0),7);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	
	cout <<endl<< "after Add4::Fill(c5,c1,c2); Add4::Fill(c6,c3,c4); "<<endl;
	b4.Fill(c5,c1,c2);
	b4.Fill(c6,c3,c4);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	
	cout <<endl<< "after Add4::Fill(c7,c5,c6); "<<endl;
	b4.Fill(c7,c5,c6);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	
	// do some additional checks of copying, etc
	cout <<endl<< "after c8(c7);"<<endl;
	TCandidate c8(c7);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	PC("c8",c8);
	
	cout <<endl<< "create c9(c1); then c9 = c7;"<<endl;
	TCandidate c9(c1); c9 = c7;
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	PC("c8",c8);
	PC("c9",c9);
	
	cout <<endl<< "c9 = c5;"<<endl;
	c9 = c5;
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	PC("c8",c8);
	PC("c9",c9);
	
	cout << endl;
	cout << "testing Overlaps:"<<endl;
	cout << "c1 and c2: "<<(c1.Overlaps(c2)?"t":"f")<<endl;
	cout << "c9 and c5: "<<(c9.Overlaps(c5)?"t":"f")<<endl;
	cout << "c8 and c5: "<<(c8.Overlaps(c5)?"t":"f")<<endl;
	cout << "c7 and c5: "<<(c7.Overlaps(c5)?"t":"f")<<endl;
	cout << "c6 and c5: "<<(c6.Overlaps(c5)?"t":"f")<<endl;
	cout << "c5 and c5: "<<(c5.Overlaps(c5)?"t":"f")<<endl;
	cout << "c5 and c9: "<<(c5.Overlaps(c9)?"t":"f")<<endl;
	cout << "c5 and c8: "<<(c5.Overlaps(c8)?"t":"f")<<endl;
	cout << "c5 and c7: "<<(c5.Overlaps(c7)?"t":"f")<<endl;
	cout << "c5 and c6: "<<(c5.Overlaps(c6)?"t":"f")<<endl;
	cout << "c5 and c5: "<<(c5.Overlaps(c5)?"t":"f")<<endl;
	cout << "---------------------------------------------------"<<endl;
    }
    
    //
    // start testing OpMakeTree
    
    theStream  <<  "Before Making Tree " << endl;
    theStream << endl;
    
    {
	
	cout << "Initialization of Pdt " << endl;
	//Pdt::readMCppTable("PARENT/PDT/pdt.table");
	TDatabasePDG *Pdt = TRho::Instance()->GetPDG();
	cout << "done." << endl;
	
	// now let's consider the Y(4S)
	double beamAngle  = 0.0204;
	double beamDeltaP = 9.-3.1; 
	
	TVector3 pY4S( -beamDeltaP*sin(beamAngle),0, 
	    beamDeltaP*cos(beamAngle) );
	TCandidate Y4S( pY4S, Pdt->GetParticle("Upsilon(4S)") );
	TTreeNavigator::PrintTree( Y4S );
	cout << "theta " << Y4S.P3().Theta() << endl;
	cout << "phi "   << Y4S.P3().Phi() << endl;
	
	// instanciate a Booster
	TBooster cmsBooster( &Y4S , kTRUE);
	
	// Let's imagine a photon with a certain angle in the CMS frame
	
	// a photon 
	double ePhot = 1.;
	double photAngle = 30*3.1416/180.;
	double photPhi   = 45*3.1416/180.;
	TCandidate 
	    photon( TVector3( ePhot*sin(photAngle)*cos(photPhi), ePhot*sin(photAngle)*sin(photPhi), ePhot*cos(photAngle) ), 
	    Pdt->GetParticle("gamma") );
	
	cout << endl << "The original photon in the CMS frame " << endl;
	TTreeNavigator::PrintTree( photon );
	cout << "theta " << photon.P3().Theta() << endl;
	cout << "phi "   << photon.P3().Phi() << endl;
	
	// the same photon in the LAB frame :
	TCandidate boostedPhoton = cmsBooster.BoostFrom( photon );
	TLorentzVector theLabP4 = cmsBooster.BoostedP4( photon, TBooster::From );
	cout << "the lab Four-Vector (" << 
	    theLabP4.X() << "," << theLabP4.Y() << "," << theLabP4.Z() << ";" << theLabP4.E() << ")" << endl;
	cout << endl << "The lab boosted photon " << endl;
	TTreeNavigator::PrintTree( boostedPhoton );
	cout << "theta " << boostedPhoton.P3().Theta() << endl;
	cout << "phi "   << boostedPhoton.P3().Phi() << endl;
	
	// now boost back in the CMS frame
	TLorentzVector theP4 = cmsBooster.BoostedP4( boostedPhoton, TBooster::To );
	cout << "the Four-Vector in CMS frame (" << 
	    theP4.X() << "," << theP4.Y() << "," << theP4.Z() << ";" << theP4.E() << ")" << endl;
	cout << " from cand :    (" << 
	    photon.P4().X() << "," << photon.P4().Y() << "," << photon.P4().Z() << ";" <<photon.P4().E() << ")" << endl;
	
	
	double mPsi = Pdt->GetParticle("J/psi")->Mass();
	double mMu  = Pdt->GetParticle("mu+")->Mass();
	double mPi  = Pdt->GetParticle("pi+")->Mass();
	double mK   = Pdt->GetParticle("K+")->Mass();
	double mB   = Pdt->GetParticle("B+")->Mass();
	double mDst = Pdt->GetParticle("D*+")->Mass();
	double mD0  = Pdt->GetParticle("D0")->Mass();
	double mRho = Pdt->GetParticle("rho+")->Mass();
	
	//
	// Let's start with a simple example   :  B+ -> J/Psi K+
	//
	
	// muons in the J/Psi frame
	double E(0.), P(0.), th(0.), ph(0.);
	TVector3 p3;
	
	th = 0.3;
	ph = 1.3;
	P  = 0.5*sqrt( pow(mPsi,2) - 4*pow(mMu,2) );
	E  = sqrt( pow(mMu,2) + pow(P,2) );
	p3 = TVector3( sin(th)*cos(ph)*P, sin(th)*sin(ph)*P, cos(th)*P );
	
	TLorentzVector mu1P4(  p3, E );
	TLorentzVector mu2P4( -p3, E );
	
	// J/psi in the B frame
	th = 1.1;
	ph = 0.5;
	P = 0.5*sqrt((pow(mB,2)-pow(mPsi-mK,2))*(pow(mB,2)-pow(mPsi+mK,2)))/mB;
	p3 = TVector3( sin(th)*cos(ph)*P, sin(th)*sin(ph)*P, cos(th)*P );
	E = sqrt( pow(mPsi,2) + pow(P,2) ); 
	TVector3 boostVector( p3.X()/E, p3.Y()/E,p3.Z()/E );
	mu1P4.Boost( boostVector );
	mu2P4.Boost( boostVector );
	E = sqrt( pow(mK,2) + pow(P,2) ); 
	TLorentzVector KP4( -p3, E );
	
	// create the TCandidates
	TCandidate* mu1 = new TCandidate( mu1P4.Vect(), Pdt->GetParticle("mu+") );
	TCandidate* mu2 = new TCandidate( mu2P4.Vect(), Pdt->GetParticle("mu-") );
	TCandidate* K   = new TCandidate( KP4.Vect(), Pdt->GetParticle("K+") );
	
	// now create the Make Tree operator
	TOpMakeTree op;
	
	// now create the J/Psi
	TCandidate psi = op.Combine( *mu1, *mu2 );
	psi.SetType( "J/psi" );
	psi.SetMassConstraint();
	
	cout << endl << "The original psi " << endl;
	TTreeNavigator::PrintTree( psi );
	
	// now create the B+
	TCandidate B = op.Combine( psi, *K );
	B.SetType( "B+" );
	B.SetMassConstraint();
	
	cout << endl << "The B " << endl;
	TTreeNavigator::PrintTree( B );
	
	// create a TTreeNavigator
	TTreeNavigator treeNavigator( B );
	TTreeNavigator::PrintTree( psi );
	
	theStream << "After tree making" << endl;
	theStream << endl;
	
	//instanciate the fitter with the B Candidate
	VAbsFitter* fitter = new TDummyFitter( psi );
	
	theStream << "After fitter construction " << endl;
	theStream << endl;
	
	// get the "fitted" TCandidates
	TCandidate fittedPsi = fitter->GetFitted( psi );
	TTreeNavigator::PrintTree( fittedPsi );
	
	TCandListIterator iterDau =  psi.DaughterIterator();
	TCandidate* dau=0;
	while( dau=iterDau.Next() )
	{
	    TCandidate fittedDau = fitter->GetFitted( *dau );
	    TTreeNavigator::PrintTree( fittedDau );
	}
	
	delete fitter;
	
	fitter = new TDummyFitter( B );
	
	// get the "fitted" TCandidates
	TCandidate fittedB = fitter->GetFitted( B );
	TTreeNavigator::PrintTree( fittedB );
	
	iterDau.Rewind();
	dau=0;
	while( dau=iterDau.Next() )
	{
	    TCandidate fittedDau = fitter->GetFitted( *dau );
	    TTreeNavigator::PrintTree( fittedDau );
	}
	
	TCandidate hello = fitter->GetFitted( psi );
	TTreeNavigator::PrintTree( hello );
	
	delete fitter;
	
	theStream << "After fitter deletion " << endl;
	theStream << endl;
	
	// first let's boost the kaon
	TCandidate boostedKaon = cmsBooster.BoostTo( *K );
	cout << endl << "The boosted Kaon " << endl;
	TTreeNavigator::PrintTree( *K );
	
	// let's boost the psi
	TCandidate boostedPsi = cmsBooster.BoostTo( psi );
	cout << endl << "The boosted Psi " << endl;
	TTreeNavigator::PrintTree( boostedPsi );
	
	
	theStream << "before tree boosting " << endl;
	theStream << endl;
	
	// now let's boost the B in the Y4S frame
	TCandidate boostedB = cmsBooster.BoostTo( B );
	
	// let's see the tree
	cout << endl << "The boosted B " << endl;
	TTreeNavigator::PrintTree( boostedB );
	
	theStream << "after tree boosting " << endl;
	theStream << endl;
	
	// now let's boost a list
	TCandList theList;
	theList.Add( psi );
	theList.Add( *K );
	theList.Add( B );
	TCandList theBoostedList;
	cmsBooster.BoostTo( theList, theBoostedList );
	TCandListIterator iter(theBoostedList);
	TCandidate* c(0);
	while( c=iter.Next() )
	{
	    cout << "boosted cand " << c->PdtEntry()->GetName() << endl;
	    TTreeNavigator::PrintTree( *c );
	}
	
	
	theBoostedList.Cleanup();
	
	PrintAncestors( *mu1 );
	
	delete mu1;
	delete mu2;
	delete K;
	
	cout << "---------------------------------------------------"<<endl;
     }
     
     theStream  <<  "At the end of the test program " << endl;
     theStream << endl;
}
コード例 #23
0
ファイル: TestColor.cpp プロジェクト: nerd-toolkit/nerd
//chris
void TestColor::testConstructor() {
	
	Color c1;
	QVERIFY(c1.red() == 255);
	QVERIFY(c1.green() == 255);
	QVERIFY(c1.blue() == 255);
	QVERIFY(c1.alpha() == 255);

	Color c2(1, 2, 3, 4);
	QVERIFY(c2.red() == 1);
	QVERIFY(c2.green() == 2);
	QVERIFY(c2.blue() == 3);
	QVERIFY(c2.alpha() == 4);

	Color c3(5, 6, 7);
	QVERIFY(c3.red() == 5);
	QVERIFY(c3.green() == 6);
	QVERIFY(c3.blue() == 7);
	QVERIFY(c3.alpha() == 255);

	// c4 has to get the same color values as c3 and c3 has to stay unchanged
	Color c4(c3);
	QVERIFY(c4.red() == 5);
	QVERIFY(c4.green() == 6);
	QVERIFY(c4.blue() == 7);
	QVERIFY(c4.alpha() == 255);
	QVERIFY(c3.red() == 5);
	QVERIFY(c3.green() == 6);
	QVERIFY(c3.blue() == 7);
	QVERIFY(c3.alpha() == 255);

	Color c5;
	c5.setRed(17);
	QCOMPARE(c5.red(), 17);

	c5.setGreen(18);
	QCOMPARE(c5.green(), 18);

	c5.setBlue(19);
	QCOMPARE(c5.blue(), 19);

	c5.setAlpha(20);
	QCOMPARE(c5.alpha(), 20);

	Color c6(-1, 756, -34, 1200);
	QVERIFY(c6.red() == 0);
	QVERIFY(c6.green() == 255);
	QVERIFY(c6.blue() == 0);
	QVERIFY(c6.alpha() == 255);

	Color c7(256, 300, -300);
	QVERIFY(c7.red() == 255);
	QVERIFY(c7.green() == 255);
	QVERIFY(c7.blue() == 0);
	QVERIFY(c7.alpha() == 255);

	c7.setRed(-20);
	QVERIFY(c7.red() == 0);

	c7.setGreen(700);
	QVERIFY(c7.green() == 255);

	c7.setBlue(-20);
	QVERIFY(c7.blue() == 0);

	c7.setAlpha(700);
	QVERIFY(c7.alpha() == 255);

}