int main() { // 2 1 3 ListNode l1(2), l2(1), l3(3); ListNode l4(4), l5(2), l6(1), l7(6), l8(6), l9(9), l10(10), l11(11), l12(12), l13(6); ListNode n1(0), n2(0), n3(0), n4(1); l1.next = &l2; //l2.next = &l3; l4.next = &l5; l5.next = &l6; l6.next = &l7; l7.next = &l8; l8.next = &l9; l9.next = &l10; l10.next = &l11; l11.next = &l12; l12.next = &l13; print_list(&l1); Solution s; ListNode *result = s.removeNthFromEnd(&l1, 2); print_list(result); return 0; }
// // Save // ==== // // Save the information for this object to the AuditDataFile // bool CLocaleScanner::SaveData (CAuditDataFile* pAuditDataFile) { CLogFile log; log.Write("CLocaleScanner::SaveData Start" ,true); CString strValue; // Add the Category for memory CAuditDataFileCategory category(HARDWARE_CLASS); // Each audited item gets added an a CAuditDataFileItem to the category CAuditDataFileItem l1(V_LOCALE_CODEPAGE ,m_iCodePage); CAuditDataFileItem l2(V_LOCALE_CALENDARTYPE ,m_strCalendarType); CAuditDataFileItem l3(V_LOCALE_COUNTRY ,m_strCountry); CAuditDataFileItem l4(V_LOCALE_COUNTRYCODE ,m_iCountryCode); CAuditDataFileItem l5(V_LOCALE_CURRENCY ,m_strCurrency); CAuditDataFileItem l6(V_LOCALE_DATEFORMAT ,m_strDateFormat); CAuditDataFileItem l7(V_LOCALE_LANGUAGE ,m_strLanguage); CAuditDataFileItem l8(V_LOCALE_LOCALLANGUAGE ,m_strLocaleLocalLanguage); CAuditDataFileItem l9(V_LOCALE_OEM_CODEPAGE ,m_iOEMCodePage); CAuditDataFileItem l10(V_LOCALE_TIMEFORMAT ,m_strTimeFormat); CAuditDataFileItem l11(V_LOCALE_TIMEFORMATSPECIFIER ,m_strTimeFormatSpecifier); CAuditDataFileItem l12(V_LOCALE_TIMEZONE ,m_strLocaleTimeZone); // Add the items to the category category.AddItem(l1); category.AddItem(l2); category.AddItem(l3); category.AddItem(l4); category.AddItem(l5); category.AddItem(l6); category.AddItem(l7); category.AddItem(l8); category.AddItem(l9); category.AddItem(l10); category.AddItem(l11); category.AddItem(l12); // ...and add the category to the AuditDataFile pAuditDataFile->AddAuditDataFileItem(category); // we always need to get the default browser details so do here CAuditDataFileCategory browserCategory("Internet|Browsers|Default Browser", FALSE, TRUE); CAuditDataFileItem b1("Path", GetRegValue("HKEY_CLASSES_ROOT\\http\\shell\\open\\command", "")); browserCategory.AddItem(b1); pAuditDataFile->AddInternetItem(browserCategory); log.Write("CLocaleScanner::SaveData End" ,true); return true; }
void process_msg_prio_(int fd, char* msg, ssize_t len, struct game* g) { GList * conn_to_terminate = NULL; if (!g) g = find_game_by_fd(fd); if (g) { int i; for (i = 0; i < g->players_number; i++) { // Pings are for the server only. Don't broadcast them to save bandwidth. if (len == 3 && msg[1] == 'p') { // nada // Emitter wants to receive synchro message as well } else if (g->players_conn[i] == fd && len > 2 && msg[1] == '!') { char synchro4self[] = "?!\n"; ssize_t retval; synchro4self[0] = fd; l1(OUTPUT_TYPE_DEBUG, "[%d] sending self synchro", g->players_conn[i]); retval = send(g->players_conn[i], synchro4self, sizeof(synchro4self) - 1, MSG_NOSIGNAL|MSG_DONTWAIT); if (retval != sizeof(synchro4self) - 1) { if (retval != -1) { l4(OUTPUT_TYPE_INFO, "[%d] short send of %zd instead of %zd bytes from %d - destination is not reading data " "(illegal FB client) or our upload bandwidth is saturated - sorry, cannot continue serving " "this client in this situation, closing connection", g->players_conn[i], retval, sizeof(synchro4self) - 1, fd); } conn_to_terminate = g_list_append(conn_to_terminate, GINT_TO_POINTER(g->players_conn[i])); } } else if (g->players_conn[i] != fd) { ssize_t retval; l3(OUTPUT_TYPE_DEBUG, "[%d] sending %zd bytes to %d", fd, len, g->players_conn[i]); retval = send(g->players_conn[i], msg, len, MSG_NOSIGNAL|MSG_DONTWAIT); if (retval != len) { if (retval != -1) { l4(OUTPUT_TYPE_INFO, "[%d] short send of %zd instead of %zd bytes from %d - destination is not reading data " "(illegal FB client) or our upload bandwidth is saturated - sorry, cannot continue serving " "this client in this situation, closing connection", g->players_conn[i], retval, len, fd); } conn_to_terminate = g_list_append(conn_to_terminate, GINT_TO_POINTER(g->players_conn[i])); } } } if (conn_to_terminate) { g_list_foreach(conn_to_terminate, conn_to_terminate_helper, NULL); g_list_free(conn_to_terminate); } } else { l1(OUTPUT_TYPE_ERROR, "Internal error: could not find game by fd: %d", fd); exit(EXIT_FAILURE); } }
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; }
void SpiralScene::setupLights() { Color white(1, 1, 1); LightPointer l1(new Light(Vector3d(-3, 12, -15), 0)); l1->setAmbient(white * .2); l1->setDiffuse(white); l1->setSpecular(white); addLight(l1); LightPointer l2(new Light(Vector3d(-10, 10, -15), 0)); Color l2Color(.3, .8, .3); l2->setDiffuse(l2Color * .8); l2->setSpecular(l2Color); addLight(l2); LightPointer l3(new Light(Vector3d(10, 10, -50), 0)); Color l3Color(.3, .3, .8); l3->setDiffuse(l3Color * .9); l3->setSpecular(l3Color); addLight(l3); LightPointer l4(new Light(Vector3d(0, 0, -100), 0)); Color l4Color(.8, .3, .3); l4->setDiffuse(l4Color * .9); l4->setSpecular(l4Color); addLight(l4); }
TEST(TestMultipleSharedSection, General) { CSharedSection sec; CEvent event; std::atomic<long> mutex(0L); locker<CSharedLock> l1(sec,&mutex, &event); { CSharedLock lock(sec); thread waitThread1(l1); EXPECT_TRUE(waitForThread(mutex,1,10000)); SleepMillis(10); EXPECT_TRUE(l1.haslock); event.Set(); EXPECT_TRUE(waitThread1.timed_join(MILLIS(10000))); } locker<CSharedLock> l2(sec,&mutex,&event); locker<CSharedLock> l3(sec,&mutex,&event); locker<CSharedLock> l4(sec,&mutex,&event); locker<CSharedLock> l5(sec,&mutex,&event); { CExclusiveLock lock(sec); thread waitThread1(l2); thread waitThread2(l3); thread waitThread3(l4); thread waitThread4(l5); EXPECT_TRUE(waitForThread(mutex,4,10000)); SleepMillis(10); EXPECT_TRUE(!l2.haslock); EXPECT_TRUE(!l3.haslock); EXPECT_TRUE(!l4.haslock); EXPECT_TRUE(!l5.haslock); lock.Leave(); EXPECT_TRUE(waitForWaiters(event,4,10000)); EXPECT_TRUE(l2.haslock); EXPECT_TRUE(l3.haslock); EXPECT_TRUE(l4.haslock); EXPECT_TRUE(l5.haslock); event.Set(); EXPECT_TRUE(waitThread1.timed_join(MILLIS(10000))); EXPECT_TRUE(waitThread2.timed_join(MILLIS(10000))); EXPECT_TRUE(waitThread3.timed_join(MILLIS(10000))); EXPECT_TRUE(waitThread4.timed_join(MILLIS(10000))); } }
void test_switch_by_csw() { ngdc dc("dc1", 5); ngspst spst("spst", ngspst::on); ngresistor r("1", 5); ngled led("led"); ngground gnd; ngline l1(dc.pos, spst.p1); ngline l2(spst.p2, r.p1); ngline l3(r.p2, led.pos); ngline l4(led.neg, dc.neg); ngline l0(dc.neg, gnd.ground); schema sch; sch.AddDevices(&dc, &spst, &r, &gnd, &led, 0); sch.AddLines(&l1, &l2, &l3, &l0, &l4, 0); circuit cir(&sch); #if 0//not work // tran with spst disconnected cir.Tran("10", "1m"); do { Sleep(100); } while (cir.IsRunning()); //cir.Stop(); // tran with spst connected, however it's still disconnected string sw = spst.switchover(); cir.Do(sw); cir.Tran("10", "1m"); do { Sleep(100); } while (cir.IsRunning()); #endif // run with event input to switch spst cir.Tran("1t", "1m", 0); do { Sleep(200); char ch = getchar(); switch (ch) { case 'a': cir.SwitchOver(&spst); Sleep(200); break; case 'q': cir.Halt(); default: break; }; } while (cir.IsRunning()); }
void test(int i) { Literal<int> l1; // expected-warning {{unused variable 'l1'}} Literal<int> l2(42); // expected-warning {{unused variable 'l2'}} Literal<int> l3(i); // no-warning Literal<T> l4(0); // no-warning NoLiteral nl1; // no-warning NoLiteral nl2(42); // no-warning }
void l4__Wrapper() { int tape_index__ANONYMOUS_s100=0; glblInit_tape_index__ANONYMOUS_s110(tape_index__ANONYMOUS_s100); bool _tt0[143] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; bool* tape__ANONYMOUS_s99= new bool [143]; CopyArr<bool >(tape__ANONYMOUS_s99,_tt0, 143, 143); glblInit_tape__ANONYMOUS_s108(tape__ANONYMOUS_s99); l4(tape__ANONYMOUS_s99, tape_index__ANONYMOUS_s100); delete[] tape__ANONYMOUS_s99; }
/* List */ void challenge() { int numbers[] = { 1, 2, 3, 4, 5 }; list<int> l1(numbers, numbers + 5); print<list<int> >(l1); list<int> l2; for (int i = 0; i < 10; ++i) { l2.push_back(i); } print<list<int> >(l2); for (int i = 0; i < 10; ++i) { l2.push_front(i); } print<list<int> >(l2); for (int i = 0; i < 10; ++i) { l2.pop_front(); } print<list<int> >(l2); for (int i = 0; i < 10; ++i) { l2.pop_back(); } print<list<int> >(l2); list<int> l3 (numbers, numbers + 5); // O(1) l3.erase(l3.begin()); print<list<int> >(l3); // O(n), n = distance(begin, end) l3.erase(l3.begin(), l3.end()); print<list<int> >(l3); // List operations list<int> l4 (numbers, numbers + 5); list<int> l5 (numbers, numbers + 5); // O(size() + size() - 1) l4.merge(l5); print<list<int> >(l4); print<list<int> >(l5); // Empty list<int> l6 (numbers, numbers + 5); print<list<int> >(l6); // O(n) l6.reverse(); print<list<int> >(l6); // O(nlog(n)) l6.sort(); print<list<int> >(l6); print<list<int> >(l4); // O(n) l4.unique(); print<list<int> >(l4); }
int main() { try { symbol k("k"),q("q"),p("p"),p1("p1"),p2("p2"),p3("p3"),ms("ms"),l("l"),s("s"),m1s("m1s"),m2s("m2s"),m3s("m3s"); symbol l1("l1"),l2("l2"),l3("l3"),l4("l4"),t("t"),p4("p4"),p5("p5"),p6("p6"),tp("tp"),v1("v1"),v2("v2"),l5("l5"); symbol k1("k1"),k2("k2"),k3("k3"),k4("k4"),k5("k5"),ms1("ms1"),ms2("ms2"),ms3("ms3"),ms4("ms4"); symbol s12("s12"),s23("s23"),s34("s34"),s45("s45"),s51("s51"),s13("s13"),s15("s15"),s56("s56"),s16("s16"),s123("s123"),s234("s234"),s345("s345"); lst inv_l; inv_l.append(p1*p1 == 0); inv_l.append( p2*p2 == 0);inv_l.append( p3*p3 == 0);inv_l.append( p4*p4 == 0);inv_l.append( p5*p5 == 0);inv_l.append( p6*p6 == 0); inv_l.append(p1* p2 == s12/2);inv_l.append( p2* p3 == s23/2);inv_l.append( p3* p4 == s34/2);inv_l.append( p4* p5 == s45/2); inv_l.append(p5* p6 == s56/2);inv_l.append( p1* p6 == s16/2);inv_l.append( p1* p3 == (-s12 + s123 - s23)/2); inv_l.append(p2* p4 == (-s23 + s234 - s34)/2); inv_l.append( p3* p5 == (-s34 + s345 - s45)/2); inv_l.append(p1* p4 == (-s123 + s23 - s234 + s56)/2); inv_l.append(p1* p5 == (-s16 + s234 - s56)/2); inv_l.append( p2* p5 == (s16 - s234 + s34 - s345)/2); inv_l.append( p2* p6 == (-s12 - s16 + s345)/2); inv_l.append( p3* p6 == (s12 - s123 - s345 + s45)/2); inv_l.append( p4* p6 == (s123 - s45 - s56)/2); RoMB_loop_by_loop hexag(lst(k1), lst(-pow(p1 + k1,2),-pow(p1 + p2 + k1,2), -pow(p1 + p2 + p3 + k1,2), -pow(p1 + p2 + p3 + p4 + k1,2), -pow(p1+p2+p3+p4+p5+k1,2),-pow(k1,2)), inv_l, lst(1,1,1,1,1,1),true); hexag.integrate_map(lst(s12 == -1, s23 == -2, s34 == -3, s45 == -4, s56 == -5, s16 == -6, s123 == -7, s234 == -8, s345 == -9)); /* FRESULT for parameters: {s12==-1,s23==-2,s34==-3,s45==-4,s56==-5,s16==-6,s123==-7,s234==-8,s345==-9} FRESULT anl : = -0.1955084880526298663-1/240*log(8)*log(6)+947/60480*log(2)^2-1/480*log(6)*log(4)+1/1080*log(3)*log(7)+131/7560*log(9)*log(2)+19/1260*log(9)^2-1/560*log(8)*log(4)+523/60480*log(3)^2-1/1080*log(7)*log(5)+41/4320*log(3)*log(5)-1/48*log(8)*log(5)-1/1080*log(7)*log(4)+22/945*log(6)*log(7)+19/3780*log(3)*log(4)+493/30240*Pi^2+43/1008*eps^(-2)+49/8640*log(5)^2-641/30240*log(2)*log(6)+1/1080*log(9)*log(5)-22/945*log(2)*log(7)+271/60480*log(4)^2-3/112*log(8)*log(3)-19/3780*log(9)*log(4)+1/1080*log(4)*log(5)-61/2520*log(9)*log(7)+61/5040*log(7)^2+1/168*log(3)*log(2)+1/168*log(8)*log(9)+13/3360*log(2)*log(4)-1/30240*(-1132.7960047725738361+576*log(8)-163*log(3)+264*log(9)+533*log(2)-479*log(6)-444*log(7)+271*log(4)-287*log(5))*eps^(-1)+47/1680*log(8)^2-17/1680*log(8)*log(2)+767/60480*log(6)^2-22/945*log(9)*log(6)-13/1890*log(3)*log(9) FRESULT num: = 1.9907333428263254975E-4+(0.032177795803854872908)*eps^(-1)+(0.04265873015873015873)*eps^(-2) eps^-2 term: 43/1008 +/- 0 eps^-1 term: 0.03746018534300839405-2/105*log(8)+163/30240*log(3)-11/1260*log(9)-533/30240*log(2)+479/30240*log(6)+37/2520*log(7)-271/30240*log(4)+41/4320*log(5) +/- 9.022403780167233619E-6 eps^0 term: -0.1955084880526298663-1/240*log(8)*log(6)+947/60480*log(2)^2-1/480*log(6)*log(4)+1/1080*log(3)*log(7)+131/7560*log(9)*log(2)+19/1260*log(9)^2-1/560*log(8)*log(4)+523/60480*log(3)^2-1/1080*log(7)*log(5)+41/4320*log(3)*log(5)-1/48*log(8)*log(5)-1/1080*log(7)*log(4)+22/945*log(6)*log(7)+19/3780*log(3)*log(4)+493/30240*Pi^2+49/8640*log(5)^2-641/30240*log(2)*log(6)+1/1080*log(9)*log(5)-22/945*log(2)*log(7)+271/60480*log(4)^2-3/112*log(8)*log(3)-19/3780*log(9)*log(4)+1/1080*log(4)*log(5)-61/2520*log(9)*log(7)+61/5040*log(7)^2+1/168*log(3)*log(2)+1/168*log(8)*log(9)+13/3360*log(2)*log(4)+47/1680*log(8)^2-17/1680*log(8)*log(2)+767/60480*log(6)^2-22/945*log(9)*log(6)-13/1890*log(3)*log(9) +/- 1.04620404922048185285E-4 */ } catch(std::exception &p) { std::cerr<<"******************************************************************"<<endl; std::cerr<<" >>>ERROR: "<<p.what()<<endl; std::cerr<<"******************************************************************"<<endl; return 1; } return 0; }
MatrixXd Utils::calculateHomographyMatrixFromFiveOrtoghonalLines(QList<Line*> firstOrtoghonalLines, QList<Line*> secondOrthogonalLines, QList<Line*> thirdOrthogonalLines, QList<Line*> fourthOrthogonalLines, QList<Line*> fifthOrthogonalLines) { // A * x = b. MatrixXd A(5, 6); MatrixXd b(5, 1); MatrixXd x(5, 1); Vector3d l1 = getLineInHomogeneousCoordinates(firstOrtoghonalLines.at(0)); Vector3d m1 = getLineInHomogeneousCoordinates(firstOrtoghonalLines.at(1)); Vector3d l2 = getLineInHomogeneousCoordinates(secondOrthogonalLines.at(0)); Vector3d m2 = getLineInHomogeneousCoordinates(secondOrthogonalLines.at(1)); Vector3d l3 = getLineInHomogeneousCoordinates(thirdOrthogonalLines.at(0)); Vector3d m3 = getLineInHomogeneousCoordinates(thirdOrthogonalLines.at(1)); Vector3d l4 = getLineInHomogeneousCoordinates(fourthOrthogonalLines.at(0)); Vector3d m4 = getLineInHomogeneousCoordinates(fourthOrthogonalLines.at(1)); Vector3d l5 = getLineInHomogeneousCoordinates(fifthOrthogonalLines.at(0)); Vector3d m5 = getLineInHomogeneousCoordinates(fifthOrthogonalLines.at(1)); b << -l1(1)*m1(1), -l2(1)*m2(1), -l3(1)*m3(1), -l4(1)*m4(1), -l5(1)*m5(1); A << l1(0)*m1(0), (l1(0)*m1(1)+l1(1)*m1(0))/2, l1(1)*m1(1), (l1(0)*m1(2)+l1(2)*m1(0))/2, (l1(1)*m1(2)+l1(2)*m1(1))/2, l1(2)*m1(2), l2(0)*m2(0), (l2(0)*m2(1)+l2(1)*m2(0))/2, l2(1)*m2(1), (l2(0)*m2(2)+l2(2)*m2(0))/2, (l2(1)*m2(2)+l2(2)*m2(1))/2, l2(2)*m2(2), l3(0)*m3(0), (l3(0)*m3(1)+l3(1)*m3(0))/2, l3(1)*m3(1), (l3(0)*m3(2)+l3(2)*m3(0))/2, (l3(1)*m3(2)+l3(2)*m3(1))/2, l3(2)*m3(2), l4(0)*m4(0), (l4(0)*m4(1)+l4(1)*m4(0))/2, l4(1)*m4(1), (l4(0)*m4(2)+l4(2)*m4(0))/2, (l4(1)*m4(2)+l4(2)*m4(1))/2, l4(2)*m4(2), l5(0)*m5(0), (l5(0)*m5(1)+l5(1)*m5(0))/2, l5(1)*m5(1), (l5(0)*m5(2)+l5(2)*m5(0))/2, (l5(1)*m5(2)+l5(2)*m5(1))/2, l5(2)*m5(2); x = A.colPivHouseholderQr().solve(b); x/=x(2); Matrix3d C; C << x(0), x(1)/2, x(3)/2, x(1)/2, x(2), x(4)/2, x(3)/2, x(4)/2, 1; Matrix2d kkt; kkt << C(0,0), C(0,1), C(1,0), C(1,1); MatrixXd vKKt(1,2); vKKt << C(2,0), C(2,1); MatrixXd V(1,2); V = vKKt * kkt.inverse(); LLT<MatrixXd> llt(kkt); MatrixXd U = llt.matrixU(); MatrixXd J (3,3); J << U(0,0), U(0,1),0, U(1,0), U(1,1),0, V(0), V(1), 1; return J; }
void JViewSet::addRect(double x, double y, double width, double height) { JFPoint p1(x, y); JFPoint p2(x+width, y); JFPoint p3(x+width, y+height); JFPoint p4(x, y+height); JLineObj l1(p1, p2); JLineObj l2(p2, p3); JLineObj l3(p3, p4); JLineObj l4(p4, p1); add(l1); add(l2); add(l3); add(l4); }
void test_try_lock_five() { int const num_mutexes=5; for(int i=-1;i<num_mutexes;++i) { dummy_mutex mutexes[num_mutexes]; if(i>=0) { mutexes[i].lock(); } boost::unique_lock<dummy_mutex> l1(mutexes[0],boost::defer_lock), l2(mutexes[1],boost::defer_lock), l3(mutexes[2],boost::defer_lock), l4(mutexes[3],boost::defer_lock), l5(mutexes[4],boost::defer_lock); int const res=boost::try_lock(l1,l2,l3,l4,l5); BOOST_CHECK(res==i); for(int j=0;j<num_mutexes;++j) { if((i==j) || (i==-1)) { BOOST_CHECK(mutexes[j].is_locked); } else { BOOST_CHECK(!mutexes[j].is_locked); } } if(i==-1) { BOOST_CHECK(l1.owns_lock()); BOOST_CHECK(l2.owns_lock()); BOOST_CHECK(l3.owns_lock()); BOOST_CHECK(l4.owns_lock()); BOOST_CHECK(l5.owns_lock()); } else { BOOST_CHECK(!l1.owns_lock()); BOOST_CHECK(!l2.owns_lock()); BOOST_CHECK(!l3.owns_lock()); BOOST_CHECK(!l4.owns_lock()); BOOST_CHECK(!l5.owns_lock()); } } }
void lock_five_mutexes_slowly(boost::mutex* m1,boost::mutex* m2,boost::mutex* m3,boost::mutex* m4,boost::mutex* m5, wait_data* locked,wait_data* quit) { boost::lock_guard<boost::mutex> l1(*m1); boost::this_thread::sleep(boost::posix_time::milliseconds(500)); boost::lock_guard<boost::mutex> l2(*m2); boost::this_thread::sleep(boost::posix_time::milliseconds(500)); boost::lock_guard<boost::mutex> l3(*m3); boost::this_thread::sleep(boost::posix_time::milliseconds(500)); boost::lock_guard<boost::mutex> l4(*m4); boost::this_thread::sleep(boost::posix_time::milliseconds(500)); boost::lock_guard<boost::mutex> l5(*m5); locked->signal(); quit->wait(); }
void test_spdt() { //创建所需元器件 ngdc dc("dc1", 5); ngspdt spdt("spdt", ngspdt::status_throw1); ngresistor r1("1", 5); ngresistor r2("2", 5); ngled led1("led1"); ngled led2("led2"); ngground gnd; //创建接线,连接各元器件 ngline l1(dc.pos, spdt.pole); ngline l2(spdt.throw1, r1.p1); ngline l3(spdt.throw2, r2.p1); ngline l4(r1.p2, led1.pos); ngline l5(r2.p2, led2.pos); ngline l6(led1.neg, dc.neg); ngline l7(led2.neg, dc.neg); ngline l0(dc.neg, gnd.ground); //创建电路图,添加元器件、接线到电路图 schema sch; sch.AddDevices(&dc, &spdt, &r1, &r2, &led1, &led2, &gnd, 0); sch.AddLines(&l1, &l2, &l3, &l4, &l5, &l6, &l7, &l0, 0); //创建仿真对象,添加电路图,并开始暂态仿真 circuit cir(&sch); cir.Tran("1t", "1m", 0); do { Sleep(200); char ch = getchar(); switch (ch) { case 'a': cir.SwitchOver(&spdt); Sleep(200); break; case 'q': cir.Halt(); default: break; }; } while (cir.IsRunning()); //主程序线程,类似windows UI消息循环 }
void testCase1(){ stdL<int> l1(10, 0); tsL<int> l2(10, 0); assert(TinySTL::Test::container_equal(l1, l2)); int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; stdL<int> l3(std::begin(arr), std::end(arr)); tsL<int> l4(std::begin(arr), std::end(arr)); assert(TinySTL::Test::container_equal(l3, l4)); auto l5(l1); auto l6(l2); assert(TinySTL::Test::container_equal(l5, l6)); auto l7 = l1; auto l8 = l2; assert(TinySTL::Test::container_equal(l7, l8)); }
int main(){ ListNode l0(0); ListNode l1(5); ListNode l2(2); ListNode l3(3); ListNode l4(4); ListNode l5(1); ListNode l6(6); l0.next = &l1; l1.next = &l2; l2.next = &l3; l3.next = &l4; l4.next = &l5; l5.next = &l6; ListNode* curr = sortList(&l0); while(curr){ printf("%d ", curr->val); curr = curr->next; } printf("\n"); return 0; }
TEST(Line, length) { Line l1(1,0, 0,0); EXPECT_EQ(1, l1.getLength()); Line l2(0,1, 0,0); EXPECT_EQ(1, l2.getLength()); Line l3(0,0, 1,0); EXPECT_EQ(1, l3.getLength()); Line l4(0,0, 0,1); EXPECT_EQ(1, l4.getLength()); Line l5(1,1, 1,1); EXPECT_EQ(0, l5.getLength()); Line l6(0,0, 1,1); EXPECT_EQ(std::sqrt(2), l6.getLength()); }
void test_switch_by_resistor() { ngdc dc("dc", 10); ngresistor r("r1", 370); ngled led("led1", 5e-3); ngswitch sw("sw", ngswitch::off); ngground gnd; ngline l0(dc.neg, gnd.p1); ngline l1(dc.pos, r.p1); ngline l2(r.p2, led.p1); ngline l3(led.p2, sw.p1); ngline l4(sw.p2, dc.neg); schema sch; sch.AddDevices(&dc, &r, &led, &gnd, &sw, 0); sch.AddLines(&l0, &l1, &l2, &l3, &l4, 0); circuit cir(&sch); cir.Tran("1t", "1m"); do { Sleep(200); char ch = getchar(); switch (ch) { case 'a': cir.SwitchOver(&sw); Sleep(200); break; case 'q': cir.Halt(); default: break; }; } while (cir.IsRunning()); }
int main() { Solution s; ListNode *ret; ListNode l1(1); ListNode l2(2); ListNode l3(3); ListNode l4(4); ListNode l5(5); l1.next = &l2; l2.next = &l3; l3.next = &l4; l4.next = &l5; ret = s.removeNthFromEnd(&l1, 2); while (ret) { std::cout << ret->val << ","; ret = ret->next; } std::cout << std::endl; }
void test_lock_five_uncontended() { boost::fibers::mutex m1,m2,m3,m4,m5; boost::fibers::mutex::scoped_lock l1(m1,boost::defer_lock), l2(m2,boost::defer_lock), l3(m3,boost::defer_lock), l4(m4,boost::defer_lock), l5(m5,boost::defer_lock); BOOST_CHECK(!l1.owns_lock()); BOOST_CHECK(!l2.owns_lock()); BOOST_CHECK(!l3.owns_lock()); BOOST_CHECK(!l4.owns_lock()); BOOST_CHECK(!l5.owns_lock()); boost::lock(l1,l2,l3,l4,l5); BOOST_CHECK(l1.owns_lock()); BOOST_CHECK(l2.owns_lock()); BOOST_CHECK(l3.owns_lock()); BOOST_CHECK(l4.owns_lock()); BOOST_CHECK(l5.owns_lock()); }
void testCase14(){ stdL<int> l1(10, 0), l3(10, 1); tsL<int> l2(10, 0), l4(10, 1); l1.splice(l1.begin(), l3); l2.splice(l2.begin(), l4); assert(TinySTL::Test::container_equal(l1, l2)); auto l5 = l1; auto l6 = l2; l1.splice(l1.end(), l5, l5.begin()); l2.splice(l2.end(), l6, l6.begin()); assert(TinySTL::Test::container_equal(l1, l2)); auto it1 = l1.begin(); auto it2 = l2.begin(); for (auto i = 0; i != l1.size() / 2; ++i){ ++it1; ++it2; } l1.splice(it1, l5, l5.begin(), l5.end()); l2.splice(it2, l6, l6.begin(), l6.end()); assert(TinySTL::Test::container_equal(l1, l2)); }
int main(int argc, char **argv) { plan_tests(92); // test constructor GeoPoint p1(Angle::Degrees(345.32), Angle::Degrees(-6.332)); ok1(p1.IsValid()); ok1(equals(p1, -6.332, 345.32)); // test normalize() p1.Normalize(); ok1(p1.IsValid()); ok1(equals(p1, -6.332, -14.68)); // test parametric() GeoPoint p2(Angle::Degrees(2), Angle::Degrees(1)); GeoPoint p3 = p1.Parametric(p2, 5); ok1(p2.IsValid()); ok1(p3.IsValid()); ok1(equals(p3, -1.332, -4.68)); // test interpolate GeoPoint p4 = p1.Interpolate(p3, 0.5); ok1(p4.IsValid()); ok1(equals(p4, -3.832, -9.68)); GeoPoint p5 = p1.Interpolate(p3, 0.25); ok1(p5.IsValid()); ok1(equals(p5, -5.082, -12.18)); // test * GeoPoint p6 = p2 * 3.5; ok1(p6.IsValid()); ok1(equals(p6, 3.5, 7)); // test + p6 = p6 + p2; ok1(p6.IsValid()); ok1(equals(p6, 4.5, 9)); // test += p6 += p2; ok1(p6.IsValid()); ok1(equals(p6, 5.5, 11)); // test - p6 = p6 - p2; ok1(p6.IsValid()); ok1(equals(p6, 4.5, 9)); // for large and short distance testing GeoPoint p11(Angle::Degrees(0.00001), Angle::Degrees(0.00001)); GeoPoint p12(Angle::Degrees(179), Angle::Degrees(0)); p11 += p1; p12 += p1; ok1(p11.IsValid()); ok1(equals(p11, -6.33199, -14.67999)); ok1(p12.IsValid()); ok1(equals(p12, -6.332, 164.32)); // test sort() ok1(!p1.Sort(p3)); ok1(p3.Sort(p1)); ok1(!p1.Sort(p4)); ok1(p4.Sort(p1)); ok1(!p1.Sort(p5)); ok1(p5.Sort(p1)); ok1(!p4.Sort(p3)); ok1(p3.Sort(p4)); ok1(!p5.Sort(p3)); ok1(p3.Sort(p5)); ok1(!p5.Sort(p4)); ok1(p4.Sort(p5)); // test distance() // // note: distance between p1 and p4 and between p3 and p4 is not // the same due to linear interpolation instead of real geographic // intermediate point calculation ok1(equals(p2.Distance(p6), 869146.334126)); ok1(equals(p6.Distance(p2), 869146.334126)); ok1(equals(p1.Distance(p5), 309506.275043)); ok1(equals(p1.Distance(p4), 619486.719361)); ok1(equals(p1.Distance(p3), 1240403.22926)); ok1(equals(p3.Distance(p4), 620924.169000)); ok1(equals(p1.Distance(p11), 1.561761)); ok1(equals(p1.Distance(p12), 18599361.600)); ok1(equals(p2.DistanceS(p6), 869326.653160)); ok1(equals(p6.DistanceS(p2), 869326.653160)); ok1(equals(p1.DistanceS(p5), 309562.219016)); ok1(equals(p1.DistanceS(p4), 619603.149273)); ok1(equals(p1.DistanceS(p3), 1240649.267606)); ok1(equals(p3.DistanceS(p4), 621053.760625)); ok1(equals(p1.DistanceS(p11), 1.568588)); ok1(equals(p1.DistanceS(p12), 18602548.701)); // test bearing() // // note: the bearings p1 -> p5, p5 -> p4 and so on are not the same due to // linear interpolation instead of real geographic intermediate point // calculation ok1(equals(p2.Bearing(p6), 63.425773)); ok1(equals(p6.Bearing(p2), 243.762198)); ok1(equals(p1.Bearing(p5), 63.601900)); ok1(equals(p1.Bearing(p4), 63.735395)); ok1(equals(p1.Bearing(p3), 63.937616)); ok1(equals(p5.Bearing(p4), 63.619712)); ok1(equals(p5.Bearing(p3), 63.799336)); ok1(equals(p4.Bearing(p3), 63.694155)); ok1(equals(p5.Bearing(p6), 66.126880)); ok1(equals(p2.Bearing(p3), 250.886912)); ok1(equals(p2.BearingS(p6), 63.272424)); ok1(equals(p6.BearingS(p2), 243.608847)); ok1(equals(p1.BearingS(p5), 63.449343)); ok1(equals(p1.BearingS(p4), 63.582620)); ok1(equals(p1.BearingS(p3), 63.784526)); ok1(equals(p5.BearingS(p4), 63.466726)); ok1(equals(p5.BearingS(p3), 63.646072)); ok1(equals(p4.BearingS(p3), 63.540756)); ok1(equals(p5.BearingS(p6), 65.982854)); ok1(equals(p2.BearingS(p3), 250.786774)); // test distance_bearing() // note: should be the same output as bearing() and distance() GeoVector v = p2.DistanceBearing(p6); ok1(equals(v.distance, 869146.334126)); ok1(equals(v.bearing, 63.425773)); v = p2.DistanceBearingS(p6); ok1(equals(v.distance, 869326.653160)); ok1(equals(v.bearing, 63.272424)); // test intermediate_point() GeoPoint p7(Angle::Zero(), Angle::Zero()); ok1(p7.IsValid()); GeoPoint p8 = p7.IntermediatePoint(p2, 100000); ok1(p8.IsValid()); ok1(equals(p8, 0.402361, 0.804516)); ok1(equals(p8.Distance(p7), 100000)); GeoPoint p9 = p7.IntermediatePoint(p2, 100000000); ok1(p9.IsValid()); ok1(equals(p9, p2)); // test projected_distance() ok1(equals(p8.ProjectedDistance(p7, p2), 100000)); ok1(equals(p4.ProjectedDistance(p1, p3), 619494.517917)); ok1(equals((p2 * 2).ProjectedDistance(p2, p6), 248511.833322)); // Tests moved here from test_fixed.cpp GeoPoint l1(Angle::Zero(), Angle::Zero()); ok1(l1.IsValid()); GeoPoint l2(Angle::Degrees(-0.3), Angle::Degrees(1.0)); ok1(l2.IsValid()); GeoPoint l3(Angle::Degrees(0.00001), Angle::Zero()); ok1(l3.IsValid()); GeoPoint l4(Angle::Degrees(10), Angle::Zero()); ok1(l4.IsValid()); l4.SetInvalid(); ok1(!l4.IsValid()); bool find_lat_lon_okay = true; for (Angle bearing = Angle::Zero(); bearing < Angle::FullCircle(); bearing += Angle::Degrees(5)) { GeoPoint p_test = FindLatitudeLongitude(p1, bearing, 50000); find_lat_lon_okay = equals(p_test.Distance(p1), 50000) && find_lat_lon_okay; } ok1(find_lat_lon_okay); v = l1.DistanceBearing(l2); // 116090 @ 343 v = l1.DistanceBearing(l3); ok(v.distance > 0 && v.distance < 2, "earth distance short", 0); GeoPoint p10(GeoPoint::Invalid()); ok1(!p10.IsValid()); return exit_status(); }
void TestBandMatrixArith_D1() { std::vector<tmv::BandMatrixView<T> > b; std::vector<tmv::BandMatrixView<std::complex<T> > > cb; MakeBandList(b,cb); const int N = b[0].rowsize(); tmv::Matrix<T> a1(N,N); for (int i=0; i<N; ++i) for (int j=0; j<N; ++j) a1(i,j) = T(3+i-5*j); tmv::Matrix<std::complex<T> > ca1(N,N); for (int i=0; i<N; ++i) for (int j=0; j<N; ++j) ca1(i,j) = std::complex<T>(3+i-5*j,4-8*i-j); tmv::UpperTriMatrix<T,tmv::NonUnitDiag|tmv::RowMajor> u1(a1); tmv::UpperTriMatrix<std::complex<T>,tmv::NonUnitDiag|tmv::RowMajor> cu1(ca1); tmv::UpperTriMatrixView<T> u1v = u1.view(); tmv::UpperTriMatrixView<std::complex<T> > cu1v = cu1.view(); tmv::UpperTriMatrix<T,tmv::NonUnitDiag> u1x = u1v; tmv::UpperTriMatrix<std::complex<T>,tmv::NonUnitDiag> cu1x = cu1v; #if (XTEST & 2) tmv::UpperTriMatrix<T,tmv::UnitDiag|tmv::RowMajor> u2(a1); tmv::UpperTriMatrix<T,tmv::NonUnitDiag|tmv::ColMajor> u3(a1); tmv::UpperTriMatrix<T,tmv::UnitDiag|tmv::ColMajor> u4(a1); tmv::LowerTriMatrix<T,tmv::NonUnitDiag|tmv::RowMajor> l1(a1); tmv::LowerTriMatrix<T,tmv::UnitDiag|tmv::RowMajor> l2(a1); tmv::LowerTriMatrix<T,tmv::NonUnitDiag|tmv::ColMajor> l3(a1); tmv::LowerTriMatrix<T,tmv::UnitDiag|tmv::ColMajor> l4(a1); tmv::UpperTriMatrix<std::complex<T>,tmv::UnitDiag|tmv::RowMajor> cu2(ca1); tmv::UpperTriMatrix<std::complex<T>,tmv::NonUnitDiag|tmv::ColMajor> cu3(ca1); tmv::UpperTriMatrix<std::complex<T>,tmv::UnitDiag|tmv::ColMajor> cu4(ca1); tmv::LowerTriMatrix<std::complex<T>,tmv::NonUnitDiag|tmv::RowMajor> cl1(ca1); tmv::LowerTriMatrix<std::complex<T>,tmv::UnitDiag|tmv::RowMajor> cl2(ca1); tmv::LowerTriMatrix<std::complex<T>,tmv::NonUnitDiag|tmv::ColMajor> cl3(ca1); tmv::LowerTriMatrix<std::complex<T>,tmv::UnitDiag|tmv::ColMajor> cl4(ca1); tmv::UpperTriMatrixView<T> u2v = u2.view(); tmv::UpperTriMatrixView<T> u3v = u3.view(); tmv::UpperTriMatrixView<T> u4v = u4.view(); tmv::LowerTriMatrixView<T> l1v = l1.view(); tmv::LowerTriMatrixView<T> l2v = l2.view(); tmv::LowerTriMatrixView<T> l3v = l3.view(); tmv::LowerTriMatrixView<T> l4v = l4.view(); tmv::UpperTriMatrixView<std::complex<T> > cu2v = cu2.view(); tmv::UpperTriMatrixView<std::complex<T> > cu3v = cu3.view(); tmv::UpperTriMatrixView<std::complex<T> > cu4v = cu4.view(); tmv::LowerTriMatrixView<std::complex<T> > cl1v = cl1.view(); tmv::LowerTriMatrixView<std::complex<T> > cl2v = cl2.view(); tmv::LowerTriMatrixView<std::complex<T> > cl3v = cl3.view(); tmv::LowerTriMatrixView<std::complex<T> > cl4v = cl4.view(); #endif for(size_t i=START;i<b.size();i++) { if (showstartdone) { std::cerr<<"Start loop "<<i<<std::endl; std::cerr<<"bi = "<<b[i]<<std::endl; } tmv::BandMatrixView<T> bi = b[i]; tmv::BandMatrixView<std::complex<T> > cbi = cb[i]; TestMatrixArith4(bi,cbi,u1v,cu1v,"Band/UpperTri"); TestMatrixArith5(bi,cbi,u1v,cu1v,"Band/UpperTri"); TestMatrixArith6x(bi,cbi,u1v,cu1v,"Band/UpperTri"); #if (XTEST & 2) TestMatrixArith4(bi,cbi,l1v,cl1v,"Band/LowerTri"); TestMatrixArith5(bi,cbi,l1v,cl1v,"Band/LowerTri"); TestMatrixArith6x(bi,cbi,l1v,cl1v,"Band/LowerTri"); TestMatrixArith4(bi,cbi,u2v,cu2v,"Band/UpperTri"); TestMatrixArith5(bi,cbi,u2v,cu2v,"Band/UpperTri"); TestMatrixArith6x(bi,cbi,u2v,cu2v,"Band/UpperTri"); TestMatrixArith4(bi,cbi,l2v,cl2v,"Band/LowerTri"); TestMatrixArith5(bi,cbi,l2v,cl2v,"Band/LowerTri"); TestMatrixArith6x(bi,cbi,l2v,cl2v,"Band/LowerTri"); TestMatrixArith4(bi,cbi,u3v,cu3v,"Band/UpperTri"); TestMatrixArith5(bi,cbi,u3v,cu3v,"Band/UpperTri"); TestMatrixArith6x(bi,cbi,u3v,cu3v,"Band/UpperTri"); TestMatrixArith4(bi,cbi,l3v,cl3v,"Band/LowerTri"); TestMatrixArith5(bi,cbi,l3v,cl3v,"Band/LowerTri"); TestMatrixArith6x(bi,cbi,l3v,cl3v,"Band/LowerTri"); TestMatrixArith4(bi,cbi,u4v,cu4v,"Band/UpperTri"); TestMatrixArith5(bi,cbi,u4v,cu4v,"Band/UpperTri"); TestMatrixArith6x(bi,cbi,u4v,cu4v,"Band/UpperTri"); TestMatrixArith4(bi,cbi,l4v,cl4v,"Band/LowerTri"); TestMatrixArith5(bi,cbi,l4v,cl4v,"Band/LowerTri"); TestMatrixArith6x(bi,cbi,l4v,cl4v,"Band/LowerTri"); #endif } }
main() { SymbolTable symtab ; Attribute *attr1a = new Attribute(symtab.intern("attr1a"),"one-a"); Attribute *attr1b = new Attribute(symtab.intern("attr1b"),"one-b"); AttributeList *alist1 = new AttributeList ; alist1->add(attr1a); alist1->add(attr1b); Element one(symtab.intern("One"), 1, alist1, 0); Element two(symtab.intern("Two"), 2, 0, 0); PQPosition posn_eq(PQEqual, 1); PQPosition posn_neq(PQNotEqual, 1); // ///////////////////////////////////////////////////////////////////////// // Test Position // ///////////////////////////////////////////////////////////////////////// /* -------- Test Position Equal -------- */ cout << posn_eq.evaluate (one) << endl; // 1 cout << posn_eq.evaluate (two) << endl; // 0 cout << "---" << endl; /* -------- Test Position Not Equal -------- */ cout << posn_neq.evaluate (one) << endl; // 0 cout << posn_neq.evaluate (two) << endl; // 1 cout << "---" << endl; // /////////////////////////////////////////////////////////////////////// // Test Attribute Comparison // /////////////////////////////////////////////////////////////////////// PQAttributeSelector pqas_eqa(symtab.intern("attr1a"), PQEqual, "one-a"); PQAttributeSelector pqas_eqb(symtab.intern("attr1a"), PQEqual, "one-b"); PQAttributeSelector pqas_neqa(symtab.intern("attr1a"), PQNotEqual, "one-a"); PQAttributeSelector pqas_neqb(symtab.intern("attr1a"), PQNotEqual, "one-b"); PQAttributeSelector pqas_eqa2(symtab.intern("attr2a"), PQEqual, "one-a"); PQAttributeSelector pqas_eqb2(symtab.intern("attr2a"), PQEqual, "one-b"); PQAttributeSelector pqas_neqa2(symtab.intern("attr2a"), PQNotEqual, "one-a"); PQAttributeSelector pqas_neqb2(symtab.intern("attr2a"), PQNotEqual, "one-b"); cout << pqas_eqa.evaluate(one) << endl ; // 1 cout << pqas_eqa.evaluate(two) << endl ; // 0 cout << pqas_eqb.evaluate(one) << endl ; // 0 cout << pqas_eqb.evaluate(two) << endl ; // 0 cout << pqas_neqa.evaluate(one) << endl ; // 0 cout << pqas_neqa.evaluate(two) << endl ; // 1 cout << pqas_neqb.evaluate(one) << endl ; // 1 cout << pqas_neqb.evaluate(two) << endl ; // 1 cout << pqas_eqa2.evaluate(one) << endl ; // 0 cout << pqas_eqa2.evaluate(two) << endl ; // 0 cout << pqas_eqb2.evaluate(one) << endl ; // 0 cout << pqas_eqb2.evaluate(two) << endl ; // 0 cout << pqas_neqa2.evaluate(one) << endl ; // 1 cout << pqas_neqa2.evaluate(two) << endl ; // 1 cout << pqas_neqb2.evaluate(one) << endl ; // 1 cout << pqas_neqb2.evaluate(two) << endl ; // 1 cout << "****" << endl; // /////////////////////////////////////////////////////////////////////// // composite // /////////////////////////////////////////////////////////////////////// // position = 1 and attr(attr1a) == "one-a" PQPosition *p1 = new PQPosition(PQEqual, 1); PQAttributeSelector *a1 = new PQAttributeSelector(symtab.intern("attr1a"), PQEqual, "one-a"); PQAttributeSelector *a2 = new PQAttributeSelector(symtab.intern("attr1a"), PQEqual, "value"); PQLogExpr l1 (p1, PQand, a1); PQLogExpr l2 (p1, PQor, a1); PQLogExpr l3 (p1, PQand, a2); PQLogExpr l4 (p1, PQor, a2); cout << l1.evaluate(one) << endl ; // 1 cout << l1.evaluate(two) << endl ; // 0 cout << l2.evaluate(one) << endl ; // 1 cout << l2.evaluate(two) << endl ; // 0 cout << l3.evaluate(one) << endl ; // 0 cout << l3.evaluate(two) << endl ; // 0 cout << l4.evaluate(one) << endl ; // 1 cout << l4.evaluate(two) << endl ; // 0 cout << "..." << endl; cout << PQNot(&l4).evaluate(one) << endl ; // 0 cout << PQNot(&l4).evaluate(two) << endl ; // 1 }
int main (int, char**) { UnitTest t (1208); std::vector <std::pair <std::string, Lexer::Type>> tokens; std::string token; Lexer::Type type; // Feed in some attributes and types, so that the Lexer knows what a DOM // reference is. Lexer::attributes["due"] = "date"; Lexer::attributes["tags"] = "string"; Lexer::attributes["description"] = "string"; // White space detection. t.notok (Lexer::isWhitespace (0x0041), "U+0041 (A) ! isWhitespace"); t.ok (Lexer::isWhitespace (0x0020), "U+0020 isWhitespace"); t.ok (Lexer::isWhitespace (0x0009), "U+0009 isWhitespace"); t.ok (Lexer::isWhitespace (0x000A), "U+000A isWhitespace"); t.ok (Lexer::isWhitespace (0x000B), "U+000B isWhitespace"); t.ok (Lexer::isWhitespace (0x000C), "U+000C isWhitespace"); t.ok (Lexer::isWhitespace (0x000D), "U+000D isWhitespace"); t.ok (Lexer::isWhitespace (0x0085), "U+0085 isWhitespace"); t.ok (Lexer::isWhitespace (0x00A0), "U+00A0 isWhitespace"); t.ok (Lexer::isWhitespace (0x1680), "U+1680 isWhitespace"); // 10 t.ok (Lexer::isWhitespace (0x180E), "U+180E isWhitespace"); t.ok (Lexer::isWhitespace (0x2000), "U+2000 isWhitespace"); t.ok (Lexer::isWhitespace (0x2001), "U+2001 isWhitespace"); t.ok (Lexer::isWhitespace (0x2002), "U+2002 isWhitespace"); t.ok (Lexer::isWhitespace (0x2003), "U+2003 isWhitespace"); t.ok (Lexer::isWhitespace (0x2004), "U+2004 isWhitespace"); t.ok (Lexer::isWhitespace (0x2005), "U+2005 isWhitespace"); t.ok (Lexer::isWhitespace (0x2006), "U+2006 isWhitespace"); t.ok (Lexer::isWhitespace (0x2007), "U+2007 isWhitespace"); t.ok (Lexer::isWhitespace (0x2008), "U+2008 isWhitespace"); // 20 t.ok (Lexer::isWhitespace (0x2009), "U+2009 isWhitespace"); t.ok (Lexer::isWhitespace (0x200A), "U+200A isWhitespace"); t.ok (Lexer::isWhitespace (0x2028), "U+2028 isWhitespace"); t.ok (Lexer::isWhitespace (0x2029), "U+2029 isWhitespace"); t.ok (Lexer::isWhitespace (0x202F), "U+202F isWhitespace"); t.ok (Lexer::isWhitespace (0x205F), "U+205F isWhitespace"); t.ok (Lexer::isWhitespace (0x3000), "U+3000 isWhitespace"); // static bool Lexer::isBoundary (int, int); t.ok (Lexer::isBoundary (' ', 'a'), "' ' --> 'a' = isBoundary"); t.ok (Lexer::isBoundary ('a', ' '), "'a' --> ' ' = isBoundary"); t.ok (Lexer::isBoundary (' ', '+'), "' ' --> '+' = isBoundary"); t.ok (Lexer::isBoundary (' ', ','), "' ' --> ',' = isBoundary"); t.notok (Lexer::isBoundary ('3', '4'), "'3' --> '4' = isBoundary"); t.ok (Lexer::isBoundary ('(', '('), "'(' --> '(' = isBoundary"); t.notok (Lexer::isBoundary ('r', 'd'), "'r' --> 'd' = isBoundary"); // static bool Lexer::wasQuoted (const std::string&); t.notok (Lexer::wasQuoted (""), "'' --> !wasQuoted"); t.notok (Lexer::wasQuoted ("foo"), "'foo' --> !wasQuoted"); t.ok (Lexer::wasQuoted ("a b"), "'a b' --> wasQuoted"); t.ok (Lexer::wasQuoted ("(a)"), "'(a)' --> wasQuoted"); // static bool Lexer::dequote (std::string&, const std::string& quotes = "'\""); token = "foo"; Lexer::dequote (token); t.is (token, "foo", "dequote foo --> foo"); token = "'foo'"; Lexer::dequote (token); t.is (token, "foo", "dequote 'foo' --> foo"); token = "'o\\'clock'"; Lexer::dequote (token); t.is (token, "o\\'clock", "dequote 'o\\'clock' --> o\\'clock"); token = "abba"; Lexer::dequote (token, "a"); t.is (token, "bb", "dequote 'abba' (a) --> bb"); // Should result in no tokens. Lexer l0 (""); t.notok (l0.token (token, type), "'' --> no tokens"); // Should result in no tokens. Lexer l1 (" \t "); t.notok (l1.token (token, type), "' \\t ' --> no tokens"); // \u20ac = Euro symbol. Lexer l2 (" one 'two \\'three\\''+456-(1.3*2 - 0x12) 1.2e-3.4 foo.bar and '\\u20ac'"); tokens.clear (); while (l2.token (token, type)) { std::cout << "# «" << token << "» " << Lexer::typeName (type) << "\n"; tokens.push_back (std::pair <std::string, Lexer::Type> (token, type)); } t.is (tokens[0].first, "one", "tokens[0] = 'one'"); // 30 t.is (Lexer::typeName (tokens[0].second), "identifier", "tokens[0] = identifier"); t.is (tokens[1].first, "'two 'three''", "tokens[1] = 'two 'three''"); t.is (Lexer::typeName (tokens[1].second), "string", "tokens[1] = string"); t.is (tokens[2].first, "+", "tokens[2] = '+'"); t.is (Lexer::typeName (tokens[2].second), "op", "tokens[2] = op"); t.is (tokens[3].first, "456", "tokens[3] = '456'"); t.is (Lexer::typeName (tokens[3].second), "number", "tokens[3] = number"); t.is (tokens[4].first, "-", "tokens[4] = '-'"); t.is (Lexer::typeName (tokens[4].second), "op", "tokens[4] = op"); t.is (tokens[5].first, "(", "tokens[5] = '('"); // 40 t.is (Lexer::typeName (tokens[5].second), "op", "tokens[5] = op"); t.is (tokens[6].first, "1.3", "tokens[6] = '1.3'"); t.is (Lexer::typeName (tokens[6].second), "number", "tokens[6] = number"); t.is (tokens[7].first, "*", "tokens[7] = '*'"); t.is (Lexer::typeName (tokens[7].second), "op", "tokens[7] = op"); t.is (tokens[8].first, "2", "tokens[8] = '2'"); t.is (Lexer::typeName (tokens[8].second), "number", "tokens[8] = number"); t.is (tokens[9].first, "-", "tokens[9] = '-'"); t.is (Lexer::typeName (tokens[9].second), "op", "tokens[9] = op"); t.is (tokens[10].first, "0x12", "tokens[10] = '0x12'"); // 50 t.is (Lexer::typeName (tokens[10].second), "hex", "tokens[10] = hex"); t.is (tokens[11].first, ")", "tokens[11] = ')'"); t.is (Lexer::typeName (tokens[11].second), "op", "tokens[11] = op"); t.is (tokens[12].first, "1.2e-3.4", "tokens[12] = '1.2e-3.4'"); t.is (Lexer::typeName (tokens[12].second), "number", "tokens[12] = number"); t.is (tokens[13].first, "foo.bar", "tokens[13] = 'foo.bar'"); t.is (Lexer::typeName (tokens[13].second), "identifier", "tokens[13] = identifier"); t.is (tokens[14].first, "and", "tokens[14] = 'and'"); // 60 t.is (Lexer::typeName (tokens[14].second), "op", "tokens[14] = op"); t.is (tokens[15].first, "'€'", "tokens[15] = \\u20ac --> ''€''"); t.is (Lexer::typeName (tokens[15].second), "string", "tokens[15] = string"); // Test for numbers that are no longer ISO-8601 dates. Lexer l3 ("1 12 123 1234 12345 123456 1234567"); tokens.clear (); while (l3.token (token, type)) { std::cout << "# «" << token << "» " << Lexer::typeName (type) << "\n"; tokens.push_back (std::pair <std::string, Lexer::Type> (token, type)); } t.is ((int)tokens.size (), 7, "7 tokens"); t.is (tokens[0].first, "1", "tokens[0] == '1'"); t.is ((int) tokens[0].second, (int) Lexer::Type::number, "tokens[0] == Type::number"); t.is (tokens[1].first, "12", "tokens[1] == '12'"); t.is ((int) tokens[1].second, (int) Lexer::Type::number, "tokens[1] == Type::date"); t.is (tokens[2].first, "123", "tokens[2] == '123'"); t.is ((int) tokens[2].second, (int) Lexer::Type::number, "tokens[2] == Type::number"); // 70 t.is (tokens[3].first, "1234", "tokens[3] == '1234'"); t.is ((int) tokens[3].second, (int) Lexer::Type::number, "tokens[3] == Type::date"); t.is (tokens[4].first, "12345", "tokens[4] == '12345'"); t.is ((int) tokens[4].second, (int) Lexer::Type::number, "tokens[4] == Type::number"); t.is (tokens[5].first, "123456", "tokens[5] == '123456'"); t.is ((int) tokens[5].second, (int) Lexer::Type::number, "tokens[5] == Type::date"); t.is (tokens[6].first, "1234567", "tokens[6] == '1234567'"); t.is ((int) tokens[6].second, (int) Lexer::Type::number, "tokens[6] == Type::number"); // void split (std::vector<std::string>&, const std::string&); std::string unsplit = " ( A or B ) "; std::vector <std::string> items; items = Lexer::split (unsplit); t.is (items.size (), (size_t) 5, "split ' ( A or B ) '"); t.is (items[0], "(", "split ' ( A or B ) ' -> [0] '('"); t.is (items[1], "A", "split ' ( A or B ) ' -> [1] 'A'"); t.is (items[2], "or", "split ' ( A or B ) ' -> [2] 'or'"); t.is (items[3], "B", "split ' ( A or B ) ' -> [3] 'B'"); t.is (items[4], ")", "split ' ( A or B ) ' -> [4] ')'"); // Test simple mode with contrived tokens that ordinarily split. unsplit = " +-* a+b 12.3e4 'c d'"; items = Lexer::split (unsplit); t.is (items.size (), (size_t) 8, "split ' +-* a+b 12.3e4 'c d''"); t.is (items[0], "+", "split ' +-* a+b 12.3e4 'c d'' -> [0] '+'"); t.is (items[1], "-", "split ' +-* a+b 12.3e4 'c d'' -> [1] '-'"); t.is (items[2], "*", "split ' +-* a+b 12.3e4 'c d'' -> [2] '*'"); t.is (items[3], "a", "split ' +-* a+b 12.3e4 'c d'' -> [3] 'a'"); t.is (items[4], "+", "split ' +-* a+b 12.3e4 'c d'' -> [4] '+'"); t.is (items[5], "b", "split ' +-* a+b 12.3e4 'c d'' -> [5] 'b'"); t.is (items[6], "12.3e4", "split ' +-* a+b 12.3e4 'c d'' -> [6] '12.3e4'"); t.is (items[7], "'c d'", "split ' +-* a+b 12.3e4 'c d'' -> [7] ''c d''"); // static bool decomposePair (const std::string&, std::string&, std::string&, std::string&, std::string&); // 2 * 4 * 2 * 5 = 80 tests. std::string outName, outMod, outValue, outSep; for (auto& name : {"name"}) { for (auto& mod : {"", "mod"}) { for (auto& sep : {":", "=", "::", ":="}) { for (auto& value : {"", "value", "a:b", "a::b", "a=b", "a:=b"}) { std::string input = std::string ("name") + (strlen (mod) ? "." : "") + mod + sep + value; t.ok (Lexer::decomposePair (input, outName, outMod, outSep, outValue), "decomposePair '" + input + "' --> true"); t.is (name, outName, " '" + input + "' --> name '" + name + "'"); t.is (mod, outMod, " '" + input + "' --> mod '" + mod + "'"); t.is (value, outValue, " '" + input + "' --> value '" + value + "'"); t.is (sep, outSep, " '" + input + "' --> sep '" + sep + "'"); } } } } // static bool readWord (const std::string&, const std::string&, std::string::size_type&, std::string&); std::string::size_type cursor = 0; std::string word; t.ok (Lexer::readWord ("'one two'", "'\"", cursor, word), "readWord ''one two'' --> true"); t.is (word, "'one two'", " word '" + word + "'"); t.is ((int)cursor, 9, " cursor"); // Unterminated quoted string is invalid. cursor = 0; t.notok (Lexer::readWord ("'one", "'\"", cursor, word), "readWord ''one' --> false"); // static bool readWord (const std::string&, std::string::size_type&, std::string&); cursor = 0; t.ok (Lexer::readWord ("input", cursor, word), "readWord 'input' --> true"); t.is (word, "input", " word '" + word + "'"); t.is ((int)cursor, 5, " cursor"); cursor = 0; t.ok (Lexer::readWord ("one\\ two", cursor, word), "readWord 'one\\ two' --> true"); t.is (word, "one two", " word '" + word + "'"); t.is ((int)cursor, 8, " cursor"); cursor = 0; t.ok (Lexer::readWord ("\\u20A43", cursor, word), "readWord '\\u20A43' --> true"); t.is (word, "₤3", " word '" + word + "'"); t.is ((int)cursor, 7, " cursor"); cursor = 0; t.ok (Lexer::readWord ("U+20AC4", cursor, word), "readWord '\\u20AC4' --> true"); t.is (word, "€4", " word '" + word + "'"); t.is ((int)cursor, 7, " cursor"); std::string text = "one 'two' three\\ four"; cursor = 0; t.ok (Lexer::readWord (text, cursor, word), "readWord \"one 'two' three\\ four\" --> true"); t.is (word, "one", " word '" + word + "'"); cursor++; t.ok (Lexer::readWord (text, cursor, word), "readWord \"one 'two' three\\ four\" --> true"); t.is (word, "'two'", " word '" + word + "'"); cursor++; t.ok (Lexer::readWord (text, cursor, word), "readWord \"one 'two' three\\ four\" --> true"); t.is (word, "three four", " word '" + word + "'"); text = "one "; cursor = 0; t.ok (Lexer::readWord (text, cursor, word), "readWord \"one \" --> true"); t.is (word, "one", " word '" + word + "'"); // bool isLiteral (const std::string&, bool, bool); Lexer l4 ("one.two"); t.notok (l4.isLiteral("zero", false, false), "isLiteral 'one.two' --> false"); t.ok (l4.isLiteral("one", false, false), "isLiteral 'one.two' --> 'one'"); t.ok (l4.isLiteral(".", false, false), "isLiteral 'one.two' --> '.'"); t.ok (l4.isLiteral("two", false, true), "isLiteral 'one.two' --> 'two'"); Lexer l5 ("wonder"); t.notok (l5.isLiteral ("wonderful", false, false), "isLiteral 'wonderful' != 'wonder' without abbreviation"); t.ok (l5.isLiteral ("wonderful", true, false), "isLiteral 'wonderful' == 'wonder' with abbreviation"); // bool isOneOf (const std::string&, bool, bool); Lexer l6 ("Grumpy."); std::vector <std::string> dwarves = {"Sneezy", "Doc", "Bashful", "Grumpy", "Happy", "Sleepy", "Dopey"}; t.notok (l6.isOneOf (dwarves, false, true), "isOneof ('Grumpy', true) --> false"); t.ok (l6.isOneOf (dwarves, false, false), "isOneOf ('Grumpy', false) --> true"); // static std::string::size_type commonLength (const std::string&, const std::string&); t.is ((int)Lexer::commonLength ("", ""), 0, "commonLength '' : '' --> 0"); t.is ((int)Lexer::commonLength ("a", "a"), 1, "commonLength 'a' : 'a' --> 1"); t.is ((int)Lexer::commonLength ("abcde", "abcde"), 5, "commonLength 'abcde' : 'abcde' --> 5"); t.is ((int)Lexer::commonLength ("abc", ""), 0, "commonLength 'abc' : '' --> 0"); t.is ((int)Lexer::commonLength ("abc", "def"), 0, "commonLength 'abc' : 'def' --> 0"); t.is ((int)Lexer::commonLength ("foobar", "foo"), 3, "commonLength 'foobar' : 'foo' --> 3"); t.is ((int)Lexer::commonLength ("foo", "foobar"), 3, "commonLength 'foo' : 'foobar' --> 3"); // static std::string::size_type commonLength (const std::string&, std::string::size_type, const std::string&, std::string::size_type); t.is ((int)Lexer::commonLength ("wonder", 0, "prowonderbread", 3), 6, "'wonder'+0 : 'prowonderbread'+3 --> 6"); // Test all Lexer types. #define NO {"",Lexer::Type::word} struct { const char* input; struct { const char* token; Lexer::Type type; } results[5]; } lexerTests[] = { // Pattern { "/foo/", { { "/foo/", Lexer::Type::pattern }, NO, NO, NO, NO }, }, { "/a\\/b/", { { "/a\\/b/", Lexer::Type::pattern }, NO, NO, NO, NO }, }, { "/'/", { { "/'/", Lexer::Type::pattern }, NO, NO, NO, NO }, }, // Substitution { "/from/to/g", { { "/from/to/g", Lexer::Type::substitution }, NO, NO, NO, NO }, }, { "/from/to/", { { "/from/to/", Lexer::Type::substitution }, NO, NO, NO, NO }, }, // Tag { "+tag", { { "+tag", Lexer::Type::tag }, NO, NO, NO, NO }, }, { "-tag", { { "-tag", Lexer::Type::tag }, NO, NO, NO, NO }, }, { "+@tag", { { "+@tag", Lexer::Type::tag }, NO, NO, NO, NO }, }, // Path { "/long/path/to/file.txt", { { "/long/path/to/file.txt", Lexer::Type::path }, NO, NO, NO, NO }, }, // Word { "1.foo.bar", { { "1.foo.bar", Lexer::Type::word }, NO, NO, NO, NO }, }, // Identifier { "foo", { { "foo", Lexer::Type::identifier }, NO, NO, NO, NO }, }, { "Çirçös", { { "Çirçös", Lexer::Type::identifier }, NO, NO, NO, NO }, }, { "☺", { { "☺", Lexer::Type::identifier }, NO, NO, NO, NO }, }, { "name", { { "name", Lexer::Type::identifier }, NO, NO, NO, NO }, }, { "f1", { { "f1", Lexer::Type::identifier }, NO, NO, NO, NO }, }, { "foo.bar", { { "foo.bar", Lexer::Type::identifier }, NO, NO, NO, NO }, }, { "a1a1a1a1_a1a1_a1a1_a1a1_a1a1a1a1a1a1", { { "a1a1a1a1_a1a1_a1a1_a1a1_a1a1a1a1a1a1", Lexer::Type::identifier }, NO, NO, NO, NO }, }, // Word that starts wih 'or', which is an operator, but should be ignored. { "ordinary", { { "ordinary", Lexer::Type::identifier }, NO, NO, NO, NO }, }, // DOM { "due", { { "due", Lexer::Type::dom }, NO, NO, NO, NO }, }, { "123.tags", { { "123.tags", Lexer::Type::dom }, NO, NO, NO, NO }, }, { "123.tags.PENDING", { { "123.tags.PENDING", Lexer::Type::dom }, NO, NO, NO, NO }, }, { "123.description", { { "123.description", Lexer::Type::dom }, NO, NO, NO, NO }, }, { "123.annotations.1.description", { { "123.annotations.1.description", Lexer::Type::dom }, NO, NO, NO, NO }, }, { "123.annotations.1.entry", { { "123.annotations.1.entry", Lexer::Type::dom }, NO, NO, NO, NO }, }, { "123.annotations.1.entry.year", { { "123.annotations.1.entry.year", Lexer::Type::dom }, NO, NO, NO, NO }, }, { "a360fc44-315c-4366-b70c-ea7e7520b749.due", { { "a360fc44-315c-4366-b70c-ea7e7520b749.due", Lexer::Type::dom }, NO, NO, NO, NO }, }, { "12345678-1234-1234-1234-123456789012.due", { { "12345678-1234-1234-1234-123456789012.due", Lexer::Type::dom }, NO, NO, NO, NO }, }, { "system.os", { { "system.os", Lexer::Type::dom }, NO, NO, NO, NO }, }, { "rc.foo", { { "rc.foo", Lexer::Type::dom }, NO, NO, NO, NO }, }, // URL { "http://tasktools.org", { { "http://tasktools.org", Lexer::Type::url }, NO, NO, NO, NO }, }, { "https://bug.tasktools.org", { { "https://bug.tasktools.org", Lexer::Type::url }, NO, NO, NO, NO }, }, // String { "'one two'", { { "'one two'", Lexer::Type::string }, NO, NO, NO, NO }, }, { "\"three\"", { { "\"three\"", Lexer::Type::string }, NO, NO, NO, NO }, }, { "'\\''", { { "'''", Lexer::Type::string }, NO, NO, NO, NO }, }, { "\"\\\"\"", { { "\"\"\"", Lexer::Type::string }, NO, NO, NO, NO }, }, { "\"\tfoo\t\"", { { "\"\tfoo\t\"", Lexer::Type::string }, NO, NO, NO, NO }, }, { "\"\\u20A43\"", { { "\"₤3\"", Lexer::Type::string }, NO, NO, NO, NO }, }, { "\"U+20AC4\"", { { "\"€4\"", Lexer::Type::string }, NO, NO, NO, NO }, }, // Number { "1", { { "1", Lexer::Type::number }, NO, NO, NO, NO }, }, { "3.14", { { "3.14", Lexer::Type::number }, NO, NO, NO, NO }, }, { "6.02217e23", { { "6.02217e23", Lexer::Type::number }, NO, NO, NO, NO }, }, { "1.2e-3.4", { { "1.2e-3.4", Lexer::Type::number }, NO, NO, NO, NO }, }, { "0x2f", { { "0x2f", Lexer::Type::hex }, NO, NO, NO, NO }, }, // Set (1,2,4-7,9) { "1,2", { { "1,2", Lexer::Type::set }, NO, NO, NO, NO }, }, { "1-2", { { "1-2", Lexer::Type::set }, NO, NO, NO, NO }, }, { "1-2,4", { { "1-2,4", Lexer::Type::set }, NO, NO, NO, NO }, }, { "1-2,4,6-8", { { "1-2,4,6-8", Lexer::Type::set }, NO, NO, NO, NO }, }, { "1-2,4,6-8,10-12", { { "1-2,4,6-8,10-12", Lexer::Type::set }, NO, NO, NO, NO }, }, // Pair { "name:value", { { "name:value", Lexer::Type::pair }, NO, NO, NO, NO }, }, { "name=value", { { "name=value", Lexer::Type::pair }, NO, NO, NO, NO }, }, { "name:=value", { { "name:=value", Lexer::Type::pair }, NO, NO, NO, NO }, }, { "name.mod:value", { { "name.mod:value", Lexer::Type::pair }, NO, NO, NO, NO }, }, { "name.mod=value", { { "name.mod=value", Lexer::Type::pair }, NO, NO, NO, NO }, }, { "name:", { { "name:", Lexer::Type::pair }, NO, NO, NO, NO }, }, { "name=", { { "name=", Lexer::Type::pair }, NO, NO, NO, NO }, }, { "name.mod:", { { "name.mod:", Lexer::Type::pair }, NO, NO, NO, NO }, }, { "name.mod=", { { "name.mod=", Lexer::Type::pair }, NO, NO, NO, NO }, }, { "pro:'P 1'", { { "pro:'P 1'", Lexer::Type::pair }, NO, NO, NO, NO }, }, { "rc:x", { { "rc:x", Lexer::Type::pair }, NO, NO, NO, NO }, }, { "rc.name:value", { { "rc.name:value", Lexer::Type::pair }, NO, NO, NO, NO }, }, { "rc.name=value", { { "rc.name=value", Lexer::Type::pair }, NO, NO, NO, NO }, }, { "rc.name:=value", { { "rc.name:=value", Lexer::Type::pair }, NO, NO, NO, NO }, }, { "due:='eow - 2d'", { { "due:='eow - 2d'", Lexer::Type::pair }, NO, NO, NO, NO }, }, // Operator - complete set { "^", { { "^", Lexer::Type::op }, NO, NO, NO, NO }, }, { "!", { { "!", Lexer::Type::op }, NO, NO, NO, NO }, }, { "_neg_", { { "_neg_", Lexer::Type::op }, NO, NO, NO, NO }, }, { "_pos_", { { "_pos_", Lexer::Type::op }, NO, NO, NO, NO }, }, { "_hastag_", { { "_hastag_", Lexer::Type::op }, NO, NO, NO, NO }, }, { "_notag_", { { "_notag_", Lexer::Type::op }, NO, NO, NO, NO }, }, { "*", { { "*", Lexer::Type::op }, NO, NO, NO, NO }, }, { "/", { { "/", Lexer::Type::op }, NO, NO, NO, NO }, }, { "%", { { "%", Lexer::Type::op }, NO, NO, NO, NO }, }, { "+", { { "+", Lexer::Type::op }, NO, NO, NO, NO }, }, { "-", { { "-", Lexer::Type::op }, NO, NO, NO, NO }, }, { "<=", { { "<=", Lexer::Type::op }, NO, NO, NO, NO }, }, { ">=", { { ">=", Lexer::Type::op }, NO, NO, NO, NO }, }, { ">", { { ">", Lexer::Type::op }, NO, NO, NO, NO }, }, { "<", { { "<", Lexer::Type::op }, NO, NO, NO, NO }, }, { "=", { { "=", Lexer::Type::op }, NO, NO, NO, NO }, }, { "==", { { "==", Lexer::Type::op }, NO, NO, NO, NO }, }, { "!=", { { "!=", Lexer::Type::op }, NO, NO, NO, NO }, }, { "!==", { { "!==", Lexer::Type::op }, NO, NO, NO, NO }, }, { "~", { { "~", Lexer::Type::op }, NO, NO, NO, NO }, }, { "!~", { { "!~", Lexer::Type::op }, NO, NO, NO, NO }, }, { "and", { { "and", Lexer::Type::op }, NO, NO, NO, NO }, }, { "or", { { "or", Lexer::Type::op }, NO, NO, NO, NO }, }, { "xor", { { "xor", Lexer::Type::op }, NO, NO, NO, NO }, }, { "(", { { "(", Lexer::Type::op }, NO, NO, NO, NO }, }, { ")", { { ")", Lexer::Type::op }, NO, NO, NO, NO }, }, // UUID { "ffffffff-ffff-ffff-ffff-ffffffffffff", { { "ffffffff-ffff-ffff-ffff-ffffffffffff", Lexer::Type::uuid }, NO, NO, NO, NO }, }, { "00000000-0000-0000-0000-0000000", { { "00000000-0000-0000-0000-0000000", Lexer::Type::uuid }, NO, NO, NO, NO }, }, { "00000000-0000-0000-0000", { { "00000000-0000-0000-0000", Lexer::Type::uuid }, NO, NO, NO, NO }, }, { "00000000-0000-0000", { { "00000000-0000-0000", Lexer::Type::uuid }, NO, NO, NO, NO }, }, { "00000000-0000", { { "00000000-0000", Lexer::Type::uuid }, NO, NO, NO, NO }, }, { "00000000", { { "00000000", Lexer::Type::uuid }, NO, NO, NO, NO }, }, { "a360fc44-315c-4366-b70c-ea7e7520b749", { { "a360fc44-315c-4366-b70c-ea7e7520b749", Lexer::Type::uuid }, NO, NO, NO, NO }, }, { "a360fc44-315c-4366-b70c-ea7e752", { { "a360fc44-315c-4366-b70c-ea7e752", Lexer::Type::uuid }, NO, NO, NO, NO }, }, { "a360fc44-315c-4366-b70c", { { "a360fc44-315c-4366-b70c", Lexer::Type::uuid }, NO, NO, NO, NO }, }, { "a360fc44-315c-4366", { { "a360fc44-315c-4366", Lexer::Type::uuid }, NO, NO, NO, NO }, }, { "a360fc44-315c", { { "a360fc44-315c", Lexer::Type::uuid }, NO, NO, NO, NO }, }, { "a360fc44", { { "a360fc44", Lexer::Type::uuid }, NO, NO, NO, NO }, }, // Date { "2015-W01", { { "2015-W01", Lexer::Type::date }, NO, NO, NO, NO }, }, { "2015-02-17", { { "2015-02-17", Lexer::Type::date }, NO, NO, NO, NO }, }, { "2013-11-29T22:58:00Z", { { "2013-11-29T22:58:00Z", Lexer::Type::date }, NO, NO, NO, NO }, }, { "20131129T225800Z", { { "20131129T225800Z", Lexer::Type::date }, NO, NO, NO, NO }, }, { "9th", { { "9th", Lexer::Type::date }, NO, NO, NO, NO }, }, { "10th", { { "10th", Lexer::Type::date }, NO, NO, NO, NO }, }, { "today", { { "today", Lexer::Type::date }, NO, NO, NO, NO }, }, // Duration { "year", { { "year", Lexer::Type::duration }, NO, NO, NO, NO }, }, { "4weeks", { { "4weeks", Lexer::Type::duration }, NO, NO, NO, NO }, }, { "PT23H", { { "PT23H", Lexer::Type::duration }, NO, NO, NO, NO }, }, { "1second", { { "1second", Lexer::Type::duration }, NO, NO, NO, NO }, }, { "1s", { { "1s", Lexer::Type::duration }, NO, NO, NO, NO }, }, { "1minute", { { "1minute", Lexer::Type::duration }, NO, NO, NO, NO }, }, { "2hour", { { "2hour", Lexer::Type::duration }, NO, NO, NO, NO }, }, { "3 days", { { "3 days", Lexer::Type::duration }, NO, NO, NO, NO }, }, { "4w", { { "4w", Lexer::Type::duration }, NO, NO, NO, NO }, }, { "5mo", { { "5mo", Lexer::Type::duration }, NO, NO, NO, NO }, }, { "6 years", { { "6 years", Lexer::Type::duration }, NO, NO, NO, NO }, }, { "P1Y", { { "P1Y", Lexer::Type::duration }, NO, NO, NO, NO }, }, { "PT1H", { { "PT1H", Lexer::Type::duration }, NO, NO, NO, NO }, }, { "P1Y1M1DT1H1M1S", { { "P1Y1M1DT1H1M1S", Lexer::Type::duration }, NO, NO, NO, NO }, }, // Misc { "--", { { "--", Lexer::Type::separator }, NO, NO, NO, NO }, }, // Expression // due:eom-2w // due < eom + 1w + 1d // ( /pattern/ or 8ad2e3db-914d-4832-b0e6-72fa04f6e331,3b6218f9-726a-44fc-aa63-889ff52be442 ) { "(1+2)", { { "(", Lexer::Type::op }, { "1", Lexer::Type::number }, { "+", Lexer::Type::op }, { "2", Lexer::Type::number }, { ")", Lexer::Type::op }, }, }, { "description~pattern", { { "description", Lexer::Type::dom }, { "~", Lexer::Type::op }, { "pattern", Lexer::Type::identifier }, NO, NO }, }, { "(+tag)", { { "(", Lexer::Type::op }, { "+tag", Lexer::Type::tag }, { ")", Lexer::Type::op }, NO, NO }, }, { "(name:value)", { { "(", Lexer::Type::op }, { "name:value", Lexer::Type::pair }, { ")", Lexer::Type::op }, NO, NO }, }, }; #define NUM_TESTS (sizeof (lexerTests) / sizeof (lexerTests[0])) for (unsigned int i = 0; i < NUM_TESTS; i++) { // The isolated test puts the input string directly into the Lexer. Lexer isolated (lexerTests[i].input); for (int j = 0; j < 5; j++) { if (lexerTests[i].results[j].token[0]) { // Isolated: "<token>" t.ok (isolated.token (token, type), "Isolated Lexer::token(...) --> true"); t.is (token, lexerTests[i].results[j].token, " token --> " + token); t.is ((int)type, (int)lexerTests[i].results[j].type, " type --> Lexer::Type::" + Lexer::typeToString (type)); } } // The embedded test surrounds the input string with a space. Lexer embedded (std::string (" ") + lexerTests[i].input + " "); for (int j = 0; j < 5; j++) { if (lexerTests[i].results[j].token[0]) { // Embedded: "<token>" t.ok (embedded.token (token, type), "Embedded Lexer::token(...) --> true"); t.is (token, lexerTests[i].results[j].token, " token --> " + token); t.is ((int)type, (int)lexerTests[i].results[j].type, " type --> Lexer::Type::" + Lexer::typeToString (type)); } } } return 0; }
int main() { try { symbol k("k"),q("q"),p("p"),p1("p1"),p2("p2"),p3("p3"),ms("ms"),l("l"),s("s"),m1s("m1s"),m2s("m2s"),m3s("m3s"); symbol l1("l1"),l2("l2"),l3("l3"),l4("l4"),t("t"),p4("p4"),p5("p5"),tp("tp"),v1("v1"),v2("v2"),l5("l5"); symbol k1("k1"),k2("k2"),k3("k3"),k4("k4"),k5("k5"),ms1("ms1"),ms2("ms2"),ms3("ms3"),ms4("ms4"); // oneloop box // UFXmap l45 = UF(lst(k),lst(pow(k,2),pow(k+p1,2),pow(k+p1+p2,2),pow(k+p1+p2+p3,2)),lst(pow(p1,2)==0,pow(p2,2)==0)); // MBintegral root_int(l45,lst(1,1,1,1),1); //two loop box bubble // UFXmap l45 = UF(lst(k,l),lst(pow(k,2),pow(k+p1,2),pow(k+p1+p2,2),pow(l+p1+p2,2),pow(l+p1+p2+p3,2),pow(l,2),pow(k-l,2)),lst(pow(p1,2)==0,pow(p2,2)==0,pow(p3,2)==0)); //MBintegral root_int(l45,lst(1,1,1,1,1,1,1),2); // B0 // UFXmap l45 = UF(lst(k),lst(ms-pow(k,2),ms-pow(-k,2)),lst(ms==1)); // MBintegral root_int(l45,lst(1,1),1); // 2 loop sunrise //UFXmap l45 = UF(lst(k,q),lst(ms-pow(k,2),ms-pow(-q-k,2),ms-pow(q,2)),lst(ms==1)); //MBintegral root_int(l45,lst(1,1,1),2); //RoMB_planar box2loop(lst(k,l),lst(pow(k,2),pow(k+p1,2),pow(k+p1+p2,2),pow(l+p1+p2,2),pow(l+p1+p2+p3,2),pow(l,2),pow(k-l,2)),lst(pow(p1,2)==0,pow(p2,2)==0,pow(p3,2)==0),lst(1,1,1,1,1,1,1),2); // RoMB_planar box1loop(lst(k),lst(pow(k,2),pow(k+p1,2)-ms,pow(k+p1+p2,2),pow(k+p1+p2+p3,2)),lst(pow(p1,2)==0,pow(p2,2)==0,pow(p3,2)==0,p1==0,p2==0,p3==0,ms==1),lst(1,1,1,1),1); // RoMB_planar B0_1loop(lst(k),lst(pow(k,2)-ms,pow(p+k,2)-ms),lst(ms==0,pow(p,2)==1),lst(1,1),1); // RoMB_planar C0_1loop(lst(k),lst(pow(k,2)-ms,pow(p1+k,2)-ms,pow(p1+p2+k,2)),lst(ms==1,pow(p1,2)==0,pow(p2,2)==0,p1*p2==50),lst(1,1,1),1); //cout<<" new point "<<endl<<root_int.new_point()<<endl; // cout<<" saved point "<<endl<<root_int.get_point()<<endl; // MBcontinue(root_int); //cout<<MB_lst(l45,lst(1,1,1,1),1).expand()<<endl; // RoMB_loop_by_loop box2loop(lst(k,l),lst(pow(k,2),pow(k+p1,2),pow(k+p1+p2,2),pow(l+p1+p2,2),pow(l+p1+p2+p3,2),pow(l,2),pow(k-l,2)),lst(pow(p1,2)==0,pow(p2,2)==0,pow(p3,2)==0),lst(1,1,1,1,1,1,1)); // RoMB_loop_by_loop t2(lst(k,l), lst(pow(k,2),pow(p+k,2),pow(p+k+l,2),pow(l,2),pow(k+l,2)),lst(pow(p,2)==1),lst(1,1,1,1,1)); // works!!! // RoMB_loop_by_loop sunset(lst(k,l), lst(pow(k,2)-1,pow(p-k-l,2)-4,pow(l,2)-5),lst(pow(p,2)==s),lst(1,1,1)); // RoMB_loop_by_loop sunset(lst(k,l), lst(pow(k,2)-m1s,pow(-k-l,2)-m2s,pow(l,2)-m3s),lst(pow(p,2)==s),lst(1,1,1)); // sunset.integrate(lst(m1s==1,m2s==1,m3s==1,s==0),0); // bubble sunset 2=loop // RoMB_loop_by_loop sunset_bub(lst(k,l), lst(-pow(k,2)+ms,-pow(-k-l,2)+ms,-pow(l,2)+ms),lst(pow(p,2)==0),lst(1,1,1)); // sunset_bub.integrate(lst(ms==1,m2s==1,m3s==1,s==0),1); // bubble sunset 3=loop // RoMB_loop_by_loop sunset_bub(lst(p,k,l), lst(-pow(p,2)+ms,-pow(k,2)+ms,-pow(l,2)+ms,-pow(-p-k-l,2)+ms),lst(pow(l3,2)==s),lst(1,1,1,1)); // sunset_bub.integrate(lst(ms==1,m2s==1,m3s==1,s==0),0); // RoMB_loop_by_loop sunset_bub_d(lst(l1,l2,l3), lst(-pow(l1,2)+ms,-pow(l2,2)+ms,-pow(l3,2)+ms,-pow(l1+l2,2)+ms,-pow(l1+l2+l3,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1)); // sunset_bub_d.integrate(lst(ms==1,m2s==1,m3s==1,s==0),-1); // RoMB_loop_by_loop sunset_bub_e(lst(l1,l2,l3), lst(-pow(l1,2)+ms,-pow(l2,2)+ms,-pow(l3,2)+ms,-pow(l1-l2,2)+ms,-pow(l2-l3,2)+ms,-pow(l3-l1,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1,1)); // sunset_bub_e.integrate_map(lst(ms==1,m2s==1,m3s==1,s==0),1); //bubble 4-loop // RoMB_loop_by_loop sunset_bub(lst(k,l1,l2,l3), lst(-pow(k,2)+ms,-pow(l2,2)+ms,-pow(l1,2)+ms,-pow(l3,2)+ms,-pow(k+l1+l2+l3,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1)); // sunset_bub.integrate(lst(ms==1,m2s==1,m3s==1,s==0),0); //bubble 5-loop // RoMB_loop_by_loop sunset_bub5(lst(l3,k,l1,l2,l4), lst(-pow(l3,2)+ms,-pow(k,2)+ms,-pow(l1,2)+ms,-pow(l2,2)+ms,-pow(l4,2)+ms,-pow(k+l1+l2+l3+l4,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1,1)); // sunset_bub5.integrate_map(lst(ms==1,m2s==1,m3s==1,s==0),3); // RoMB_loop_by_loop sunset_bubC2(lst(l1,l2,l3,l4,l5), lst(-pow(l3,2)+ms,-pow(l5,2)+ms,-pow(l1,2)+ms,-pow(l2,2)+ms,-pow(l4,2)+ms,-pow(l5+l1+l2,2)+ms,-pow(l5+l3+l4,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1,1,1)); // sunset_bubC2.integrate_map(lst(ms==1,m2s==1,m3s==1,s==0),0); // RoMB_loop_by_loop sunset_bubC2(lst(l1,l2,l3,l4,l5), lst(-pow(l3,2)+ms,-pow(l5,2)+ms,-pow(l1,2)+ms,-pow(l2,2)+ms,-pow(l4,2)+ms,-pow(l3+l4+l5,2)+ms,-pow(l1+l2+l5+l3+l4,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1,1,1)); // sunset_bubC2.integrate_map(lst(ms==1,m2s==1,m3s==1,s==0),0); // RoMB_loop_by_loop sunset_bubC1(lst(l1,l2,l3,l4,l5), lst(-pow(l3,2)+ms,-pow(l5,2)+ms,-pow(l1,2)+ms,-pow(l2,2)+ms,-pow(l4,2)+ms,-pow(l2+l3+l4+l5,2)+ms,-pow(l1+l2+l5+l3+l4,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1,1,1)); // sunset_bubC1.integrate_map(lst(ms==1,m2s==1,m3s==1,s==0),0); /* MEGA 5-LOOP BUBBLE with 12 propagators */ //RoMB_loop_by_loop l5p12(lst(k5,k2,k1,k4,k3),lst(-pow(k1,2)+ms,-pow(k2,2)+ms,-pow(k3,2)+ms,-pow(k4,2)+ms,-pow(k5,2)+ms, //-pow(k1-k3,2)+ms,-pow(k1-k4,2)+ms,-pow(k3-k2,2)+ms,-pow(k2-k4,2)+ms,-pow(k5+k3-k1,2)+ms,-pow(k5+k3-k2,2)+ms,-pow(k5+k3-k4,2)+ms),lst(pow(p,2)==0),lst(1,1,1,1,1,1,1,1,1,1,1,1)); //l5p12.integrate(lst(ms==0),0); //RoMB_loop_by_loop l5c1(lst(k2,k5,k3,k4,k1),lst(-pow(k3,2)+ms,-pow(k2,2)+ms,-pow(k1,2)+ms,-pow(k4,2)+ms,-pow(k5,2)+ms, //-pow(k1+k3+k4,2)+ms,-pow(k2+k5-k3-k4,2)+ms),lst(pow(p,2)==0),lst(1,1,1,1,1,1,1)); //l5c1.integrate_map(lst(ms==1),0); // RoMB_loop_by_loop t2loop(lst(k,l), lst(-pow(k,2)+ms,-pow(p+k,2)+ms,-pow(p+k+l,2)+ms,-pow(k+l,2)+ms,-pow(l,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1)); // t2loop.integrate(lst(s==1,ms == 0),1); /* RoMB_loop_by_loop bubble_five_loop(lst(k,l1,l2,l3,l4), lst(pow(k,2)-ms,pow(l1,2)-ms,pow(l2,2)-ms,pow(l3,2)-ms,pow(l4,2)-ms,pow(k+l1,2)-ms,pow(k+l1+l2,2)-ms,pow(k+l1+l2+l3,2)-ms,pow(k+l1+l2+l3+l4,2)-ms,pow(k+l1+l2+l3,2)-ms,pow(k+l1+l2,2)-ms,pow(k+l1,2)-ms), lst(ms==1), lst(1,1,1,1,1,1,1,1,1,1,1,1)); */ // works!!! // RoMB_loop_by_loop B0_1loop_lbl(lst(k),lst(pow(k,2)-2-ms,pow(p+k,2)-ms),lst(ms==0,pow(p,2)==1),lst(2,1)); // RoMB_loop_by_loop B0_1loop_lbl(lst(k),lst(pow(k,2)-m1s,pow(p+k,2)-m2s),lst(pow(p,2)==s),lst(1,1)); // B0_1loop_lbl.integrate(lst(s==-1,m1s==1,m2s==1)); //MB works??? // RoMB_loop_by_loop C0_1loop_lbl(lst(k),lst(pow(k,2),pow(k+p1,2)-m1s,pow(k-p2,2)-m2s),lst(ms==1,pow(p1,2)==m1s,pow(p2,2)==m2s,p1*p2==(s-m1s-m2s)/2),lst(1,1,1)); // C0_1loop_lbl.integrate(lst(m1s==1,m2s==1,s==-100)); //MB works??? /* RoMB_loop_by_loop box1loopm0(lst(k),lst(-pow(k,2),-pow(k+p1,2),-pow(k+p1+p2,2),-pow(k+p1+p2+p4,2)), lst(pow(p1,2)==0,pow(p2,2)==0,pow(p4,2)==0, p1*p2==-s/2,// p1*p4==s/2+t/2,// p2*p4==-t/2 // ), lst(1,1,1,1),false); box1loopm0.integrate_map(lst(s==3,t==1)); box1loopm0.integrate(lst(s==5,t==2)); */ //MASIVE BOX LBL RoMB_loop_by_loop box1loopm(lst(k),lst(-pow(k,2)+ms,-pow(k+p1,2)+ms,-pow(k+p1+p2,2)+ms,-pow(k+p1+p2+p4,2)+ms), lst(pow(p1,2)==0,pow(p2,2)==0,pow(p4,2)==0, p1*p2==s/2,// p1*p4==-(s/2+t/2),// p2*p4==t/2 // ), lst(1,1,1,1),false); box1loopm.integrate_map(lst(ms1==1,ms2==1,ms3==1,ms4==1,ms==1,s==-3,t==-1),3); //triple box /* RoMB_loop_by_loop tribox1loopm(lst(k1,k2,k3),lst(-pow(k1,2)+ms,-pow(k1+p1,2),-pow(k1+p1+p2,2)+ms, -pow(k1-k2,2),-pow(k2,2)+ms,-pow(k2+p1+p2,2)+ms, -pow(k2-k3,2),-pow(k3,2)+ms,-pow(k3+p1+p2,2)+ms, -pow(k3-p3,2)), lst(pow(p1,2)==ms,pow(p2,2)==ms,pow(p3,2)==ms,pow(p4,2)==ms, p1*p2==s/2-ms,// p1*p3==t/2-ms,// p2*p3==ms-(s+t)/2 // ), lst(1,1,1,1,1,1,1,1,1,1),true); tribox1loopm.integrate_map(lst(ms1==1,ms2==1,ms3==1,ms4==1,ms==1,s==-1/2,t==-3)); */ //double box /* RoMB_loop_by_loop dobox1loopm(lst(k1,k2),lst(-pow(k1,2),-pow(k1+p1,2),-pow(k1+p1+p2,2), -pow(k1-k2,2),-pow(k2,2),-pow(k2+p1+p2,2), -pow(k2-p3,2)), lst(pow(p1,2)==0,pow(p2,2)==0,pow(p3,2)==0,pow(p4,2)==0, p1*p2==s/2-ms,// p1*p3==t/2-ms,// p2*p3==ms-(s+t)/2 // ), lst(1,1,1,1,1,1,1),false); dobox1loopm.integrate_map(lst(ms1==1,ms2==1,ms3==1,ms4==1,ms==1,s==-1/2,t==-3)); */ /* 4-loop tadpole */ // RoMB_loop_by_loop tad4(lst(l1, l2, l3, l4),lst(pow(l1,2)- ms,pow(l2,2)- ms,pow(l3 ,2)- ms,pow(l4,2),pow(l1+l2+l3+l4,2)),lst(),lst(1,1,1,1,1)); // tad4.integrate(lst(ms == 1),-2); /* Pentagon */ /* RoMB_loop_by_loop pent(lst(k1),lst(-pow(p1 + k1,2)+ ms,-pow(p1 + p5 + k1,2), -pow(p1 + p5 + p4 + k1,2)+ ms,-pow(p1 + p5 + p4 + p3 + k1,2)+ ms, -pow(k1,2)), lst( p1*p1 == ms, p2*p2 == ms, p3*p3 == 0, p4*p4 == ms, p5*p5 == ms, p1*p2 == 1/2* (tp - 2* ms), p1*p3 == 1/2* (t - tp - v1), p1*p4 == ms - 1/2* (s + t - v1), p1*p5 == 1/2* (s - 2* ms), p2* p3 == 1/2* v1, p2* p4 == 1/2* (s - 2* ms - v1 - v2), p2* p5 == ms - 1/2* (s + tp - v2), p3* p4 == 1/2* v2, p3* p5 == 1/2* (tp - t - v2), p4* p5 == 1/2* (t - 2* ms)), lst(1,1,1,1,1)); pent.integrate_map(lst(s==-2,t==-3,v2==-4,tp==-5,v1==-6,ms==1)); */ /* RoMB_loop_by_loop pent(lst(k1),lst(-pow(p1 + k1,2)+ ms,-pow(p1 + p5 + k1,2), -pow(p1 + p5 + p4 + k1,2)+ ms,-pow(p1 + p5 + p4 + p3 + k1,2)+ ms, -pow(k1,2)), lst( p1*p1 == ms, p2*p2 == ms, p3*p3 == 0, p4*p4 == ms, p5*p5 == ms, p1*p2 == 1/2* (tp - 2* ms), wild(1)*p1*p3 == wild(1)*1/2* (t - tp - v1), wild(2)*p1*p4 == wild(2)*(ms - 1/2* (s + t - v1)), wild(3)* p1*p5 == wild(3)*1/2* (s - 2* ms), wild(4)*p2* p3 == wild(4)*1/2* v1, wild(5)*p2* p4 == wild(5)*1/2* (s - 2* ms - v1 - v2), wild(6)*p2* p5 ==wild(6)*( ms - 1/2* (s + tp - v2)), wild(7)*p3* p4 == wild(7)*1/2* v2, wild(8)*p3* p5 == wild(8)*1/2* (tp - t - v2), wild()*p4* p5 == wild()*1/2* (t - 2* ms)), lst(1,1,1,1,1)); pent.integrate_map(lst(s==-2,t==-3,v2==-4,tp==-5,v1==-6,ms==1)); */ } catch(std::exception &p) { std::cerr<<"******************************************************************"<<endl; std::cerr<<" >>>ERROR: "<<p.what()<<endl; std::cerr<<"******************************************************************"<<endl; return 1; } return 0; }
int main() { try { symbol k("k"),q("q"),p("p"),p1("p1"),p2("p2"),p3("p3"),ms("ms"),l("l"),s("s"),m1s("m1s"),m2s("m2s"),m3s("m3s"); symbol l1("l1"),l2("l2"),l3("l3"),l4("l4"),t("t"),p4("p4"),p5("p5"),tp("tp"),v1("v1"),v2("v2"),l5("l5"); symbol k1("k1"),k2("k2"),k3("k3"),k4("k4"),k5("k5"),ms1("ms1"),ms2("ms2"),ms3("ms3"),ms4("ms4"); // oneloop box // UFXmap l45 = UF(lst(k),lst(pow(k,2),pow(k+p1,2),pow(k+p1+p2,2),pow(k+p1+p2+p3,2)),lst(pow(p1,2)==0,pow(p2,2)==0)); // MBintegral root_int(l45,lst(1,1,1,1),1); //two loop box bubble // UFXmap l45 = UF(lst(k,l),lst(pow(k,2),pow(k+p1,2),pow(k+p1+p2,2),pow(l+p1+p2,2),pow(l+p1+p2+p3,2),pow(l,2),pow(k-l,2)),lst(pow(p1,2)==0,pow(p2,2)==0,pow(p3,2)==0)); //MBintegral root_int(l45,lst(1,1,1,1,1,1,1),2); // B0 // UFXmap l45 = UF(lst(k),lst(ms-pow(k,2),ms-pow(-k,2)),lst(ms==1)); // MBintegral root_int(l45,lst(1,1),1); // 2 loop sunrise //UFXmap l45 = UF(lst(k,q),lst(ms-pow(k,2),ms-pow(-q-k,2),ms-pow(q,2)),lst(ms==1)); //MBintegral root_int(l45,lst(1,1,1),2); //RoMB_planar box2loop(lst(k,l),lst(pow(k,2),pow(k+p1,2),pow(k+p1+p2,2),pow(l+p1+p2,2),pow(l+p1+p2+p3,2),pow(l,2),pow(k-l,2)),lst(pow(p1,2)==0,pow(p2,2)==0,pow(p3,2)==0),lst(1,1,1,1,1,1,1),2); // RoMB_planar box1loop(lst(k),lst(pow(k,2),pow(k+p1,2)-ms,pow(k+p1+p2,2),pow(k+p1+p2+p3,2)),lst(pow(p1,2)==0,pow(p2,2)==0,pow(p3,2)==0,p1==0,p2==0,p3==0,ms==1),lst(1,1,1,1),1); // RoMB_planar B0_1loop(lst(k),lst(pow(k,2)-ms,pow(p+k,2)-ms),lst(ms==0,pow(p,2)==1),lst(1,1),1); // RoMB_planar C0_1loop(lst(k),lst(pow(k,2)-ms,pow(p1+k,2)-ms,pow(p1+p2+k,2)),lst(ms==1,pow(p1,2)==0,pow(p2,2)==0,p1*p2==50),lst(1,1,1),1); //cout<<" new point "<<endl<<root_int.new_point()<<endl; // cout<<" saved point "<<endl<<root_int.get_point()<<endl; // MBcontinue(root_int); //cout<<MB_lst(l45,lst(1,1,1,1),1).expand()<<endl; // RoMB_loop_by_loop box2loop(lst(k,l),lst(pow(k,2),pow(k+p1,2),pow(k+p1+p2,2),pow(l+p1+p2,2),pow(l+p1+p2+p3,2),pow(l,2),pow(k-l,2)),lst(pow(p1,2)==0,pow(p2,2)==0,pow(p3,2)==0),lst(1,1,1,1,1,1,1)); // RoMB_loop_by_loop t2(lst(k,l), lst(pow(k,2),pow(p+k,2),pow(p+k+l,2),pow(l,2),pow(k+l,2)),lst(pow(p,2)==1),lst(1,1,1,1,1)); // works!!! // RoMB_loop_by_loop sunset(lst(k,l), lst(pow(k,2)-1,pow(p-k-l,2)-4,pow(l,2)-5),lst(pow(p,2)==s),lst(1,1,1)); // RoMB_loop_by_loop sunset(lst(k,l), lst(pow(k,2)-m1s,pow(-k-l,2)-m2s,pow(l,2)-m3s),lst(pow(p,2)==s),lst(1,1,1)); // sunset.integrate(lst(m1s==1,m2s==1,m3s==1,s==0),0); // bubble sunset 2=loop // RoMB_loop_by_loop sunset_bub(lst(k,l), lst(-pow(k,2)+ms,-pow(-k-l,2)+ms,-pow(l,2)+ms),lst(pow(p,2)==0),lst(1,1,1)); // sunset_bub.integrate_map(lst(ms==1,m2s==1,m3s==1,s==0),1); // bubble sunset 3=loop //#define TOPO 1 //#if TOPO==1 /****************************************************************** * FRESULT for parameters: {ms==1,m2s==1,m3s==1,s==0} * * FRESULT anl : = 21.308685443306456902+23/3*eps^(-2)+2*eps^(-3)+35/2*eps^(-1) * FRESULT num: = 21.308685443306456902+(7.6666666666666666665)*eps^(-2)+(2.0)*eps^(-3)+(17.5)*eps^(-1) * eps^-3 term: 2 +/- 0 * eps^-2 term: 23/3 +/- 0 * eps^-1 term: 35/2 +/- 0 * eps^0 term: 21.308685443306456902 +/- 0.01814768000077260732 ***************************************************************/ // RoMB_loop_by_loop sunset_bub(lst(p,k,l), lst(-pow(p,2)+ms,-pow(k,2)+ms,-pow(l,2)+ms,-pow(-p-k-l,2)+ms),lst(pow(l3,2)==s),lst(1,1,1,1)); // sunset_bub.integrate_map(lst(ms==1,m2s==1,m3s==1,s==0),1); //#elif TOPO==2 // RoMB_loop_by_loop sunset_bub_d(lst(l1,l2,l3), lst(-pow(l1,2)+ms,-pow(l2,2)+ms,-pow(l3,2)+ms,-pow(l1+l2,2)+ms,-pow(l1+l2+l3,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1)); // sunset_bub_d.integrate_map(lst(ms==1,m2s==1,m3s==1,s==0),1); //#elif TOPO==3 // RoMB_loop_by_loop sunset_bub_e(lst(l1,l2,l3), lst(-pow(l1,2)+ms,-pow(l2,2)+ms,-pow(l3,2)+ms,-pow(l1-l2,2)+ms,-pow(l2-l3,2)+ms,-pow(l3-l1,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1,1)); // sunset_bub_e.integrate_map(lst(ms==1,m2s==1,m3s==1,s==0),1); //#endif //bubble 4-loop // RoMB_loop_by_loop sunset_bub(lst(k,l1,l2,l3), lst(-pow(k,2)+ms,-pow(l2,2)+ms,-pow(l1,2)+ms,-pow(l3,2)+ms,-pow(k+l1+l2+l3,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1)); // sunset_bub.integrate(lst(ms==1,m2s==1,m3s==1,s==0),0); #define TOPO 5 #if TOPO==1 //bubble 5-loop /* FRESULT for parameters: {ms==1,m2s==1,m3s==1,s==0} FRESULT anl : = 274.5475357301444122+1247/24*eps^(-3)+6/5*Pi^4+(125.67152533053854918)*eps^(-2)+3*eps^(-5)+33/2*eps^(-4)+(259.98755698571087874)*eps^(-1)-110/3*zeta(3) FRESULT num: = 347.3630251884288798+(51.958333333333333332)*eps^(-3)+(125.67152533053854918)*eps^(-2)+(3.0)*eps^(-5)+(16.5)*eps^(-4)+(259.98755698571087874)*eps^(-1) eps^-5 term: 3 +/- 0 eps^-4 term: 33/2 +/- 0 eps^-3 term: 1247/24 +/- 0 eps^-2 term: 125.67152533053854918 +/- 5.2760713655226570643E-5 eps^-1 term: 259.98755698571087874 +/- 9.888628922902401464E-6 eps^0 term: 274.5475357301444122+6/5*Pi^4-110/3*zeta(3) +/- 0.043609817405085687474 */ RoMB_loop_by_loop sunset_bub5(lst(l3,k,l1,l2,l4), lst(-pow(l3,2)+ms,-pow(k,2)+ms,-pow(l1,2)+ms,-pow(l2,2)+ms,-pow(l4,2)+ms,-pow(k+l1+l2+l3+l4,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1,1)); sunset_bub5.integrate_map(lst(ms==1,m2s==1,m3s==1,s==0),1); #elif TOPO==2 RoMB_loop_by_loop sunset_bubC2(lst(l1,l2,l3,l4,l5), lst(-pow(l3,2)+ms,-pow(l5,2)+ms,-pow(l1,2)+ms,-pow(l2,2)+ms,-pow(l4,2)+ms,-pow(l5+l1+l2,2)+ms,-pow(l5+l3+l4,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1,1,1)); sunset_bubC2.integrate_map(lst(ms==1,m2s==1,m3s==1,s==0),0); // RoMB_loop_by_loop sunset_bubC2(lst(l1,l2,l3,l4,l5), lst(-pow(l3,2)+ms,-pow(l5,2)+ms,-pow(l1,2)+ms,-pow(l2,2)+ms,-pow(l4,2)+ms,-pow(l3+l4+l5,2)+ms,-pow(l1+l2+l5+l3+l4,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1,1,1)); // sunset_bubC2.integrate_map(lst(ms==1,m2s==1,m3s==1,s==0),0); // RoMB_loop_by_loop sunset_bubC1(lst(l1,l2,l3,l4,l5), lst(-pow(l3,2)+ms,-pow(l5,2)+ms,-pow(l1,2)+ms,-pow(l2,2)+ms,-pow(l4,2)+ms,-pow(l2+l3+l4+l5,2)+ms,-pow(l1+l2+l5+l3+l4,2)+ms),lst(pow(p,2)==s),lst(1,1,1,1,1,1,1),true); // sunset_bubC1.integrate_map(lst(ms==1,m2s==1,m3s==1,s==0),0); /* MEGA 5-LOOP BUBBLE with 12 propagators */ //RoMB_loop_by_loop l5p12(lst(k5,k2,k1,k4,k3),lst(-pow(k1,2)+ms,-pow(k2,2)+ms,-pow(k3,2)+ms,-pow(k4,2)+ms,-pow(k5,2)+ms, //-pow(k1-k3,2)+ms,-pow(k1-k4,2)+ms,-pow(k3-k2,2)+ms,-pow(k2-k4,2)+ms,-pow(k5+k3-k1,2)+ms,-pow(k5+k3-k2,2)+ms,-pow(k5+k3-k4,2)+ms),lst(pow(p,2)==0),lst(1,1,1,1,1,1,1,1,1,1,1,1)); //l5p12.integrate(lst(ms==0),0); #elif TOPO==3 /* FRESULT for parameters: {ms==1} FRESULT anl : = 1/5400*eps^(-2)*(-1540485.6006392892897+233937*zeta(3)-1505*Pi^4+6656*Pi^2)-1/10*(233.57451266786976057+Pi^2)*eps^(-4)-1/4*eps^(-6)+1/216000*eps^(-1)*(-7.391571256935002719E7+37697940*zeta(3)-40800*zeta(3)*Pi^2-727494*Pi^4+12801600*zeta(5)-1399535*Pi^2)-(3.7800000113486752996)*eps^(-5)+1/1200*(-100893.525326654920406+5280*zeta(3)-349*Pi^2)*eps^(-3) FRESULT num: = -(465.22101564968708165)*eps^(-1)-(0.25)*eps^(-6)-(24.344411706895911919)*eps^(-4)-(3.7800000113486752996)*eps^(-5)-(81.65929734496037395)*eps^(-3)-(248.18307592543818119)*eps^(-2) eps^-6 term: -1/4 +/- 0 eps^-5 term: -3.7800000113486752996 +/- 3.2541102943124789963E-10 eps^-4 term: -23.357451266786976057-1/10*Pi^2 +/- 2.7206664064692618508E-5 eps^-3 term: -84.07793777221243367+22/5*zeta(3)-349/1200*Pi^2 +/- 1.5019954980075151021E-4 eps^-2 term: -285.2751112294980166+25993/600*zeta(3)-301/1080*Pi^4+832/675*Pi^2 +/- 0.00206337770109377918 eps^-1 term: -342.20237300625012586+69811/400*zeta(3)-17/90*zeta(3)*Pi^2-121249/36000*Pi^4+889/15*zeta(5)-279907/43200*Pi^2 +/- 6.187359464224749039 */ RoMB_loop_by_loop l5c1(lst(k2,k5,k3,k4,k1),lst(-pow(k3,2)+ms,-pow(k2,2)+ms,-pow(k1,2)+ms,-pow(k4,2)+ms,-pow(k5,2)+ms, -pow(k1+k3+k4,2)+ms,-pow(k2+k5-k3-k4,2)+ms),lst(pow(p,2)==0),lst(1,1,1,1,1,1,1)); l5c1.integrate_map(lst(ms==1),0); #elif TOPO==4 // point in 2 RoMB_loop_by_loop l5c1(lst(k2,k5,k3,k4,k1),lst(-pow(k3,2)+ms,-pow(k2,2)+ms,-pow(k1,2)+ms,-pow(k4,2)+ms,-pow(k5,2)+ms, -pow(k1+k3+k4,2)+ms,-pow(k2+k5-k3-k4,2)+ms),lst(pow(p,2)==0),lst(1,2,1,1,1,1,1)); l5c1.integrate_map(lst(ms==1),0); #elif TOPO==5 // point in 1 RoMB_loop_by_loop l5c1(lst(k2,k5,k3,k4,k1),lst(-pow(k3,2)+ms,-pow(k2,2)+ms,-pow(k1,2)+ms,-pow(k4,2)+ms,-pow(k5,2)+ms, -pow(k1+k3+k4,2)+ms,-pow(k2+k5-k3-k4,2)+ms),lst(pow(p,2)==0),lst(2,1,1,1,1,1,1)); l5c1.integrate_map(lst(ms==1),0); #endif // RoMB_loop_by_loop t2loop(lst(l,k), lst(-pow(k,2)+ms,-pow(p+k,2)+ms,-pow(p+k+l,2)+ms,-pow(k+l,2)+ms,-pow(l,2)+ms),lst(pow(p,2)==s,ms==0),lst(1,1,1,1,1)); //t2loop.integrate_map(lst(s==-1,ms == 0),3); /* RoMB_loop_by_loop bubble_five_loop(lst(k,l1,l2,l3,l4), lst(pow(k,2)-ms,pow(l1,2)-ms,pow(l2,2)-ms,pow(l3,2)-ms,pow(l4,2)-ms,pow(k+l1,2)-ms,pow(k+l1+l2,2)-ms,pow(k+l1+l2+l3,2)-ms,pow(k+l1+l2+l3+l4,2)-ms,pow(k+l1+l2+l3,2)-ms,pow(k+l1+l2,2)-ms,pow(k+l1,2)-ms), lst(ms==1), lst(1,1,1,1,1,1,1,1,1,1,1,1)); */ // works!!! // RoMB_loop_by_loop B0_1loop_lbl(lst(k),lst(pow(k,2)-2-ms,pow(p+k,2)-ms),lst(ms==0,pow(p,2)==1),lst(2,1)); // RoMB_loop_by_loop B0_1loop_lbl(lst(k),lst(pow(k,2)-m1s,pow(p+k,2)-m2s),lst(pow(p,2)==s),lst(1,1)); // B0_1loop_lbl.integrate(lst(s==-1,m1s==1,m2s==1)); //MB works??? // RoMB_loop_by_loop C0_1loop_lbl(lst(k),lst(pow(k,2),pow(k+p1,2)-m1s,pow(k-p2,2)-m2s),lst(ms==1,pow(p1,2)==m1s,pow(p2,2)==m2s,p1*p2==(s-m1s-m2s)/2),lst(1,1,1)); // C0_1loop_lbl.integrate(lst(m1s==1,m2s==1,s==-100)); //MB works??? /* RoMB_loop_by_loop box1loopm0(lst(k),lst(-pow(k,2),-pow(k+p1,2),-pow(k+p1+p2,2),-pow(k+p1+p2+p4,2)), lst(pow(p1,2)==0,pow(p2,2)==0,pow(p4,2)==0, p1*p2==-s/2,// p1*p4==s/2+t/2,// p2*p4==-t/2 // ), lst(1,1,1,1),false); box1loopm0.integrate_map(lst(s==3,t==1)); box1loopm0.integrate(lst(s==5,t==2)); */ //MASIVE BOX LBL /* RoMB_loop_by_loop box1loopm(lst(k),lst(-pow(k,2)+ms,-pow(k+p1,2)+ms,-pow(k+p1+p2,2)+ms,-pow(k+p1+p2+p4,2)+ms), lst(pow(p1,2)==0,pow(p2,2)==0,pow(p4,2)==0, p1*p2==-s/2,// p1*p4==(s/2+t/2),// p2*p4==-t/2 // ), lst(1,1,1,1),false); box1loopm.integrate_map(lst(ms1==1,ms2==1,ms3==1,ms4==1,ms==1,s==30,t==5)); */ //triple box /* RoMB_loop_by_loop tribox1loopm(lst(k1,k2,k3),lst(-pow(k1,2)+ms,-pow(k1+p1,2),-pow(k1+p1+p2,2)+ms, -pow(k1-k2,2),-pow(k2,2)+ms,-pow(k2+p1+p2,2)+ms, -pow(k2-k3,2),-pow(k3,2)+ms,-pow(k3+p1+p2,2)+ms, -pow(k3-p3,2)), lst(pow(p1,2)==ms,pow(p2,2)==ms,pow(p3,2)==ms,pow(p4,2)==ms, p1*p2==s/2-ms,// p1*p3==t/2-ms,// p2*p3==ms-(s+t)/2 // ), lst(1,1,1,1,1,1,1,1,1,1),true); tribox1loopm.integrate_map(lst(ms1==1,ms2==1,ms3==1,ms4==1,ms==1,s==-1/2,t==-3)); */ //double box /* RoMB_loop_by_loop dobox1loopm(lst(k1,k2),lst(-pow(k1,2),-pow(k1+p1,2),-pow(k1+p1+p2,2), -pow(k1-k2,2),-pow(k2,2),-pow(k2+p1+p2,2), -pow(k2-p3,2)), lst(pow(p1,2)==0,pow(p2,2)==0,pow(p3,2)==0,pow(p4,2)==0, p1*p2==s/2,// p1*p3==t/2,// p2*p3==-(s+t)/2 // ), lst(1,1,1,1,1,1,1),true); dobox1loopm.integrate_map(lst(ms1==1,ms2==1,ms3==1,ms4==1,ms==1,s==-1/2,t==-3)); */ /* 4-loop tadpole */ /* RoMB_loop_by_loop tad4(lst(l1, l2, l3, l4),lst(-pow(l1,2)+ ms,-pow(l2,2)+ ms,-pow(l3 ,2)+ ms,-pow(l4,2),-pow(l1+l2+l3+l4,2)),lst(),lst(1,1,1,1,1)); tad4.integrate_map(lst(ms == 1),1); */ /* Pentagon */ /* RoMB_loop_by_loop pent(lst(k1),lst(-pow(p1 + k1,2)+ ms,-pow(p1 + p5 + k1,2), -pow(p1 + p5 + p4 + k1,2)+ ms,-pow(p1 + p5 + p4 + p3 + k1,2)+ ms, -pow(k1,2)), lst( p1*p1 == ms, p2*p2 == ms, p3*p3 == 0, p4*p4 == ms, p5*p5 == ms, p1*p2 == 1/2* (tp - 2* ms), p1*p3 == 1/2* (t - tp - v1), p1*p4 == ms - 1/2* (s + t - v1), p1*p5 == 1/2* (s - 2* ms), p2* p3 == 1/2* v1, p2* p4 == 1/2* (s - 2* ms - v1 - v2), p2* p5 == ms - 1/2* (s + tp - v2), p3* p4 == 1/2* v2, p3* p5 == 1/2* (tp - t - v2), p4* p5 == 1/2* (t - 2* ms)), lst(1,1,1,1,1)); pent.integrate_map(lst(s==-2,t==-3,v2==-4,tp==-5,v1==-6,ms==1)); */ /* RoMB_loop_by_loop pent(lst(k1),lst(-pow(p1 + k1,2)+ ms,-pow(p1 + p5 + k1,2), -pow(p1 + p5 + p4 + k1,2)+ ms,-pow(p1 + p5 + p4 + p3 + k1,2)+ ms, -pow(k1,2)), lst( p1*p1 == ms, p2*p2 == ms, p3*p3 == 0, p4*p4 == ms, p5*p5 == ms, p1*p2 == 1/2* (tp - 2* ms), wild(1)*p1*p3 == wild(1)*1/2* (t - tp - v1), wild(2)*p1*p4 == wild(2)*(ms - 1/2* (s + t - v1)), wild(3)* p1*p5 == wild(3)*1/2* (s - 2* ms), wild(4)*p2* p3 == wild(4)*1/2* v1, wild(5)*p2* p4 == wild(5)*1/2* (s - 2* ms - v1 - v2), wild(6)*p2* p5 ==wild(6)*( ms - 1/2* (s + tp - v2)), wild(7)*p3* p4 == wild(7)*1/2* v2, wild(8)*p3* p5 == wild(8)*1/2* (tp - t - v2), wild()*p4* p5 == wild()*1/2* (t - 2* ms)), lst(1,1,1,1,1)); pent.integrate_map(lst(s==-2,t==-3,v2==-4,tp==-5,v1==-6,ms==1)); */ } catch(std::exception &p) { std::cerr<<"******************************************************************"<<endl; std::cerr<<" >>>ERROR: "<<p.what()<<endl; std::cerr<<"******************************************************************"<<endl; return 1; } return 0; }
static double lobatto_fn_4(double x) { return l4(x); }