void StringTest::testConstructor() { cxxtools::String s1; CXXTOOLS_UNIT_ASSERT(s1 == cxxtools::String(L"")); cxxtools::String s2(L"abcde"); CXXTOOLS_UNIT_ASSERT(s2 == L"abcde"); cxxtools::String s3(L"abcde", 3); CXXTOOLS_UNIT_ASSERT(s3 == L"abc"); cxxtools::String s4(3, 'x'); CXXTOOLS_UNIT_ASSERT(s4 == L"xxx"); cxxtools::String s5(s2); CXXTOOLS_UNIT_ASSERT(s5 == L"abcde"); cxxtools::String s6(s2, 1); CXXTOOLS_UNIT_ASSERT(s6 == L"bcde"); cxxtools::String s7(s2, 1, 3); CXXTOOLS_UNIT_ASSERT(s7 == L"bcd"); cxxtools::String s10; CXXTOOLS_UNIT_ASSERT(s10 == cxxtools::String(L"")); const cxxtools::Char c11[] = { 'a', 'b', 'c', 'd', 'e', '\0' }; cxxtools::String s11(c11); CXXTOOLS_UNIT_ASSERT(s11 == c11); const cxxtools::Char c12[] = { 'a', 'b', 'c', '\0' }; cxxtools::String s12(L"abcde", 3); CXXTOOLS_UNIT_ASSERT(s12 == c12); const cxxtools::Char c13[] = { 'x', 'x', 'x', '\0' }; cxxtools::String s13(3, 'x'); CXXTOOLS_UNIT_ASSERT(s13 == c13); const cxxtools::Char c14[] = { 'a', 'b', 'c', 'd', 'e', '\0' }; cxxtools::String s14(s11); CXXTOOLS_UNIT_ASSERT(s14 == c14); const cxxtools::Char c15[] = { 'b', 'c', 'd', 'e', '\0' }; cxxtools::String s15(s11, 1); CXXTOOLS_UNIT_ASSERT(s15 == c15); const cxxtools::Char c16[] = { 'b', 'c', 'd', '\0' }; cxxtools::String s16(s11, 1, 3); CXXTOOLS_UNIT_ASSERT(s16 == c16); cxxtools::String s20(s2.begin(), s2.end()); CXXTOOLS_UNIT_ASSERT(s20 == L"abcde"); }
bool GRect::intersect(GRect rect1, GRect rect2) { Segment s11(rect1.coord1.x, rect1.coord2.x); Segment s12(rect1.coord1.y, rect1.coord2.y); Segment s21(rect2.coord1.x, rect2.coord2.x); Segment s22(rect2.coord1.y, rect2.coord2.y); return ( (Segment::intersect(s11, s21)) && (Segment::intersect(s12, s22)) ); }
void sphericalHarmonics::drawSHFunction(const SHFunction& func) const { int n = 64; double du = PI / (n+1); double dv = 2 * PI/ (n+1); //float r; XYZ col; glBegin(GL_QUADS); for (double v = 0; v < 2 * PI; v += dv) { for (double u = 0; u < PI; u += du) { XYZ p[4] = { func.getVector(u, v), func.getVector(u + du, v), func.getVector(u + du, v + dv), func.getVector(u, v + dv) }; SHSample s00(u,v); SHSample s10(u+du,v); SHSample s01(u,v+dv); SHSample s11(u+du,v+dv); #ifdef SH_DEBUG s00.calcCoe(); s10.calcCoe(); s01.calcCoe(); s11.calcCoe(); #endif //r = func.getFloat(s01); col = func.getColor(s01); glColor3f(col.x, col.y, col.z); glVertex3f(p[3].x, p[3].y, p[3].z); //r = func.getFloat(s11); col = func.getColor(s11); glColor3f(col.x, col.y, col.z); glVertex3f(p[2].x, p[2].y, p[2].z); //r = func.getFloat(s10); col = func.getColor(s10); glColor3f(col.x, col.y, col.z); glVertex3f(p[1].x, p[1].y, p[1].z); //r = func.getFloat(s00); col = func.getColor(s00); glColor3f(col.x, col.y, col.z); glVertex3f(p[0].x, p[0].y, p[0].z); } } glEnd(); }
int main() { // Step(a) - construct a triangular face. Arrangement_2 arr; Segment_2 s1(Point_2(667, 1000), Point_2(4000, 5000)); Segment_2 s2(Point_2(4000, 0), Point_2(4000, 5000)); Segment_2 s3(Point_2(667, 1000), Point_2(4000, 0)); Halfedge_handle e1 = arr.insert_in_face_interior(s1, arr.unbounded_face()); Vertex_handle v1 = e1->source(); Vertex_handle v2 = e1->target(); Halfedge_handle e2 = arr.insert_from_right_vertex(s2, v2); Vertex_handle v3 = e2->target(); arr.insert_at_vertices(s3, v3, v1); // Step (b) - create additional two faces inside the triangle. Point_2 p1(4000, 3666), p2(4000, 1000); Segment_2 s4(Point_2(4000, 5000), p1); Segment_2 s5(p1, p2); Segment_2 s6(Point_2(4000, 0), p2); Halfedge_handle e4 = arr.split_edge(e2, s4, Segment_2(Point_2(4000, 0), p1)); Vertex_handle w1 = e4->target(); Halfedge_handle e5 = arr.split_edge(e4->next(), s5, s6); Vertex_handle w2 = e5->target(); Halfedge_handle e6 = e5->next(); Segment_2 s7(p1, Point_2(3000, 2666)); Segment_2 s8(p2, Point_2(3000, 1333)); Segment_2 s9(Point_2(3000, 2666), Point_2(2000, 1666)); Segment_2 s10(Point_2(3000, 1333), Point_2(2000, 1666)); Segment_2 s11(Point_2(3000, 1333), Point_2(3000, 2666)); Halfedge_handle e7 = arr.insert_from_right_vertex(s7, w1); Vertex_handle v4 = e7->target(); Halfedge_handle e8 = arr.insert_from_right_vertex(s8, w2); Vertex_handle v5 = e8->target(); Vertex_handle v6 = arr.insert_in_face_interior(Point_2(2000, 1666), e8->face()); arr.insert_at_vertices(s9, v4, v6); arr.insert_at_vertices(s10, v5, v6); arr.insert_at_vertices(s11, v4, v5); // Step(c) - remove and merge faces to form a single hole in the traingle. arr.remove_edge(e7); arr.remove_edge(e8); e5 = arr.merge_edge(e5, e6, Segment_2(e5->source()->point(), e6->target()->point())); e2 = arr.merge_edge(e4, e5, s2); print_arrangement(arr); return 0; }
void StdStringTestCase::StdConversion() { std::string strStd("std::string value"); wxStdWideString strStdWide(L"std::wstring value"); wxString s1(strStd); CPPUNIT_ASSERT_EQUAL( "std::string value", s1 ); wxString s2(strStdWide); CPPUNIT_ASSERT_EQUAL( "std::wstring value", s2 ); wxString s3; s3 = strStd; CPPUNIT_ASSERT_EQUAL( "std::string value", s3 ); s3 = strStdWide; CPPUNIT_ASSERT_EQUAL( "std::wstring value", s3 ); wxString s4("hello"); // notice that implicit wxString -> std::string conversion is only // available in wxUSE_STL case, because it conflicts with conversion to // const char*/wchar_t* #if wxUSE_STL && wxUSE_UNSAFE_WXSTRING_CONV std::string s5 = s4; #else std::string s5 = s4.ToStdString(); #endif CPPUNIT_ASSERT_EQUAL( "hello", s5 ); #if wxUSE_STL wxStdWideString s6 = s4; #else wxStdWideString s6 = s4.ToStdWstring(); #endif CPPUNIT_ASSERT_EQUAL( "hello", s6 ); #if wxUSE_UNSAFE_WXSTRING_CONV std::string s7(s4); CPPUNIT_ASSERT( s7 == "hello" ); #endif wxStdWideString s8(s4); CPPUNIT_ASSERT( s8 == "hello" ); std::string s9("\xF0\x9F\x90\xB1\0\xE7\x8C\xAB", 9); /* U+1F431 U+0000 U+732B */ wxString s10 = wxString::FromUTF8(s9); CPPUNIT_ASSERT_EQUAL( s9, s10.ToStdString(wxConvUTF8) ); std::string s11("xyz\0\xFF", 5); /* an invalid UTF-8 sequence */ CPPUNIT_ASSERT_EQUAL( wxString::FromUTF8(s11), "" ); }
/*---------------------------------------------------------------- main -----------------------------------------------------------------*/ void test1() { const char *j = "jag"; cout << "length of j = " << strlen(j) << endl; str s1('U', verbose); str s2("jag", verbose); cout << s2 << endl; s2.reverse(); cout << s2 << endl; str s3(s2); cout << s1 << endl; cout << s2 << endl; cout << s3 << endl; s2 = s1; cout << s2 << endl; cout << s1 << endl; if (s1 == s2) { cout << "s1 == s2" << endl; } if (s1 != s3) { cout << "s1 != s3" << endl; } str s10("abcd", verbose); str s11("abc", verbose); int x = string_compare(s10, s11); s3 = 'a' + s1; cout << "s1 = " << s1 << endl; cout << "s3 = " << s3 << endl; s3 = s1 + 'p'; cout << "s3 = " << s3 << endl; //s3 = "abc" + "123" ; // You cannot do this. At least one in RHS must be str s3 = str("abc") + "123"; cout << "s3 = " << s3 << endl; s1 = "++"; s2 = "Claaaa"; cout << "Jag " << 'C' + s1 + '+' + '+' + ' ' << s2 << "s" << endl; }
String AirDC::OutputSerial(int mode) { String StreamOut; switch(mode) { case 1: //Measurements output { //_p,_T,_RH,_qc,AOA,AOS String s1(_p, 6); String s2(_T, 6); String s3(_RH, 6); String s4(_qc, 6); String s5(_AOA, 6); String s6(_AOS, 6); StreamOut="$TMO,"+s1+','+s2+','+s3+','+s4+','+s5+','+s6; //To read string on the other side /* if (Serial.find("$TMO,")) { _p = Serial.parseFloat(); // _T = Serial.parseFloat();// _RH = Serial.parseFloat();// _qc = Serial.parseFloat();// */ break; } case 2: //Air data output //_Rho,_IAS,_CAS,_TAS,_TASPCorrected,_M,_TAT,_h,_mu,_Re { String s1(_Rho, 6); String s2(_IAS, 6); String s3(_CAS, 6); String s4(_TAS, 6); String s5(_TASPCorrected, 6); String s6(_M, 6); String s7(_TAT, 6); String s8(_h, 6); String s9(_mu, 8); String s10(_Re, 6); StreamOut="$TAD,"+s1+','+s2+','+s3+','+s4+','+s5+','+s6+','+s7+','+s8+','+s9+','+s10; break; } case 3: //Measurements uncertainty output //_up,_uT,_uRH,_uqc { String s1(_up, 6); String s2(_uT, 6); String s3(_uRH, 6); String s4(_uqc, 6); StreamOut="$TMU,"+s1+','+s2+','+s3+','+s4; break; } case 4: //Air data uncertainty output //_uRho,_uIAS,_uCAS,_uTAS,_uTAT,_uh; { String s1(_uRho, 6); String s2(_uIAS, 6); String s3(_uCAS, 6); String s4(_uTAS, 6); String s5(_uTAT, 6); String s6(_uh, 6); StreamOut="$TAU,"+s1+','+s2+','+s3+','+s4+','+s5+','+s6; break; } case 51: //Output for Temperature Logger Example { String s1(_Rho, 6); String s2(_TAT, 2); String s3(_TAT-273.15, 2); String s4(_uTAT, 2); String s5(_p, 2); String s6(_mu, 6); String s7(hour()); String s8(minute()); String s9(second()); String s10(month()); String s11(day()); String s12(year()); String s13(millis()); StreamOut="$TEX,"+s1+','+s2+','+s3+','+s4+','+s5+','+s6+','+s7+','+s8+','+s9+','+s10+','+s11+','+s12+','+s13; break; } return StreamOut; } }
int testExpr3(int errors) { std::string expr3 = op_OR + "(" + op_AND + "(3,4,5)," + op_AND + "(1,2)," + op_AND + "(4,1,6,5))"; BLAccessPolicy pol3(expr3, 6); ShareTuple s11(1,0,"1:1"); ShareTuple s12(2,0,"1:2"); ShareTuple s13(3,0,"1:3"); ShareTuple s14(4,0,"1:4"); ShareTuple s15(5,0,"1:5"); ShareTuple s21(1,0,"2:1"); ShareTuple s22(2,0,"2:2"); ShareTuple s23(3,0,"2:3"); ShareTuple s31(1,0,"3:1"); ShareTuple s32(2,0,"3:2"); ShareTuple s33(3,0,"3:3"); ShareTuple s34(4,0,"3:4"); ShareTuple s35(5,0,"3:5"); ShareTuple s36(6,0,"3:6"); vector<ShareTuple> ex3TestA3A4A5; vector<ShareTuple> ex3TestB1B2; vector<ShareTuple> ex3TestC1C2C3C4C5C6; vector<ShareTuple> ex3TestA4C6C5B1; vector<ShareTuple> ex3TestA1A2B3B1C4B2; vector<ShareTuple> ex3WitnessA3A4A5; vector<ShareTuple> ex3WitnessB1B2; vector<ShareTuple> ex3WitnessC1C2C3C4C5C6; vector<ShareTuple> ex3WitnessA4C6C5B1; vector<ShareTuple> ex3WitnessA1A2B3B1C4B2; ex3TestA3A4A5.push_back(s13); ex3TestA3A4A5.push_back(s14); ex3TestA3A4A5.push_back(s15); ex3TestB1B2.push_back(s21); ex3TestB1B2.push_back(s22); ex3TestC1C2C3C4C5C6.push_back(s31); ex3TestC1C2C3C4C5C6.push_back(s32); ex3TestC1C2C3C4C5C6.push_back(s33); ex3TestC1C2C3C4C5C6.push_back(s34); ex3TestC1C2C3C4C5C6.push_back(s35); ex3TestC1C2C3C4C5C6.push_back(s36); ex3TestA4C6C5B1.push_back(s14); ex3TestA4C6C5B1.push_back(s36); ex3TestA4C6C5B1.push_back(s35); ex3TestA4C6C5B1.push_back(s21); ex3TestA1A2B3B1C4B2.push_back(s11); ex3TestA1A2B3B1C4B2.push_back(s12); ex3TestA1A2B3B1C4B2.push_back(s23); ex3TestA1A2B3B1C4B2.push_back(s21); ex3TestA1A2B3B1C4B2.push_back(s34); ex3TestA1A2B3B1C4B2.push_back(s22); ex3WitnessA3A4A5.push_back(s13); ex3WitnessA3A4A5.push_back(s14); ex3WitnessA3A4A5.push_back(s15); ex3WitnessB1B2.push_back(s21); ex3WitnessB1B2.push_back(s22); ex3WitnessC1C2C3C4C5C6.push_back(s34); ex3WitnessC1C2C3C4C5C6.push_back(s31); ex3WitnessC1C2C3C4C5C6.push_back(s36); ex3WitnessC1C2C3C4C5C6.push_back(s35); ex3WitnessA1A2B3B1C4B2.push_back(s21); ex3WitnessA1A2B3B1C4B2.push_back(s22); vector<vector<ShareTuple> > ex3TestRun; vector<vector<ShareTuple> > ex3WitnessRun; ex3TestRun.push_back(ex3TestA3A4A5); ex3TestRun.push_back(ex3TestB1B2); ex3TestRun.push_back(ex3TestC1C2C3C4C5C6); ex3TestRun.push_back(ex3TestA4C6C5B1); ex3TestRun.push_back(ex3TestA1A2B3B1C4B2); ex3WitnessRun.push_back(ex3WitnessA3A4A5); ex3WitnessRun.push_back(ex3WitnessB1B2); ex3WitnessRun.push_back(ex3WitnessC1C2C3C4C5C6); ex3WitnessRun.push_back(ex3WitnessA4C6C5B1); ex3WitnessRun.push_back(ex3WitnessA1A2B3B1C4B2); errors = testVectors(errors, ex3TestRun, ex3WitnessRun, pol3, expr3); return errors; }
int testExpr2(int errors) { std::string expr2 = op_OR + "(" + op_AND + "(1,2)," + op_AND + "(3,4))"; BLAccessPolicy pol2(expr2, 4); ShareTuple s11(1,0,"1:1"); ShareTuple s12(2,0,"1:2"); ShareTuple s13(3,0,"1:3"); ShareTuple s22(2,0,"2:2"); ShareTuple s23(3,0,"2:3"); ShareTuple s24(4,0,"2:4"); vector<ShareTuple> ex2TestA1; vector<ShareTuple> ex2TestA2; vector<ShareTuple> ex2TestA1A2; vector<ShareTuple> ex2TestB3B4; vector<ShareTuple> ex2TestB2B3B4; vector<ShareTuple> ex2TestA1B4A2; vector<ShareTuple> ex2TestA1B2B3B4; vector<ShareTuple> ex2TestA1A3B4B2; vector<ShareTuple> ex2WitnessA1; vector<ShareTuple> ex2WitnessA2; vector<ShareTuple> ex2WitnessA1A2; vector<ShareTuple> ex2WitnessB3B4; vector<ShareTuple> ex2WitnessB2B3B4; vector<ShareTuple> ex2WitnessA1B4A2; vector<ShareTuple> ex2WitnessA1B2B3B4; vector<ShareTuple> ex2WitnessA1A3B4B2; ex2TestA1.push_back(s11); ex2TestA2.push_back(s12); ex2TestA1A2.push_back(s11); ex2TestA1A2.push_back(s12); ex2TestB3B4.push_back(s23); ex2TestB3B4.push_back(s24); ex2TestB2B3B4.push_back(s22); ex2TestB2B3B4.push_back(s23); ex2TestB2B3B4.push_back(s24); ex2TestA1B4A2.push_back(s11); ex2TestA1B4A2.push_back(s24); ex2TestA1B4A2.push_back(s12); ex2TestA1B2B3B4.push_back(s11); ex2TestA1B2B3B4.push_back(s22); ex2TestA1B2B3B4.push_back(s23); ex2TestA1B2B3B4.push_back(s24); ex2TestA1A3B4B2.push_back(s11); ex2TestA1A3B4B2.push_back(s13); ex2TestA1A3B4B2.push_back(s24); ex2TestA1A3B4B2.push_back(s22); ex2WitnessA1A2.push_back(s11); ex2WitnessA1A2.push_back(s12); ex2WitnessB3B4.push_back(s23); ex2WitnessB3B4.push_back(s24); ex2WitnessB2B3B4.push_back(s23); ex2WitnessB2B3B4.push_back(s24); ex2WitnessA1B4A2.push_back(s11); ex2WitnessA1B4A2.push_back(s12); ex2WitnessA1B2B3B4.push_back(s23); ex2WitnessA1B2B3B4.push_back(s24); vector<vector<ShareTuple> > ex2TestRun; vector<vector<ShareTuple> > ex2WitnessRun; ex2TestRun.push_back(ex2TestA1); ex2TestRun.push_back(ex2TestA2); ex2TestRun.push_back(ex2TestA1A2); ex2TestRun.push_back(ex2TestB3B4); ex2TestRun.push_back(ex2TestB2B3B4); ex2TestRun.push_back(ex2TestA1B4A2); ex2TestRun.push_back(ex2TestA1B2B3B4); ex2TestRun.push_back(ex2TestA1A3B4B2); ex2WitnessRun.push_back(ex2WitnessA1); ex2WitnessRun.push_back(ex2WitnessA2); ex2WitnessRun.push_back(ex2WitnessA1A2); ex2WitnessRun.push_back(ex2WitnessB3B4); ex2WitnessRun.push_back(ex2WitnessB2B3B4); ex2WitnessRun.push_back(ex2WitnessA1B4A2); ex2WitnessRun.push_back(ex2WitnessA1B2B3B4); ex2WitnessRun.push_back(ex2WitnessA1A3B4B2); errors = testVectors(errors, ex2TestRun, ex2WitnessRun, pol2, expr2); return errors; }
int testExpr1(int errors) { std::string expr1 = op_OR + "(1,2,3)"; BLAccessPolicy pol1(expr1, 5); ShareTuple s11(1,0,"1:1"); ShareTuple s12(2,0,"2:2"); ShareTuple s13(3,0,"3:3"); ShareTuple s14(4,0,"4:4"); ShareTuple s15(5,0,"5:5"); vector<ShareTuple> ex1Test1; vector<ShareTuple> ex1Test2; vector<ShareTuple> ex1Test3; vector<ShareTuple> ex1Test4; vector<ShareTuple> ex1Test5; vector<ShareTuple> ex1Test42; vector<ShareTuple> ex1Test23; vector<ShareTuple> ex1Test231; vector<ShareTuple> ex1Witness1; vector<ShareTuple> ex1Witness2; vector<ShareTuple> ex1Witness3; vector<ShareTuple> ex1Witness4; vector<ShareTuple> ex1Witness5; vector<ShareTuple> ex1Witness42; vector<ShareTuple> ex1Witness23; vector<ShareTuple> ex1Witness231; ex1Test1.push_back(s11); ex1Test2.push_back(s12); ex1Test3.push_back(s13); ex1Test4.push_back(s14); ex1Test5.push_back(s15); ex1Test42.push_back(s14); ex1Test42.push_back(s12); ex1Test23.push_back(s12); ex1Test23.push_back(s13); ex1Test231.push_back(s12); ex1Test231.push_back(s13); ex1Test231.push_back(s11); ex1Witness1.push_back(s11); ex1Witness2.push_back(s12); ex1Witness3.push_back(s13); ex1Witness42.push_back(s12); ex1Witness23.push_back(s12); ex1Witness231.push_back(s11); vector<vector<ShareTuple> > ex1TestRun; vector<vector<ShareTuple> > ex1WitnessRun; ex1TestRun.push_back(ex1Test1); ex1TestRun.push_back(ex1Test2); ex1TestRun.push_back(ex1Test3); ex1TestRun.push_back(ex1Test4); ex1TestRun.push_back(ex1Test5); ex1TestRun.push_back(ex1Test42); ex1TestRun.push_back(ex1Test23); ex1TestRun.push_back(ex1Test231); ex1WitnessRun.push_back(ex1Witness1); ex1WitnessRun.push_back(ex1Witness2); ex1WitnessRun.push_back(ex1Witness3); ex1WitnessRun.push_back(ex1Witness4); ex1WitnessRun.push_back(ex1Witness5); ex1WitnessRun.push_back(ex1Witness42); ex1WitnessRun.push_back(ex1Witness23); ex1WitnessRun.push_back(ex1Witness231); errors = testVectors(errors, ex1TestRun, ex1WitnessRun, pol1, expr1); return errors; }
int run_main (int, ACE_TCHAR *[]) { ACE_START_TEST (ACE_TEXT ("SString_Test")); { /* Set #1 */ ACE_CString s0 ("hello"); ACE_CString s1 ("hello"); ACE_CString s2 ("world"); ACE_CString s3 ("ll"); ACE_CString s4 ("ello"); ACE_CString s5 = s1 + " " + s2; char single_character = 'z'; ACE_CString single_character_string (single_character); ACE_CString empty_string; ACE_CString zero_size_string (s1.c_str (), 0, 0, 1); if (ACE_CString::npos == 0) ACE_ERROR((LM_ERROR,"Set #1: npos is incorrect.\n")); // Not equal comparisons. Error if they are equal if (s1 == s2){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s1 == s5){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} // Equal comparisons. Error if they are not equal if (s1 != s1){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s1 != s0){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} // Substring match. Error if they are not equal if (s1.strstr (s2) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s1.strstr (s3) != 2){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s3.strstr (s1) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s1.strstr (s4) != 1){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} // Substring creation. Error if they are not equal if (s1.substring (0) != s1){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s1.substring (1) != s4){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s1.substring (2, 2) != s3){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s1.substring (0, 0) != empty_string){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s1.substring (4, 10).length () != 1){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} // Forward search. Error if they are not equal if (s1.find (s3) != 2){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s3.find (s1) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s1.find (s3, 2) != 2){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s3.find (s1, 1) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s1.find (s2) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s1.find ('o') != 4){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} // Reverse search. Error if they are not equal if (s1.rfind ('l') != 3){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} if (s1.rfind ('l', 3) != 2){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} // Assignment. Error if they are not equal ACE_CString s6; s6 = s0; if (s6 != s0){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} s6 = s4; if (s4 != s6){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} s6 = s5; if (s6 != s5){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;} } { /* Set #2 */ ACE_CString s0 = "hello"; ACE_CString s1 ("hello", 0, false); ACE_CString s2 ("world", 0, false); ACE_CString s3 ("ll", 0, false); ACE_CString s4 ("ello", 0, false); ACE_CString s5 = s1 + " " + s2; char single_character = 'z'; ACE_CString single_character_string (single_character); ACE_CString empty_string (0, 0, false); ACE_CString zero_size_string (s1.c_str (), 0, 0, false); // Not equal comparisons. Error if they are equal if (s1 == s2){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} if (s1 == s5){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} // Equal comparisons. Error if they are not equal if (s1 != s1){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} if (s1 != s0){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} // Substring match. Error if they are not equal if (s1.strstr (s2) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} if (s1.strstr (s3) != 2){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} if (s3.strstr (s1) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} if (s1.strstr (s4) != 1){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} // Substring creation. Error if they are not equal if (s1.substring (0) != s1){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} if (s1.substring (1) != s4){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} if (s1.substring (2, 2) != s3){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} if (s1.substring (0, 0) != empty_string){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} // Forward search. Error if they are not equal if (s1.find (s3) != 2){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} if (s3.find (s1) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} if (s1.find (s3, 2) != 2){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} if (s3.find (s1, 1) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} if (s1.find (s2) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} if (s1.find ('o') != 4){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} // Reverse search. Error if they are not equal if (s1.rfind ('l') != 3){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} if (s1.rfind ('l', 3) != 2){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} // Assignment. Error if they are not equal ACE_CString s6; s6 = s0; if (s6 != s0){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} s6 = s4; if (s4 != s6){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} s6 = s5; if (s6 != s5){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} // Clear. Error if they are not equal s0.clear(); if (s0.length() != 0){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} // Rep. Error if they are not equal ACE_Auto_Basic_Array_Ptr<char> s (s1.rep ()); if (ACE_OS::strlen (s.get ()) != s1.length ()) { ACE_ERROR((LM_ERROR,"Auto_ptr s:\n")); }; ACE_CString s7 (s.get ()); if (s1 != s7){ACE_ERROR((LM_ERROR,"Set #2:\n"));return 1;} } { /* Set #3 */ ACE_NS_WString s0 ("hello"); ACE_NS_WString s1 ("hello"); ACE_NS_WString s2 ("world"); ACE_NS_WString s3 ("ll"); ACE_NS_WString s4 ("ello"); ACE_NS_WString s5 = s1 + " " + s2; ACE_NS_WString s6 = ("hella"); // Same length as s1, off by one char. ACE_WCHAR_T single_character = 'z'; ACE_NS_WString single_character_string (single_character); ACE_NS_WString empty_string; ACE_NS_WString zero_size_string (s1.c_str (), 0, 0); // Not equal comparisons. Error if they are equal if (s1 == s2){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s1 == s5){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s1 == s6){ACE_ERROR((LM_ERROR,"Set #3: off-by-one failed\n"));return 1;} // Equal comparisons. Error if they are not equal if (s1 != s1){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s1 != s0){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} // Substring match. Error if they are not equal if (s1.strstr (s2) != ACE_NS_WString::npos){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s1.strstr (s3) != 2){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s3.strstr (s1) != ACE_NS_WString::npos){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s1.strstr (s4) != 1){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} // Substring creation. Error if they are not equal if (s1.substring (0) != s1){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s1.substring (1) != s4){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s1.substring (2, 2) != s3){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s1.substring (0, 0) != empty_string){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} // Forward search. Error if they are not equal if (s1.find (s3) != 2){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s3.find (s1) != ACE_NS_WString::npos){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s1.find (s3, 2) != 2){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s3.find (s1, 1) != ACE_NS_WString::npos){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s1.find (s2) != ACE_NS_WString::npos){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s1.find ('o') != 4){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} // Reverse search. Error if they are not equal if (s1.rfind ('l') != 3){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} if (s1.rfind ('l', 3) != 2){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} // Assignment. Error if they are not equal ACE_NS_WString s7; s7 = s0; if (s7 != s0){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} s7 = s4; if (s4 != s7){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} s7 = s5; if (s7 != s5){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} // Clear. Error if they are not equal s0.clear(); if (s0.length() != 0){ACE_ERROR((LM_ERROR,"Set #3:\n"));return 1;} } { /* Set #4 */ ACE_CString s1("dog"); ACE_CString s2("d"); if (s1 == s2){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} if (!(s1 > s2)){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} if (s1 < s2){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} ACE_CString s3 ("dog"); ACE_CString s4 ("dogbert"); if (s3 == s4){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} if (!(s3 < s4)){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} if (s3 > s4){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} ACE_CString s5 ("dogbert",3); ACE_CString s6 ("dogbert",5); if(s5 == s6){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} if(!(s5 < s6)){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} if(s5 > s6){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} ACE_CString s7 ("dogbert",4); ACE_CString s8 ("dogbert",2); if(s7 == s8){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} if(!(s7 > s8)){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} if(s7 < s8){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} ACE_CString s9 ("dogbert",3); ACE_CString s10 ("dogbert"); if(s9 == s10){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} if(!(s9 < s10)){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} if(s9 > s10){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} ACE_CString s11 ("dogbert",5); ACE_CString s12 ("dog"); if(s11 == s12){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} if(!(s11 > s12)){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} if(s11 < s12){ACE_ERROR((LM_ERROR,"Set #4:\n"));return 1;} s11.fast_clear (); if (s11.length () != 0) ACE_ERROR ((LM_ERROR, ACE_TEXT ("fast_clear didn't yield 0 length\n"))); } { // Set 1 for ACE_SString, which is not tested ACE_SString sstr; const char *old = sstr.rep (); const char *str = "What_a_day_it_has_been"; sstr.rep (const_cast<char *>(str)); ACE_SString tmp = sstr.substring (2, 300); if (tmp.length () == 300) ACE_ERROR ((LM_ERROR, "SString substring\n")); // Constring an ACE_SString without a character pointer or from an // existing ACE_SString causes memory to be allocated that will not // be delete (apparently by design). ACE_Allocator::instance ()->free (const_cast<char *> (old)); ACE_Allocator::instance ()->free (const_cast<char *> (tmp.rep ())); } int err = testConcatenation (); err += testIterator (); err += testConstIterator (); ACE_END_TEST; return err; }
int main () { // qse_openstdsios (); QSE::HeapMmgr heap_mmgr (QSE::Mmgr::getDFL(), 3000000); //QSE::RedBlackTable<int,int,IntHasher> int_table (&heap_mmgr, 1000); IntTable int_table (NULL, 1000); //IntTable int_table (NULL, 0); printf ("----------\n"); for (int i = 0; i < 100; i++) { int_table.insert (i, i * 20); } for (int i = 50; i < 150; i++) { int_table.upsert (i, i * 20); } printf ("----------\n"); /* qse_size_t bucket_size = int_table.getBucketSize(); for (qse_size_t i = 0; i < bucket_size; i++) { IntTable::Bucket* b = int_table.getBucket (i); } */ printf ("----------\n"); /* IntTable::Pair* pair = int_table.findPairWithCustomKey<IntClass,IntClassHasher,IntClassComparator> (IntClass(50)); if (pair) { printf ("pair found.... [%d]\n", pair->value); } */ printf ("%p %p\n", int_table.search (60), int_table.search (90)); printf ("%d %d\n", int_table.remove (60), int_table.remove (60)); printf ("%d %d\n", int_table.remove (70), int_table.remove (70)); /* printf ("%d\n", int_table[90]); printf ("%d\n", int_table[9990]); */ //Str1Table s1 (NULL, 1000); Str1Table s1 (NULL, 0); //Str1Table s1; s1.insert ("hello", 20); s1.insert ("hello", 20); s1.insert ("hello kara", 20); s1.insert ("this is good", 3896); printf ("remove = %d\n", s1.remove ("hello")); printf ("remove = %d\n", s1.remove ("hello")); for (int i = 0; i < 100; i++) { char buf[128]; sprintf (buf, "surukaaaa %d", i); s1.insert (buf, i * 2); } printf ("%d\n", (int)s1.getSize()); for (Str1Table::Iterator it = s1.getIterator(); it.isLegit(); it++) { Str1Table::Pair& pair = *it; printf ("[%s] [%d]\n", pair.key.c_str(), pair.value); } printf ("------------------\n"); { Str1Table s11 (s1); for (Str1Table::Iterator it = s11.getIterator(); it.isLegit(); it++) { Str1Table::Pair& pair = *it; printf ("[%s] [%d]\n", pair.key.c_str(), pair.value); } } printf ("------------------\n"); { Str1Table s11 (&heap_mmgr, 0); //Str1Table s11 (NULL, 200); //Str1Table s11; for (int i = 0; i < 100; i++) { char buf[128]; sprintf (buf, "abiyo %d", i); s11.insert (buf, i * 2); } printf ("%d\n", s11.heteroremove<const char*, cstr_comparator> ("abiyo 12")); printf ("%d\n", s11.heteroremove<const char*, cstr_comparator> ("abiyo 12")); printf ("SIZE => %d\n", (int)s11.getSize()); for (Str1Table::Iterator it = s11.getIterator(); it.isLegit(); it++) { Str1Table::Pair& pair = *it; printf ("[%s] [%d]\n", pair.key.c_str(), pair.value); } printf ("------------------\n"); //s11.clear (true); s11 = s1; printf ("SIZE => %d\n", (int)s11.getSize()); for (Str1Table::Iterator it = s11.getIterator(); it.isLegit(); it++) { Str1Table::Pair& pair = *it; printf ("[%s] [%d]\n", pair.key.c_str(), pair.value); } printf ("-------------------\n"); Str1Table::Pair* pair = s11.heterosearch<const char*, cstr_comparator> ("surukaaaa 13"); if (pair) printf ("%d\n", pair->value); else printf ("not found\n"); s11.update ("surukaaaa 13", 999); s11.update ("surukaaaa 16", 99999); s11.inject ("surukaaaa 18", 999999, 1); pair = s11.heterosearch<const char*, cstr_comparator> ("surukaaaa 13"); if (pair) printf ("%d\n", pair->value); else printf ("not found\n"); s1 = s11; } printf ("-------------------\n"); printf ("%d\n", (int)s1.getSize()); for (Str1Table::ConstIterator it = s1.getConstIterator(); it.isLegit(); it++) { const Str1Table::Pair& pair = *it; printf ("[%s] [%d]\n", pair.key.c_str(), pair.value); } printf ("-------------------\n"); #if 0 for (Str1Table::PairNode* np = s1.getTailNode(); np; np = np->getPrevNode()) { Str1Table::Pair& pair = np->value; printf ("[%s] [%d]\n", pair.key.c_str(), pair.value); } #endif // qse_closestdsios (); return 0; }
int SMatrix::createFormula(void) { bool *AVector; bool *BVector; int FormA, FormB, FormC, FormD; int count0, count1, count2, count3; int ChangeA, ChangeB; std::complex<double> A,B,C,D; int Row, Column; std::complex<double> Null_(0.0,0.0); std::complex<double> One_(1.0,0.0); if (FormulaExists_) return Formula.List.count(); fillMatrix(500e6); #ifdef DEBUG_ std::cout << print(); #endif count0=count1=count2=count3=0; AVector = (bool*) calloc(MatrixDimension_, sizeof(bool)); BVector = (bool*) calloc(MatrixDimension_, sizeof(bool)); for (int i=0; i<MatrixDimension_; i++) { *(AVector+i)=false; *(BVector+i)=false; } qHeapSort( ChopUp.List); #ifdef DEBUG_ std::cout << ChopUp.print() << std::endl; std::cout << "MatrixDimension: " << MatrixDimension_ << std::endl; #endif QValueList<ChopUpElement>::Iterator it; for ( it = ChopUp.List.begin(); it != ChopUp.List.end(); it++ ) { ChangeA = (*it).a()-1; ChangeB = (*it).b()-1; FormD = MatrixDimension_*ChangeB + ChangeA; D = *(SMatrix_+FormD); Row=0; while (Row < MatrixDimension_) { while ( ( (*(BVector+Row)) && (Row<MatrixDimension_) ) || (Row==ChangeB) ) Row++; if (Row<MatrixDimension_) { FormB=MatrixDimension_*Row+ChangeA; B = *(SMatrix_+FormB); if (B != Null_) { Column=0; while (Column < MatrixDimension_) { while ( ( (*(AVector+Column)) && (Column<MatrixDimension_) ) || (Column==ChangeA) ) Column++; if (Column<MatrixDimension_) { FormC = MatrixDimension_*ChangeB + Column; C = *(SMatrix_+FormC); if (C != Null_) { FormA = MatrixDimension_*Row + Column; A = *(SMatrix_ + FormA); #ifdef DEBUG_ std::cout << "*** Start of ChangeA: "<< ChangeA << " ChangeB: " << ChangeB << "\n"; std::cout << " A before: " << A << " <" << FormA << ">\n"; std::cout << " B: "<<B<<" <"<<FormB<<">\n"; std::cout << " C: "<<C<<" <"<<FormC<<">\n"; std::cout << " D: "<<D<<" <"<<FormD<<">\n"; std::cout << " Row: "<<Row<<" Column: "<<Column<<"\n"; #endif if ((A==Null_)&&(D==Null_)) { Formula.List.push_back(FormulaElement(0, FormA, FormB, FormC, FormD)); A = B*C; count0++; #ifdef DEBUG_ std::cout << " Formula 0: A=B*C\n"; #endif } else if ((A!=Null_)&&(D==Null_)) { Formula.List.push_back(FormulaElement(1, FormA, FormB, FormC, FormD)); A += B*C; count1++; #ifdef DEBUG_ std::cout << " Formula 1: A=A+B*C\n"; #endif } else if ((A==Null_)&&(D!=Null_)) { Formula.List.push_back(FormulaElement(2, FormA, FormB, FormC, FormD)); A = B*C/(One_-D); count2++; #ifdef DEBUG_ std::cout << " Formula 2: A=B*C/(1-D)\n"; #endif } else if ((A!=Null_)&&(D!=Null_)) { Formula.List.push_back(FormulaElement(3, FormA, FormB, FormC, FormD)); A += B*C/(One_-D); count3++; #ifdef DEBUG_ std::cout << " Formula 3: A=A+B*C/(1-D)\n"; #endif } *(SMatrix_+FormA)=A; #ifdef DEBUG_ std::cout << " A after: " << A << "<" << FormA << ">\n"; #endif } } Column++; } } } Row++; } *(BVector+ChangeB)=true; *(AVector+ChangeA)=true; } FormulaExists_=true; #ifdef DEBUG_ std::cout << S11_ << " " << S12_ << " " << S21_ << " " << S22_ << std::endl; std::cout << count0 << " " << count1 << " " << count2 << " " << count3 << " (" << count0+count1+count2+count3 << ")" << std::endl; std::cout << "S11: " << s11() << "\n"; std::cout << "S12: " << s12() << "\n"; std::cout << "S21: " << s21() << "\n"; std::cout << "S22: " << s22() << "\n"; std::cout << print(); #endif return Formula.List.count(); }