int main () { Tree t1(1), t2("u"), t3(5); Tree t4(t1,"*",t2); Tree t5("-",t3); t4(12.0, 0, 0); t5.value(); Tree t6(t1,"/",t3); t6(12.12,0,0); Tree t7(t1,"+",t5); t7.value(); }
int main() { printf("pid=%d, tid=%d\n", ::getpid(), xnet::CurrentThread::tid()); xnet::Thread t1(threadFunc); t1.start(); t1.join(); xnet::Thread t2(boost::bind(threadFunc2, 42), "thread for free function with argument"); t2.start(); t2.join(); Foo foo(87.53); xnet::Thread t3(boost::bind(&Foo::memberFunc, &foo), "thread for member function without argument"); t3.start(); t3.join(); xnet::Thread t4(boost::bind(&Foo::memberFunc2, boost::ref(foo), std::string("Testing..."))); t4.start(); t4.join(); printf("number of created threads %d\n", xnet::Thread::numCreated()); }
int main(void) { Thread t1(philosopher, (void *) 0); Thread t2(philosopher, (void *) 1); Thread t3(philosopher, (void *) 2); Thread t4(philosopher, (void *) 3); philosopher((void *) 4); }
void test_relational() { cout << "test_relational" << endl; sc_time t1; sc_time t2( 1, SC_FS ); sc_time t3( 1.2345, SC_NS ); sc_time t4( 1.2341, SC_NS ); sc_time t5( -1.5432, SC_NS ); cout << ( t1 == t2 ) << endl; cout << ( t1 != t2 ) << endl; cout << ( t1 < t2 ) << endl; cout << ( t1 <= t2 ) << endl; cout << ( t1 > t2 ) << endl; cout << ( t1 >= t2 ) << endl; cout << ( t3 == t4 ) << endl; cout << ( t3 != t4 ) << endl; cout << ( t3 < t4 ) << endl; cout << ( t3 <= t4 ) << endl; cout << ( t3 > t4 ) << endl; cout << ( t3 >= t4 ) << endl; cout << ( t1 == t5 ) << endl; cout << ( t1 != t5 ) << endl; cout << ( t1 < t5 ) << endl; cout << ( t1 <= t5 ) << endl; cout << ( t1 > t5 ) << endl; cout << ( t1 >= t5 ) << endl; }
int main() { U u; V v; W w; X x; // Direct initialization: T t1( u ); T t2( v ); T t3( w ); T t4( x ); // Copy initialization: T t5 = u; T t6 = v; // { dg-error "" } T t7 = w; T t8 = x; // { dg-error "" } // Cast notation: T t9 = (T) u; T t10 = (T) v; T t11 = (T) w; T t12 = (T) x; // Static cast: T t13 = static_cast<T>( u ); T t14 = static_cast<T>( v ); T t15 = static_cast<T>( w ); T t16 = static_cast<T>( x ); // Function-style cast: T t17 = T( u ); T t18 = T( v ); T t19 = T( w ); T t20 = T( x ); return 0; }
bool replace_test( ) { bool rc = true; const std::string s1( "Insert me!" ); std::string t1( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); t1.replace( 0, std::string::npos, s1, 0, std::string::npos ); if( t1 != "Insert me!" || INSANE( t1 ) ) FAIL std::string t2( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); t2.replace( 0, 1, s1, 0, std::string::npos ); if( t2 != "Insert me!BCDEFGHIJKLMNOPQRSTUVWXYZ" || INSANE( t2 ) ) FAIL std::string t3( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); t3.replace( 1, 0, s1, 0, 1 ); if( t3 != "AIBCDEFGHIJKLMNOPQRSTUVWXYZ" || INSANE( t3 ) ) FAIL std::string t4( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); t4.replace( 26, 0, s1, 0, std::string::npos ); if( t4 != "ABCDEFGHIJKLMNOPQRSTUVWXYZInsert me!" || INSANE( t4 ) ) FAIL std::string t5( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); t5.replace( 4, 3, s1, 2, 5 ); if( t5 != "ABCDsert HIJKLMNOPQRSTUVWXYZ" || INSANE( t5 ) ) FAIL std::string t6( "Shorty" ); t6.replace( 1, 2, s1, 0, 2 ); if( t6 != "SInrty" || INSANE( t6 ) ) FAIL // Need to test other replace methods. return( rc ); }
int main( int argc, char* argv [ ] ) { tree t0("a"); tree t1( std::string( "b" )); tree t2( std::string( "c" )); tree td("d", {t1, t2}); tree t3 = tree( std::string( "f" ), {t0, td} ); tree t4("h"); std::cout << "moving:\n\t" << t4 << "\n\t"; t4 = t3; std::cout << t4 << "\n"; t3.replacefunctor("changed"); std::cout << "changed functor\n\t" << t4 << " >> " << t3 << "\n"; std::cout << "replacesubtree b -> bb:[c, a] :\n\t" << td << " >> "; tree t5 = tree("bb", {t0, t2}); td.replacesubtree(0, t5); std::cout << td << "\n"; tree t6 = subst(t4, "b", tree("alpha", {tree("beta"), tree("gamma")})); std::cout << "subst:\n\t" << t4 << " >> " << t6 << '\n'; std::cout << "addreses:\nnode changes:\n\t" << t4.getaddress() << " >> " << t6.getaddress() << "\nnode doesn't change:\n\t" << t4[0].getaddress() << " >> " << t6[0].getaddress() << '\n'; return 0; }
int main(int argc, char* argv[]) { auto master_thread_id = std::this_thread::get_id(); auto lambda_f = [=]() { auto thread_id = std::this_thread::get_id(); if (thread_id == master_thread_id) { std::lock_guard<std::mutex> l(cout_mutex); std::cout << "Master thread. ID=" << thread_id << std::endl; } else { std::lock_guard<std::mutex> l(cout_mutex); std::cout << "Child thread. ID=" << thread_id << std::endl; } }; ScopedThread t1(lambda_f); ScopedThread t2(lambda_f); ScopedThread t3(lambda_f); ScopedThread t4(lambda_f); ScopedThread t5(lambda_f); lambda_f(); }
void test_print() { cout << "test_print" << endl; sc_time t1; cout << t1 << endl; uint64 v = 1230; sc_time t2( v, false ); cout << t2 << endl; v *= 10000; sc_time t3( v, false ); cout << t3 << endl; v *= 100; sc_time t4( v, false ); cout << t4 << endl; v *= 10000; sc_time t5( v, false ); cout << t5 << endl; v *= 100; sc_time t6( v, false ); cout << t6 << endl; v *= 10000; sc_time t7( v, false ); cout << t7 << endl; }
bool iterator_replace_test( ) { bool rc = true; const std::string s1( "Insert me!" ); std::string t1( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); t1.replace( t1.begin( ), t1.end( ), s1 ); if( t1 != "Insert me!" || INSANE( t1 ) ) FAIL std::string t2( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); t2.replace( t2.begin( ), t2.begin( ) + 1, s1 ); if( t2 != "Insert me!BCDEFGHIJKLMNOPQRSTUVWXYZ" || INSANE( t2 ) ) FAIL std::string t3( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); t3.replace( t3.end( ), t3.end( ), s1 ); if( t3 != "ABCDEFGHIJKLMNOPQRSTUVWXYZInsert me!" || INSANE( t3 ) ) FAIL std::string t4( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); t4.replace( t4.begin( ) + 4, t4.begin( ) + 7, s1 ); if( t4 != "ABCDInsert me!HIJKLMNOPQRSTUVWXYZ" || INSANE( t4 ) ) FAIL std::string t5( "Shorty" ); t5.replace( t5.begin( ), t5.begin( ) + 2, 2, 'x' ); if( t5 != "xxorty" || INSANE( t5 ) ) FAIL // Need to test other iterator replace methods. return( rc ); }
int main(void) { vector<int> ret; TreeNode root(1); TreeNode t2(2); TreeNode t3(3); TreeNode t4(4); TreeNode t5(5); TreeNode t6(6); TreeNode t7(7); TreeNode t8(8); TreeNode t9(9); TreeNode t10(10); root.left = &t2; root.right = &t3; t2.left = &t4; t3.left = &t5; t3.right = &t6; t5.left = &t7; t6.left = &t8; t6.right = &t9; t8.left = &t10; Solution s; ret = s.preorderTraversal(&root); for(auto it = ret.begin(); it != ret.end(); ++it) { std::cout << *it << " "; } std::cout << std::endl; }
int test11() { context ctx(MAGIC_VALUE11); { exc_test t1(ctx, MAGIC_VALUE11_2); try { exc_test t2(ctx, MAGIC_VALUE11_2); throw exc_test(ctx, MAGIC_VALUE11); // this magic value is expected to be catched in ff_throw() and captured in context::state } catch (exc_test&) { exc_test t3(ctx, MAGIC_VALUE11_2); try { exc_test t4(ctx, MAGIC_VALUE11_2); ff_throw(ctx); } catch (exc_test&) { exc_test t5(ctx, MAGIC_VALUE11_2); ctx.state = UNEXPECTED_CATCH1; } } } return ctx.balance(); }
int main(int argc, const char *argv[]) { int accu = 0; for (size_t bite = 0; bite < 64; ++bite) { pong p; moost::Thread t1(p); moost::Thread t2(p); moost::Thread t3(p); moost::Thread t4(p); moost::Thread t5(p); moost::Thread t0(&ping); moost::Thread t01(&ping); moost::Thread t02(&ping); moost::Thread t03(&ping); moost::Thread t04(&ping); t0.join(); t01.join(); t02.join(); t03.join(); t04.join(); t1.join(); t2.join(); t3.join(); t4.join(); t5.join(); accu = i; } if (accu == 0) std::cout << "OK" << std::endl; else std::cout << "KO" << std::endl; return (0); }
int main() { TreeNode root1(1); TreeNode root2(1); TreeNode t2(2); TreeNode t3(3); TreeNode t4(4); TreeNode t5(5); TreeNode t6(6); TreeNode t7(7); TreeNode t8(8); TreeNode t9(9); root1.left = &t2; root1.right = &t3; root2.left = &t2; root2.right = &t3; t2.left = &t4; t2.right = &t5; t3.right = &t6; t4.left = &t7; t4.right = &t8; t8.left = &t9; Solution s; std::cout << s.isSameTree(&root1, &root2) << std::endl; return 0; }
int CC_Client::run_basic_tests (void) { Test_Single_Lock_With_Mode t1 (naming_service_, CosConcurrencyControl::read); Test_Single_Lock_With_Mode t2 (naming_service_, CosConcurrencyControl::write); Test_Single_Lock_With_Mode t3 (naming_service_, CosConcurrencyControl::upgrade); Test_Single_Lock_With_Mode t4 (naming_service_, CosConcurrencyControl::intention_read); Test_Single_Lock_With_Mode t5 (naming_service_, CosConcurrencyControl::intention_write); // This test should be run for several different lock mode, but // since we do not support Test_Release_Not_Held_Lock t6 (naming_service_, CosConcurrencyControl::read); if (t1.run () == CC_SUCCESS && t2.run () == CC_SUCCESS && t3.run () == CC_SUCCESS && t4.run () == CC_SUCCESS && t5.run () == CC_SUCCESS && t6.run () == CC_SUCCESS ) return CC_SUCCESS; else return CC_FAIL; }
static const char* op_plus_equal () { std::cout << __func__ << std::endl; ioa::time t1 (1, 500500); ioa::time t2 (-2, -300300); ioa::time t3 (t1); t3 += t1; mu_assert (t3.sec () == 3); mu_assert (t3.usec () == 1000); ioa::time t4 (t1); t4 += t2; mu_assert (t4.sec () == 0); mu_assert (t4.usec () == -799800); ioa::time t5 (t2); t5 += t1; mu_assert (t5.sec () == 0); mu_assert (t5.usec () == -799800); ioa::time t6 (t2); t6 += t2; mu_assert (t6.sec () == -4); mu_assert (t6.usec () == -600600); return 0; }
int main(){ std::cout << std::endl; std::vector<int> randValues; randValues.reserve(size); std::mt19937 engine; std::uniform_int_distribution<> uniformDist(1,10); for ( long long i=0 ; i< size ; ++i) randValues.push_back(uniformDist(engine)); unsigned long long sum= 0; auto start = std::chrono::system_clock::now(); std::thread t1(sumUp,std::ref(sum),std::ref(randValues),0,firBound); std::thread t2(sumUp,std::ref(sum),std::ref(randValues),firBound,secBound); std::thread t3(sumUp,std::ref(sum),std::ref(randValues),secBound,thiBound); std::thread t4(sumUp,std::ref(sum),std::ref(randValues),thiBound,fouBound); t1.join(); t2.join(); t3.join(); t4.join(); std::chrono::duration<double> dur= std::chrono::system_clock::now() - start; std::cout << "Time for addition " << dur.count() << " seconds" << std::endl; std::cout << "Result: " << sum << std::endl; std::cout << std::endl; }
void testmain() { print("struct"); t1(); t2(); t3(); t4(); t5(); t6(); t7(); t8(); t9(); t10(); t11(); t12(); t13(); t14(); unnamed(); assign(); arrow(); incomplete(); bitfield_basic(); bitfield_mix(); bitfield_union(); bitfield_unnamed(); bitfield_initializer(); test_offsetof(); flexible_member(); empty_struct(); }
void tst_QSizeF::scale() { QSizeF t1(10.4, 12.8); t1.scale(60.6, 60.6, Qt::IgnoreAspectRatio); QCOMPARE(t1, QSizeF(60.6, 60.6)); QSizeF t2(10.4, 12.8); t2.scale(43.52, 43.52, Qt::KeepAspectRatio); QCOMPARE(t2, QSizeF(35.36, 43.52)); QSizeF t3(9.6, 12.48); t3.scale(31.68, 31.68, Qt::KeepAspectRatioByExpanding); QCOMPARE(t3, QSizeF(31.68, 41.184)); QSizeF t4(12.8, 10.4); t4.scale(43.52, 43.52, Qt::KeepAspectRatio); QCOMPARE(t4, QSizeF(43.52, 35.36)); QSizeF t5(12.48, 9.6); t5.scale(31.68, 31.68, Qt::KeepAspectRatioByExpanding); QCOMPARE(t5, QSizeF(41.184, 31.68)); QSizeF t6(0.0, 0.0); t6.scale(200, 240, Qt::IgnoreAspectRatio); QCOMPARE(t6, QSizeF(200, 240)); QSizeF t7(0.0, 0.0); t7.scale(200, 240, Qt::KeepAspectRatio); QCOMPARE(t7, QSizeF(200, 240)); QSizeF t8(0.0, 0.0); t8.scale(200, 240, Qt::KeepAspectRatioByExpanding); QCOMPARE(t8, QSizeF(200, 240)); }
void *t2() { char currchar = alphabet[t2c]; printf("%c\n", currchar); t2c ++; t2c = t2c%25; t4(); }
int main(void) { TensorStructure s(3,"ab"); // Tensor<DataMesh> t1(s); // will fail to compile const Mesh m(IPoint(MV::fill,2,2)); Tensor<DataMesh> t2(s,m); // will be fine Tensor<DataMesh> t3(s,m, 0.0); // this initializes all DataMesh points to zero Tensor<DataMesh> t4(3,"ab",m, 0.0); // this is the same as before }
int main () { if (t2 () != 4096) abort (); if (t4 () != 4096) abort (); exit (0); }
int main() { std::thread t1(waits, 1), t2(waits, 2), t3(waits, 3), t4(signals); t1.join(); t2.join(); t3.join(); t4.join(); }
void test() { const unsigned runs = 1000; unsigned next_progress_report = 10, progress; last_error_count = 0; engine.seed(std::time(0)); BOOST_TEST_EQ(Number(), 0); for (unsigned r = 1; r <= runs; ++r) { progress = 100 * r / runs; while (progress >= next_progress_report) { std::cout << "..." << progress << "%"; std::cout.flush(); next_progress_report += 10; } a = kanooth::numbers::generate_random_bits_number<ref_type>(engine, 1000); b = kanooth::numbers::generate_random_bits_number<ref_type>(engine, 512); c = kanooth::numbers::generate_random_bits_number<ref_type>(engine, 256); d = kanooth::numbers::generate_random_bits_number<ref_type>(engine, 32); si = d.convert_to<int>(); ui = si; a1 = static_cast<test_type>(a.str()); b1 = static_cast<test_type>(b.str()); c1 = static_cast<test_type>(c.str()); d1 = static_cast<test_type>(d.str()); t1(); t2(); t3(); t4(); t5(); if(last_error_count != (unsigned)boost::detail::test_errors()) { last_error_count = boost::detail::test_errors(); //std::cout << std::hex << std::showbase; std::cout << "a = " << a << std::endl; std::cout << "a1 = " << a1 << std::endl; std::cout << "b = " << b << std::endl; std::cout << "b1 = " << b1 << std::endl; std::cout << "c = " << c << std::endl; std::cout << "c1 = " << c1 << std::endl; std::cout << "d = " << d << std::endl; std::cout << "d1 = " << d1 << std::endl; } } std::cout << std::endl; }
void tst_QContactActions::testTarget() { // first, create a contact with some details QContact c1; QContactName n1; n1.setFirstName("test"); n1.setLastName("contact"); c1.saveDetail(&n1); QContactPhoneNumber p1; p1.setNumber("12345"); c1.saveDetail(&p1); QContactEmailAddress e1; e1.setEmailAddress("*****@*****.**"); c1.saveDetail(&e1); QList<QContactDetail> dl1; dl1 << p1 << e1; QContactActionTarget t1; // default ctor QContactActionTarget t2(c1); // "whole contact" target QContactActionTarget t3(c1, e1); // "specific detail" target QContactActionTarget t4(c1, dl1); // "detail list" target QCOMPARE(t2.contact(), c1); QCOMPARE(t3.contact(), c1); QCOMPARE(t4.contact(), c1); QCOMPARE(t2.details(), QList<QContactDetail>()); QCOMPARE(t3.details(), QList<QContactDetail>() << e1); QCOMPARE(t4.details(), dl1); QVERIFY(t1 != t2); QVERIFY(t1 != t3); QVERIFY(t1 != t4); QVERIFY(t2 != t3); QVERIFY(t2 != t4); QVERIFY(t3 != t4); QVERIFY(qHash(t2) != qHash(t3)); QVERIFY(qHash(t2) != qHash(t4)); QVERIFY(qHash(t3) != qHash(t4)); QVERIFY(!t1.isValid()); QVERIFY(t2.isValid()); QVERIFY(t3.isValid()); QVERIFY(t4.isValid()); t1.setContact(c1); t1.setDetails(dl1); QVERIFY(t1.isValid()); QVERIFY(t1 == t4); t2 = t1; QVERIFY(t2.isValid()); // check that assignment operator doesn't destroy validity. QVERIFY(t1 == t2); QVERIFY(t2 == t4); QVERIFY(t2 != t3); }
void allocator_tests() { std::allocator<void> alloc; int x = 42; { std::tuple<int&> t(std::ref(x)); assert(&std::get<0>(t) == &x); std::tuple<int&> t1(std::allocator_arg, alloc, std::ref(x)); assert(&std::get<0>(t1) == &x); } { auto r = std::ref(x); auto const& cr = r; std::tuple<int&> t(r); assert(&std::get<0>(t) == &x); std::tuple<int&> t1(cr); assert(&std::get<0>(t1) == &x); std::tuple<int&> t2(std::allocator_arg, alloc, r); assert(&std::get<0>(t2) == &x); std::tuple<int&> t3(std::allocator_arg, alloc, cr); assert(&std::get<0>(t3) == &x); } { std::tuple<int const&> t(std::ref(x)); assert(&std::get<0>(t) == &x); std::tuple<int const&> t2(std::cref(x)); assert(&std::get<0>(t2) == &x); std::tuple<int const&> t3(std::allocator_arg, alloc, std::ref(x)); assert(&std::get<0>(t3) == &x); std::tuple<int const&> t4(std::allocator_arg, alloc, std::cref(x)); assert(&std::get<0>(t4) == &x); } { auto r = std::ref(x); auto cr = std::cref(x); std::tuple<int const&> t(r); assert(&std::get<0>(t) == &x); std::tuple<int const&> t2(cr); assert(&std::get<0>(t2) == &x); std::tuple<int const&> t3(std::allocator_arg, alloc, r); assert(&std::get<0>(t3) == &x); std::tuple<int const&> t4(std::allocator_arg, alloc, cr); assert(&std::get<0>(t4) == &x); } }
int main() { t1 (); t2 (); t3 (); t4 (); return 0; }
int main() { Item i0; Thing t0; Thing t1( t0 ); Thing* t2 = new Thing; std::shared_ptr< Thing > t3( new Thing ); Thing t4( 42 ); delete t2; return 0; }
int main(int argc, char *argv[]) { boost::thread t1(timer); boost::thread t2(func); boost::thread t3(func); boost::thread t4(func); t1.join(); return 0; }
void testmain(void) { print("pointer"); t1(); t2(); t3(); t4(); t5(); t6(); subtract(); }