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; }
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*/ }
void h7 (void) { sizeof(*c7()); { extern A10 *c7 (void); sizeof(*c7()); { int c7; { extern A10 *c7 (void); sizeof(*c7()); } } sizeof(*c7()); } sizeof(*c7()); }
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; }
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; }
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; }
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; }
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; }
int read_multiplet_data(int lineno, char filename[], opt* opts, vector<string> *listname, vector<metab_template> *Tems, vector<double> *x, char chemshift[], int s, char inputdir[]) // read in metabolite multiplet data, note at present this assumes the file // is ordered in groups corresponding to different metabolites { vector<string> names(lineno);// name characters the first line matrix c1(lineno); matrix c2(lineno); matrix c3(lineno); matrix c4(lineno); matrix c5(lineno); //matrix c6(lineno); matrix c7(lineno); matrixI c8(lineno); // for ph vector<string> names2(lineno); matrix c11(lineno); matrix c12(lineno); int count = 0; double pst, ped; int nl = read_datf(&names,&c1, &c2, &c3, &c4, &c5, &c7, &c8, filename); if (nl < 0) { return nl; } if ((*opts).usechemshift == 1) { int nl2 = read_dat_chemshift(&names2, &c11,&c12, chemshift, s); if (nl2 < 0) { return nl2; } if (nl != nl2) { printf("Different number of multiplets, exiting ...\n"); system("PAUSE"); exit(1); //return -999; } for (unsigned int j = 0; j < nl2; j++) { if (!((c12[j][0]+50)<0.0000001)) { // if(names[j].compare(names2[j]) == 0 && c11[j][0] == c1[j][0]) //{ c1[j][0] = c12[j][0]; //}else{ // printf("something wrong with multi chemshift, exiting ...\n"); // system("PAUSE"); // exit(1); //} } } } char prevname[80]=" "; char name[80] = {'\0'}; char lis[80] = {'\0'}; metab_template templa("",(*x).size()); for (unsigned int i = 0; i < (*listname).size(); i++) { strcpy(lis,(*listname)[i].c_str()); for (int it = 0; it < nl; it++) { strcpy(name,names[it].c_str()); if (!strcmp(lis,name) && c8[it][0]==1) // find a match in the list { if (!strcmp(prevname, " ")&& c8[it][0]==1)//first prevname do not match prevname { metab_template templa1(name,(*x).size()); templa = templa1; } if (strcmp(prevname,name) && strcmp(prevname, " ") && c8[it][0]==1) // make a new template { metab_template templa1(name,(*x).size()); templa = templa1; } strcpy(prevname,name); for (unsigned int n2 = 0; n2<(*opts).st.size(); n2++) { if ((*opts).st[n2]>(*opts).ed[n2]) { pst = (*opts).ed[n2]; ped = (*opts).st[n2]; } else { ped = (*opts).ed[n2]; pst = (*opts).st[n2]; } if ((c5[it][0]+50)<0.0000001) { if (!((c7[it][0]+50)<0.0000001)) { if (c1[it][0]<ped+(15.0*(*opts).log_fwhh_prop_var)+c7[it][0] && c1[it][0]>pst-(15.0*(*opts).log_fwhh_prop_var)-c7[it][0]) { count = 1; } } else { if (c1[it][0]<ped+(15.0*(*opts).log_fwhh_prop_var)+(*opts).rdelta && c1[it][0]>pst-(15.0*(*opts).log_fwhh_prop_var)-(*opts).rdelta) { count = 1; } } } else { if (!((c7[it][0]+50)<0.0000001)) { if (c5[it][0]<ped+(15.0*(*opts).log_fwhh_prop_var)+c7[it][0] && c5[it][0]>pst-(15.0*(*opts).log_fwhh_prop_var)-c7[it][0]) { count = 1; } } else { if (c5[it][0]<ped+(15.0*(*opts).log_fwhh_prop_var)+(*opts).rdelta && c5[it][0]>pst-(15.0*(*opts).log_fwhh_prop_var)-(*opts).rdelta) { count = 1; } } } } if (count == 1) { if((c2[it][0]+1 <0.0000001) && (c2[it][0]+1 > -0.0000001)) { if (c3[it].size()!=c4[it].size()) { cout<<"\nNo. of protons do not match no. of J constant for metabolite "<<names[it]<<", exiting ...\n"; //system("PAUSE"); exit(1); } double prot=0; for(unsigned int locit=0;locit<c4[it].size();locit++) prot+=c4[it][locit]; vector<double> weights(c4[it]); for(unsigned int locit=0;locit<c4[it].size();locit++) weights[locit]/=prot; //multiplet_site ms(prot, c1[it][0]); multiplet_site ms(&c2[it], c1[it][0], &c3[it], prot, x, c5[it][0],-50, c7[it][0], opts); // vector<unsigned int> c2int(c2[it].size(),0); //vecftoi(c2[it], c2int); ms.setup_param_extra(c3[it],weights); templa.add_multiplet(ms); } else if ((c2[it][0]+2 <0.0000001) && (c2[it][0]+2 > -0.0000001)) { //multiplet_site new_mult2(&pos_vec,&nprot_vec, &x); //cout << "c2 "<<c2[it][0] << endl; vector<double> raster(0.0); double vec_el; multiplet_site ms(&c2[it], c1[it][0], &c3[it], c4[it][0], x, c5[it][0], -50, c7[it][0], opts); if (c3[it].size() == 2) { // raster //printf("find input raster\n"); raster.clear(); char fdirR[3000]={'\0'}; strcpy(fdirR,inputdir); strcat(fdirR,name); strcat(fdirR,".txt"); ifstream inA3_str(fdirR); //cout<<"route "<< fdirR<<endl; //cout<<"file is "<< inA3_str<< endl; //if (!inA3_str) //cout<<"empty, no file "<< inA3_str<< endl; //int tst = 1; int tst2 = 0; while(inA3_str.good()) { tst2 = tst2 +1; inA3_str>>vec_el; //cout<<"vec_el ppm "<<vec_el<<",tst2 " <<tst2<<endl; inA3_str.ignore(1); inA3_str.peek(); if (tst2%2 != 0) { //cout<<"tst2 " <<tst2<<endl; if(vec_el<=max(c3[it][1],c3[it][0]) && vec_el>=min(c3[it][1],c3[it][0])) { inA3_str>>vec_el; raster.push_back(vec_el); tst2 = tst2 +1; } } } /*cout<<"tst = " <<tst<<endl; cout<<"raster1 = "<< raster[0]<<"rasterE = "<<raster[raster.size()-1]<<endl; //cout << "c3 "<<c3[it].size()<<endl; //for (int ii = 0; ii <raster.size(); ii++) //cout<<"raster "<< raster[ii] << " "; FILE *outM; outM = fopen("raster.txt","w"); // wirte to file the metabolites in range for anaylsis for (unsigned int cv = 0; cv <raster.size(); cv++) { fprintf(outM, "%f",raster[cv]); if (cv <=(raster.size()-1)) { fprintf(outM, "\n"); } } fclose(outM);*/ ms.raster_setup(abs(c3[it][1]-c3[it][0]), &raster); } else { printf("Wrong ppm ranges for raster (-2) in J_constant, exiting ...\n"); system("PAUSE"); exit(1); } templa.add_multiplet(ms); } else {
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; }
//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); }
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); } }
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; }
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; }
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; }
int C7 () { return c7 (); }