void driver_actividadeCustoFixo(){ // ActividadeCustoFixo a1("chave1", "trab 1", 13, 9, 1929.98); // std::cout << a1.getCustoActividade() // << std::endl // ; // ActividadeCustoFixo * ptr_a = &a1; // ActividadeCustoFixo a2( *ptr_a, 8.838 ); // std::cout << a2.getCustoActividade() // << std::endl // ; // ActividadeCustoFixo a3("chave3", "trab3", 823, 18, 0.60); // a2 = a3; // std::cout << a2.getCustoActividade() // << std::endl // ; // std::cout << ((a2 == a3) ? "iguais" : "diferentes" ) << std::endl; // std::cout << ((a1 == a2) ? "iguais" : "diferentes" ) << std::endl; // std::cout << ((a1 < a2) ? "menor" : "falso" ) << std::endl; // std::cout << ((a2 > a1) ? "maior" : "falso" ) << std::endl; // std::cout << a2; Lista<Actividade*> la1; ActividadeCustoFixo a1("chave 1", "trab 1", 111.00, HORA, la1, 11.00); Lista<Actividade*> la2; ActividadeCustoFixo a2("chave 2", "trab 2", 222.00, HORA, la2, 22.00); Lista<Actividade*> la3; la3.insere(1, &a2); ActividadeCustoFixo a3("chave 3", "trab 3", 333.00, HORA, la3, 33.00); Lista<Actividade*> la4; ActividadeCustoFixo a4("chave 4", "trab 4", 444.00, HORA, la4, 44.00); std::cout << a3; return; }
/// This test should actually work well. ///Passing these functors by value will bit-copy the pointer addresses, and pointees will be modified. TEST ( multithreading, threadpool2 ) { googletesting::functor_test2 a1 ( 1 ); googletesting::functor_test2 a2 ( 2 ); googletesting::functor_test2 a3 ( 3 ); googletesting::functor_test2 a4 ( 4 ); { uu::TrivialThreadPool tp ( 4 ); tp ( a1 ); tp ( a2 ); tp ( a3 ); tp ( a4 ); } ///Safe to test EXPECT_EQ ( *a1.silly_, 10 ); EXPECT_EQ ( *a2.silly_, 20 ); EXPECT_EQ ( *a3.silly_, 30 ); EXPECT_EQ ( *a4.silly_, 40 ); //Extra careful memory management... delete a1.silly_; delete a2.silly_; delete a3.silly_; delete a4.silly_; user_check_ok = true; ///This should stop execution: { uu::TrivialThreadPool tp ( 0 ); } EXPECT_EQ ( user_check_ok, false ); user_check_ok = true; }
int main() { Matrix a(2,3); a.print(); printf("printing diagonal parts:\n"); print_diagonal(a); Matrix a2(3,3); a2.print(); printf("printing diagonal parts:\n"); print_diagonal(a2); Matrix a3(1,3); a3.print(); printf("printing diagonal parts:\n"); print_diagonal(a3); Matrix a4(4,1); a4.print(); printf("printing diagonal parts:\n"); print_diagonal(a4); Matrix a5(4,3); a5.print(); printf("printing diagonal parts:\n"); print_diagonal(a5); }
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 TestViewAggregateReduction() { #if ! KOKKOS_USING_EXP_VIEW const int count = 2 ; const long result = count % 2 ? ( count * ( ( count + 1 ) / 2 ) ) : ( ( count / 2 ) * ( count + 1 ) ); Kokkos::View< long * , Space > a("a",count); Kokkos::View< long * , Space > b("b",count); Kokkos::View< StaticArray<long,4> * , Space > a4("a4",count); Kokkos::View< StaticArray<long,4> * , Space > b4("b4",count); Kokkos::View< StaticArray<long,10> * , Space > a10("a10",count); Kokkos::View< StaticArray<long,10> * , Space > b10("b10",count); Kokkos::parallel_for( count , FILL<long,Space>(a,b) ); Kokkos::parallel_for( count , FILL< StaticArray<long,4> , Space >(a4,b4) ); Kokkos::parallel_for( count , FILL< StaticArray<long,10> , Space >(a10,b10) ); long r = 0; StaticArray<long,4> r4 ; StaticArray<long,10> r10 ; Kokkos::parallel_reduce( count , DOT<long,Space>(a,b) , r ); Kokkos::parallel_reduce( count , DOT< StaticArray<long,4> , Space >(a4,b4) , r4 ); Kokkos::parallel_reduce( count , DOT< StaticArray<long,10> , Space >(a10,b10) , r10 ); ASSERT_EQ( result , r ); for ( int i = 0 ; i < 10 ; ++i ) { ASSERT_EQ( result , r10.value[i] ); } for ( int i = 0 ; i < 4 ; ++i ) { ASSERT_EQ( result , r4.value[i] ); } #endif }
int main() { std::vector<int> v (5,3); int_cont a1 (3,6); // first constructor int_cont a2 (3u,6); // first constructor int_cont a3 (3,6u); // first constructor int_cont a4 (3u,6u); // first constructor int_cont b(v.begin(),v.end()); // second constructor }
void drive_get_misc_functions() { try { // Get function tests CQLValue a1(Uint64(123)); CQLValue a2(Sint64(-123)); CQLValue a3(Real64(25.24)); CQLValue a4(String("Hellow")); CQLValue a5(Boolean(true)); String _date("20040811105625.000000-360"); CIMDateTime date(_date); CQLValue a6(date); String _date1("20040811105626.000000-360"); CIMDateTime date1(_date1); CQLValue a61(date1); String opStr("MyClass.z=true,y=1234,x=\"Hello World\""); CIMObjectPath op(opStr); CQLValue a7(op); const CIMName _cimName(String("CIM_OperatingSystem")); CIMInstance _i1(_cimName); CQLValue a8(_i1); PEGASUS_TEST_ASSERT(a1.getUint() == Uint64(123)); PEGASUS_TEST_ASSERT(a2.getSint() == Sint64(-123)); PEGASUS_TEST_ASSERT(a3.getReal() == Real64(25.24)); PEGASUS_TEST_ASSERT(a4.getString() == String("Hellow")); PEGASUS_TEST_ASSERT(a5.getBool() == Boolean(true)); PEGASUS_TEST_ASSERT(a6.getDateTime() == CIMDateTime(_date)); PEGASUS_TEST_ASSERT(a6 != a61); PEGASUS_TEST_ASSERT(a6 < a61); PEGASUS_TEST_ASSERT(a7.getReference() == CIMObjectPath(opStr)); try { a1.getSint(); PEGASUS_TEST_ASSERT(0); } catch(...) { PEGASUS_TEST_ASSERT(1); } } catch(Exception & e) { cout << e.getMessage() << endl; PEGASUS_TEST_ASSERT(0); } return; }
void testBook () { Currency const c1 (1); Account const i1 (1); Currency const c2 (2); Account const i2 (2); Currency const c3 (3); Account const i3 (3); Issue a1 (c1, i1); Issue a2 (c1, i2); Issue a3 (c2, i2); Issue a4 (c3, i2); expect (Book (a1, a2) != Book (a2, a3)); expect (Book (a1, a2) < Book (a2, a3)); expect (Book (a1, a2) <= Book (a2, a3)); expect (Book (a2, a3) <= Book (a2, a3)); expect (Book (a2, a3) == Book (a2, a3)); expect (Book (a2, a3) >= Book (a2, a3)); expect (Book (a3, a4) >= Book (a2, a3)); expect (Book (a3, a4) > Book (a2, a3)); std::hash <Book> hash; // log << std::hex << hash (Book (a1, a2)); // log << std::hex << hash (Book (a1, a2)); // // log << std::hex << hash (Book (a1, a3)); // log << std::hex << hash (Book (a1, a3)); // // log << std::hex << hash (Book (a1, a4)); // log << std::hex << hash (Book (a1, a4)); // // log << std::hex << hash (Book (a2, a3)); // log << std::hex << hash (Book (a2, a3)); // // log << std::hex << hash (Book (a2, a4)); // log << std::hex << hash (Book (a2, a4)); // // log << std::hex << hash (Book (a3, a4)); // log << std::hex << hash (Book (a3, a4)); expect (hash (Book (a1, a2)) == hash (Book (a1, a2))); expect (hash (Book (a1, a3)) == hash (Book (a1, a3))); expect (hash (Book (a1, a4)) == hash (Book (a1, a4))); expect (hash (Book (a2, a3)) == hash (Book (a2, a3))); expect (hash (Book (a2, a4)) == hash (Book (a2, a4))); expect (hash (Book (a3, a4)) == hash (Book (a3, a4))); expect (hash (Book (a1, a2)) != hash (Book (a1, a3))); expect (hash (Book (a1, a2)) != hash (Book (a1, a4))); expect (hash (Book (a1, a2)) != hash (Book (a2, a3))); expect (hash (Book (a1, a2)) != hash (Book (a2, a4))); expect (hash (Book (a1, a2)) != hash (Book (a3, a4))); }
exprt string_constraint_generatort::add_axioms_for_last_index_of( const string_exprt &str, const exprt &c, const exprt &from_index) { const refined_string_typet &ref_type=to_refined_string_type(str.type()); const typet &index_type=ref_type.get_index_type(); symbol_exprt index=fresh_exist_index("last_index_of", index_type); symbol_exprt contains=fresh_boolean("contains_in_last_index_of"); // We add axioms: // a1 : -1 <= i <= from_index // a2 : (i=-1 <=> !contains) // a3 : (contains => i <= from_index &&s[i]=c) // a4 : forall n. i+1 <= n < from_index +1 &&contains => s[n]!=c // a5 : forall m. 0 <= m < from_index +1 &&!contains => s[m]!=c exprt index1=from_integer(1, index_type); exprt minus1=from_integer(-1, index_type); exprt from_index_plus_one=plus_exprt(from_index, index1); and_exprt a1( binary_relation_exprt(index, ID_ge, minus1), binary_relation_exprt(index, ID_lt, from_index_plus_one)); axioms.push_back(a1); equal_exprt a2(not_exprt(contains), equal_exprt(index, minus1)); axioms.push_back(a2); implies_exprt a3( contains, and_exprt( binary_relation_exprt(from_index, ID_ge, index), equal_exprt(str[index], c))); axioms.push_back(a3); symbol_exprt n=fresh_univ_index("QA_last_index_of", index_type); string_constraintt a4( n, plus_exprt(index, index1), from_index_plus_one, contains, not_exprt(equal_exprt(str[n], c))); axioms.push_back(a4); symbol_exprt m=fresh_univ_index("QA_last_index_of", index_type); string_constraintt a5( m, from_index_plus_one, not_exprt(contains), not_exprt(equal_exprt(str[m], c))); axioms.push_back(a5); return index; }
/** * @brief Return parameters used for all bands * * Method creates keyword vectors of band specific parameters * used in the photometric correction. * * @author Kris Becker - 2/22/2010 * * @param pvl Output PVL container write keywords */ void Hillier::Report ( PvlContainer &pvl ) { pvl.addComment("I/F = mu0/(mu0+mu) * F(phase)"); pvl.addComment(" where:"); pvl.addComment(" mu0 = cos(incidence)"); pvl.addComment(" mu = cos(incidence)"); pvl.addComment(" F(phase) = B0*exp(-B1*phase) + A0 + A1*phase + A2*phase^2 + A3*phase^3 + A4*phase^4"); pvl += PvlKeyword("Algorithm", "Hillier"); pvl += PvlKeyword("IncRef", toString(_iRef), "degrees"); pvl += PvlKeyword("EmaRef", toString(_eRef), "degrees"); pvl += PvlKeyword("PhaRef", toString(_gRef), "degrees"); PvlKeyword units("HillierUnits"); PvlKeyword phostd("PhotometricStandard"); PvlKeyword bbc("BandBinCenter"); PvlKeyword bbct("BandBinCenterTolerance"); PvlKeyword bbn("BandNumber"); PvlKeyword b0("B0"); PvlKeyword b1("B1"); PvlKeyword a0("A0"); PvlKeyword a1("A1"); PvlKeyword a2("A2"); PvlKeyword a3("A3"); PvlKeyword a4("A4"); for (unsigned int i = 0; i < _bandpho.size(); i++) { Parameters &p = _bandpho[i]; units.addValue(p.units); phostd.addValue(toString(p.phoStd)); bbc.addValue(toString(p.wavelength)); bbct.addValue(toString(p.tolerance)); bbn.addValue(toString(p.band)); b0.addValue(toString(p.b0)); b1.addValue(toString(p.b1)); a0.addValue(toString(p.a0)); a1.addValue(toString(p.a1)); a2.addValue(toString(p.a2)); a3.addValue(toString(p.a3)); a4.addValue(toString(p.a4)); } pvl += units; pvl += phostd; pvl += bbc; pvl += bbct; pvl += bbn; pvl += b0; pvl += b1; pvl += a0; pvl += a1; pvl += a2; pvl += a3; pvl += a4; return; }
void yylex() { /* Declaracao de Variaveis Locais */ int l,s; /* Variaveis de controle do AF */ /* Inicializacao de Variaveis Locais */ l=0;s=0; saida.classe[0]=EOF; saida.classe[1]='\0'; /* AUTOMATO FINITO (AF) */ peg_ch(); while(ch != EOF && s!= FINAL_STATE) { if(compara_simbolo(ch,tab_trans[l])==TRUE) { s=tab_trans[l]->proximo_estado; switch(tab_trans[l]->acao_semantica) { case 1: a1();break; case 2: a2();break; case 3: a3();break; case 4: a4();break; case 5: a5();break; case 6: a6();break; case 7: a7();break; case 8: a8();break; case 9: a9();break; case 10: a10();break; case 11: a11();break; default:; } if(s!=FINAL_STATE) { peg_ch(); l=tab_trans[l]->proxima_transicao; } } else { ++l; if(s==tab_trans[l]->estado_atual) continue; else error("* * Erro Fatal: transicao errada no ANALISADOR LEXICO * *\n"); } } return; }
TEST ( multithreading, threadpool1 ) { googletesting::functor_test a1 ( 1 ), a2 ( 2 ), a3 ( 3 ), a4 ( 4 ); { uu::TrivialThreadPool tp ( 4 ); tp ( a1 ); tp ( a2 ); tp ( a3 ); tp ( a4 ); } EXPECT_EQ ( a1.silly_, 1 ); EXPECT_EQ ( a2.silly_, 2 ); EXPECT_EQ ( a3.silly_, 3 ); EXPECT_EQ ( a4.silly_, 4 ); }
void level_three() { vector<DPipe> DirectPipes(13); vector<DoublePipe> DoublePipes(13); vector<CrossPipe> CrossPipes(2); DPipe a0(50,SCREEN_HEIGHT-50,100,40); DoublePipe b0(150,SCREEN_HEIGHT-50,70,40); DPipe a1(150,SCREEN_HEIGHT-150,100,40); DoublePipe b1(150,SCREEN_HEIGHT-250,70,40); DPipe a2(250,SCREEN_HEIGHT-350,100,40); DoublePipe b2(350,SCREEN_HEIGHT-250,70,40); DPipe a3(350,SCREEN_HEIGHT-350,100,40); DPipe a4(350,SCREEN_HEIGHT-150,100,40); DoublePipe b3(250,SCREEN_HEIGHT-450,70,40); DoublePipe b4(350,SCREEN_HEIGHT-450,70,40); CrossPipe c0(250,SCREEN_HEIGHT-250,100,40); DPipe a5(550,SCREEN_HEIGHT-50,100,40); DoublePipe b5(250,SCREEN_HEIGHT-150,70,40); DoublePipe b6(450,SCREEN_HEIGHT-50,70,40); DoublePipe b7(650,SCREEN_HEIGHT-150,70,40); DPipe a6(550,SCREEN_HEIGHT-50,100,40); DPipe a7(550,SCREEN_HEIGHT-150,100,40); DoublePipe b8(750,SCREEN_HEIGHT-50,70,40); DPipe a8(550,SCREEN_HEIGHT-250,100,40); DoublePipe b9(750,SCREEN_HEIGHT-350,70,40); CrossPipe c1(450,SCREEN_HEIGHT-150,100,40); DoublePipe b10(350,SCREEN_HEIGHT-450,70,40); DPipe a9(750,SCREEN_HEIGHT-150,100,40); DPipe a10(750,SCREEN_HEIGHT-250,100,40); DoublePipe b11(450,SCREEN_HEIGHT-250,70,40); DoublePipe b12(650,SCREEN_HEIGHT-250,70,40); DPipe a11(650,SCREEN_HEIGHT-50,100,40); DPipe a12(850,SCREEN_HEIGHT-350,100,40); DirectPipes[0] = a0; DoublePipes[0] = b0; DirectPipes[1] = a1; DoublePipes[1] = b1; DirectPipes[2] = a2; DoublePipes[2] = b2; DirectPipes[3] = a3; DoublePipes[3] = b3; DirectPipes[4] = a4; DoublePipes[4] = b4; DirectPipes[5] = a5; DoublePipes[5] = b5; DirectPipes[6] = a6; DoublePipes[6] = b6; DirectPipes[7] = a7; DoublePipes[7] = b7; DirectPipes[8] = a8; DoublePipes[8] = b8; DirectPipes[9] = a9; DoublePipes[9] = b9; DirectPipes[10] = a10; DoublePipes[10] = b10; DirectPipes[11] = a11; DoublePipes[11] = b11; DirectPipes[12] = a12; DoublePipes[12] = b12; CrossPipes[0] = c0; CrossPipes[1] = c1; Water a(20,SCREEN_HEIGHT-50,40,40); }
int main() { A a1(1); A a2(a1); A a3(std::move(a2)); A a4(std::forward<A>(5)); std::cout << "a1 = " << a1 << ", " << std::endl << "a2 = " << a2 << ", " << std::endl << "a3 = " << a3 << ", " << std::endl << "a4 = " << a4 << ", " << std::endl; return 0; }
IMPATOM_BEGIN_NAMESPACE HelixRestraint::HelixRestraint(Residues rs, bool ideal) : Restraint(rs[0]->get_model(), "HelixRestraint%1%") { //dihedral info //Float dih1,std1,dih2,std2,distON,kON; Float dih1 = -1.117010721276371; //mean = -64deg, std = 6deg Float std1 = 0.10471975511965977; Float dih2 = -0.715584993317675; //mean = -41deg, std = 8deg Float std2 = 0.13962634015954636; Float corr = -0.25; Float weight = 0.5; core::BinormalTerm bt; bt.set_means(std::make_pair(dih1,dih2)); bt.set_standard_deviations(std::make_pair(std1,std2)); bt.set_correlation(corr); bt.set_weight(weight); //bond info Float distON = 2.96; Float kON = core::Harmonic::get_k_from_standard_deviation(0.11); //will expand to more bonds and residue types bond_ON_score_ = new core::HarmonicDistancePairScore(distON,kON); if (rs.size()>=3){ for(size_t nr=0;nr<rs.size()-2;nr++){ core::XYZ a1(get_atom(rs[nr],AT_C)); core::XYZ a2(get_atom(rs[nr+1],AT_N)); core::XYZ a3(get_atom(rs[nr+1],AT_CA)); core::XYZ a4(get_atom(rs[nr+1],AT_C)); core::XYZ a5(get_atom(rs[nr+2],AT_N)); IMP_NEW(core::MultipleBinormalRestraint, mbr,(get_model(), ParticleIndexQuad(a1,a2,a3,a4), ParticleIndexQuad(a2,a3,a4,a5))); mbr->add_term(bt); dihedral_rs_.push_back(mbr); } } if (rs.size()>=5){ for(size_t nr=0;nr<rs.size()-4;nr++){ bonds_ON_.push_back(ParticleIndexPair( get_atom(rs[nr],AT_O).get_particle_index(), get_atom(rs[nr+4],AT_N).get_particle_index())); } } }
void driver_actividade(){ // Actividade a1( "chave3","trabalho3", 13, MES); // Actividade *ptr_a = &a1; // Actividade a2( *ptr_a ); // std::cout << a2.getIdentificador() << // std::endl << a2.getDescricao() << // std::endl << a2.getDuracao() << // std::endl << a2.getUnidadeDuracao() << // std::endl; // std::cout << ((a1 == a2) ? "a1 == a2\n" : "a1 <> a2\n"); // Actividade a3; // a3.setIdentificador( "key1" ); // a3.setDescricao("encomenda"); // a3.setDuracao(8); // a3.setUnidadeDuracao(MES); // std::cout << a3; // std::cout << ((a1 < a3) ? "a1 < a3\n" : "falso\n"); // std::cout << ((a1 > a3) ? "a1 > a3\n" : "falso\n"); // std::cout << ((a3 > a1) ? "a3 > a1\n" : "falso\n"); // a3 = a1; // std::cout << ((a1 == a3) ? "a1 == a3\n" : "falso\n"); // Actividade a4( "chave4","trabalho4", 34, DIA); Lista<Actividade*> l1; Actividade a1( "chave1","trabalho 1", 134, MES, l1); Lista<Actividade*> l2; Actividade a2( "chave2","trabalho 2", 10, MES, l2); Lista<Actividade*> l3; Actividade a3( "chave3","trabalho 3", 95, MES, l3); Lista<Actividade*> l4; l4.insere(1,&a2); l4.insere(1,&a3); Actividade a4( "chave4","trabalho 4", 813, HORA, l4); Lista<Actividade*> l5; Actividade a5( "chave5","trabalho 5", 87, DIA, l5); Lista<Actividade*> l6; Actividade a6( "chave6","trabalho 6", 934, MES, l6); std::cout << a4; std::cout << a5; //Actividade: // id: chave4 // desc: trabalho 4 // durac: 813 // unidade: 0 // precedentes: 0xbffff938 0xbffff954 }
int main() { try { Integer a,a1(10),a3,a4("123"); Integer a2(a1); cout<<"\nConstructors\n "; cout<<"\nDefault -a : "<<a; cout<<"\nOne argumented -a1 : "<<a1; cout<<"\nCopy Constructor -a2 : "<<a2; cout<<"\nString constructor -a4 : "<<a4; cout<<"\n\nOperations \n"; a3=a1; cout<<"\n a3=a1: "<<a3; a=a1+a2; cout<<"\n a=a1+a2: "<<a; a3=a-a2; cout<<"\n a3=a-a2: "<<a; cout<<"\n a3 : "<<a3; if(a>a3) { cout<<"\n a>a3\n"; cout<<"\n a3-- : "<<a3--; cout<<"\n --a3 : "<<--a3; cout<<"\n ++a3 : "<<++a3; cout<<"\n a3++ : "<<a3++; cout<<"\n a3 : "<<a3<<"\n"; } cout<<" a4 : "<<a4<<"\n"; Integer i1(-4), i2(10); cout << "i1: " << i1 << endl; cout << "OR : It is " << ((i1 || i2) ? "true" : "false") << endl; cout << "AND : It is " << ((i1 && i2 ) ? "true" : "false") << endl; cout << "NOT : It is " << ((! i1) ? "true" : "false") << endl; cout<<"\n>>"; cin>>a3; cout<<" \n a3 : "<<a3<<"\n"; string a5=a4.to_string(); cout<<"a5=a4.to_string() : "<<a5<<"\n"; } catch(Integer::Invalid_argument) { cout<<"\nInvalid Argument \n"; } return 0; }
exprt string_constraint_generatort::add_axioms_for_index_of( const string_exprt &str, const exprt &c, const exprt &from_index) { const typet &index_type=str.length().type(); symbol_exprt index=fresh_exist_index("index_of", index_type); symbol_exprt contains=fresh_boolean("contains_in_index_of"); // We add axioms: // a1 : -1 <= index<|str| // a2 : !contains <=> index=-1 // a3 : contains => from_index<=index&&str[index]=c // a4 : forall n, from_index<=n<index. contains => str[n]!=c // a5 : forall m, from_index<=n<|str|. !contains => str[m]!=c exprt minus1=from_integer(-1, index_type); and_exprt a1( binary_relation_exprt(index, ID_ge, minus1), binary_relation_exprt(index, ID_lt, str.length())); axioms.push_back(a1); equal_exprt a2(not_exprt(contains), equal_exprt(index, minus1)); axioms.push_back(a2); implies_exprt a3( contains, and_exprt( binary_relation_exprt(from_index, ID_le, index), equal_exprt(str[index], c))); axioms.push_back(a3); symbol_exprt n=fresh_univ_index("QA_index_of", index_type); string_constraintt a4( n, from_index, index, contains, not_exprt(equal_exprt(str[n], c))); axioms.push_back(a4); symbol_exprt m=fresh_univ_index("QA_index_of", index_type); string_constraintt a5( m, from_index, str.length(), not_exprt(contains), not_exprt(equal_exprt(str[m], c))); axioms.push_back(a5); return index; }
TEST(ExpressionAlgoIsSubsetOf, PointInUnboundedRange) { ParsedMatchExpression a4("{a: 4}"); ParsedMatchExpression a5("{a: 5}"); ParsedMatchExpression a6("{a: 6}"); ParsedMatchExpression b5("{b: 5}"); ParsedMatchExpression lt5("{a: {$lt: 5}}"); ParsedMatchExpression lte5("{a: {$lte: 5}}"); ParsedMatchExpression gte5("{a: {$gte: 5}}"); ParsedMatchExpression gt5("{a: {$gt: 5}}"); ASSERT_TRUE(expression::isSubsetOf(a4.get(), lte5.get())); ASSERT_TRUE(expression::isSubsetOf(a5.get(), lte5.get())); ASSERT_FALSE(expression::isSubsetOf(a6.get(), lte5.get())); ASSERT_TRUE(expression::isSubsetOf(a4.get(), lt5.get())); ASSERT_FALSE(expression::isSubsetOf(a5.get(), lt5.get())); ASSERT_FALSE(expression::isSubsetOf(a6.get(), lt5.get())); ASSERT_FALSE(expression::isSubsetOf(a4.get(), gte5.get())); ASSERT_TRUE(expression::isSubsetOf(a5.get(), gte5.get())); ASSERT_TRUE(expression::isSubsetOf(a6.get(), gte5.get())); ASSERT_FALSE(expression::isSubsetOf(a4.get(), gt5.get())); ASSERT_FALSE(expression::isSubsetOf(a5.get(), gt5.get())); ASSERT_TRUE(expression::isSubsetOf(a6.get(), gt5.get())); // An unbounded range query does not match a subset of documents of a point query. ASSERT_FALSE(expression::isSubsetOf(lt5.get(), a5.get())); ASSERT_FALSE(expression::isSubsetOf(lte5.get(), a5.get())); ASSERT_FALSE(expression::isSubsetOf(gte5.get(), a5.get())); ASSERT_FALSE(expression::isSubsetOf(gt5.get(), a5.get())); // Cannot be a subset if comparing different field names. ASSERT_FALSE(expression::isSubsetOf(b5.get(), lt5.get())); ASSERT_FALSE(expression::isSubsetOf(b5.get(), lte5.get())); ASSERT_FALSE(expression::isSubsetOf(b5.get(), gte5.get())); ASSERT_FALSE(expression::isSubsetOf(b5.get(), gt5.get())); }
void testAddress() { smpl::Address a1("user|"); assert(a1.user == "user"); assert(a1.id == ""); assert(a1.valid()); smpl::Address a2("user"); assert(a2.user == "user"); assert(a2.id == ""); assert(a2.valid()); smpl::Address a3(""); assert(a3.user == ""); assert(a3.id == ""); assert(!a3.valid()); smpl::Address a4("|567257247245275"); assert(a4.user == ""); assert(a4.id == "567257247245275"); assert(a4.valid()); }
void LocalPointerTest::TestLocalArrayMoveSwap() { UnicodeString *p1 = new UnicodeString[2]; UnicodeString *p2 = new UnicodeString[3]; LocalArray<UnicodeString> a1(p1); LocalArray<UnicodeString> a2(p2); a1.swap(a2); if(a1.getAlias() != p2 || a2.getAlias() != p1) { errln("LocalArray.swap() did not swap"); } swap(a1, a2); if(a1.getAlias() != p1 || a2.getAlias() != p2) { errln("swap(LocalArray) did not swap back"); } LocalArray<UnicodeString> a3; a3.moveFrom(a1); if(a3.getAlias() != p1 || a1.isValid()) { errln("LocalArray.moveFrom() did not move"); } #if U_HAVE_RVALUE_REFERENCES infoln("TestLocalArrayMoveSwap() with rvalue references"); a1 = static_cast<LocalArray<UnicodeString> &&>(a3); if(a1.getAlias() != p1 || a3.isValid()) { errln("LocalArray move assignment operator did not move"); } LocalArray<UnicodeString> a4(static_cast<LocalArray<UnicodeString> &&>(a2)); if(a4.getAlias() != p2 || a2.isValid()) { errln("LocalArray move constructor did not move"); } #else infoln("TestLocalArrayMoveSwap() without rvalue references"); #endif // Move self assignment leaves the object valid but in an undefined state. // Do it to make sure there is no crash, // but do not check for any particular resulting value. a1.moveFrom(a1); a3.moveFrom(a3); }
void level_one() { vector<DPipe> DPIPES(5); vector<DoublePipe> DOUBPIPES(8); vector<CrossPipe> CROSSPIPES(1); DPipe a0(70,600,100,40); DPipe a1(170,600,100,40); DoublePipe b0(270,600,70,40); DoublePipe b1(270,500,70,40); DoublePipe b2(170,500,70,40); DoublePipe b3(170,400,70,40); DPipe a2(270,400,100,40); CrossPipe c0(370,400,100,40); DoublePipe b4(470,400,70,40); DoublePipe b5(470,300,70,40); DoublePipe b6(370,300,70,40); DoublePipe b7(370,500,70,40); DPipe a3(470,500,100,40); DPipe a4(570,500,100,40); DPIPES[0]=a0; DPIPES[1]=a1; DPIPES[2]=a2; DPIPES[3]=a3; DPIPES[4]=a4; DOUBPIPES[0]=b0; DOUBPIPES[1]=b1; DOUBPIPES[2]=b2; DOUBPIPES[3]=b3; DOUBPIPES[4]=b4; DOUBPIPES[5]=b5; DOUBPIPES[6]=b6; DOUBPIPES[7]=b7; CROSSPIPES[0]=c0; }
void testAddress() { smpl::Address a("user@group/567257247245275"); assert(a.user == "user"); assert(a.group == "group"); assert(a.id == "567257247245275"); assert(a.valid()); smpl::Address a1("user@group"); assert(a1.user == "user"); assert(a1.group == "group"); assert(a1.id == ""); assert(a1.valid()); smpl::Address a2("group"); assert(a2.user == ""); assert(a2.group == "group"); assert(a2.id == ""); assert(a2.valid()); smpl::Address a3(""); assert(a3.user == ""); assert(a3.group == ""); assert(a3.id == ""); assert(!a3.valid()); smpl::Address a4("/567257247245275"); assert(a4.user == ""); assert(a4.group == ""); assert(a4.id == "567257247245275"); assert(a4.valid()); smpl::Address a5("group/567257247245275"); assert(a5.user == ""); assert(a5.group == "group"); assert(a5.id == "567257247245275"); assert(a5.valid()); }
void integration_rk4(listv2d& r, listv2d& v, listv2d& a, const listdouble& m, const double h, double ti) { listv2d r1(ITEMS); listv2d r2(ITEMS); listv2d r3(ITEMS); listv2d r4(ITEMS); listv2d v2(ITEMS); listv2d v3(ITEMS); listv2d v4(ITEMS); listv2d a2(ITEMS); listv2d a3(ITEMS); listv2d a4(ITEMS); for (int i = 0; i < ITEMS; i++) { r2[i] = r[i] + 0.5 * h * v[i]; v2[i] = v[i] + 0.5 * h * a[i]; } calc_accel_multiple(r2, a2, m); for (int i = 0; i < ITEMS; i++) { r3[i] = r[i] + 0.5 * h * v2[i]; v3[i] = v[i] + 0.5 * h * a2[i]; } calc_accel_multiple(r3, a3, m); for (int i = 0; i < ITEMS; i++) { r4[i] = r[i] + h * v3[i]; v4[i] = v[i] + h * a3[i]; } calc_accel_multiple(r4, a4, m); for (int i = 0; i < ITEMS; i++) { r[i] = r[i] + h/6.0 * (v[i] + 2.0 * v2[i] + 2.0 * v3[i] + v4[i]); v[i] = v[i] + h/6.0 * (a[i] + 2.0 * a2[i] + 2.0 * a3[i] + a4[i]); } }
int main() { Animal a1("Monkey", 3); Animal a2("Bear" , 8); Animal a3("Turtle", 56); Animal a4("Monkey", 200); std::set<Animal> s; s.insert(a1); s.insert(a2); s.insert(a3); s.insert(a4); std::cout << "Number of animals: " << s.size() << std::endl; std::for_each(s.begin(), s.end(), boost::bind(&Animal::print, _1)); std::cout << std::endl; std::set<Animal>::iterator it(s.find(Animal("Monkey", 200))); if (it != s.end()) { std::cout << "We found the 200 year old monkey!" << std::endl; it->print(); } // Animal("Monkey", 3) as a match it = std::find(s.begin(), s.end(), Animal("Monkey", 200)); if (it == s.end()) { std::cout << "No 200 year old monkey could be find in this set." << std::endl; } }
osgToy::RhombicDodecahedron::RhombicDodecahedron() { setOverallColor( osg::Vec4(0,1,0,1) ); osg::Vec3 a0( 1, 1, 1 ); osg::Vec3 a1( 1, 1, -1 ); osg::Vec3 a2( 1, -1, 1 ); osg::Vec3 a3( 1, -1, -1 ); osg::Vec3 a4( -1, 1, 1 ); osg::Vec3 a5( -1, 1, -1 ); osg::Vec3 a6( -1, -1, 1 ); osg::Vec3 a7( -1, -1, -1 ); osg::Vec3 xp( 2, 0, 0 ); osg::Vec3 xn( -2, 0, 0 ); osg::Vec3 yp( 0, 2, 0 ); osg::Vec3 yn( 0, -2, 0 ); osg::Vec3 zp( 0, 0, 2 ); osg::Vec3 zn( 0, 0, -2 ); addTristrip( yp, a0, a1, xp ); addTristrip( xp, a2, a3, yn ); addTristrip( yn, a6, a7, xn ); addTristrip( xn, a4, a5, yp ); addTristrip( zp, a0, a4, yp ); addTristrip( yp, a1, a5, zn ); addTristrip( zn, a3, a7, yn ); addTristrip( yn, a2, a6, zp ); addTristrip( xp, a0, a2, zp ); addTristrip( zp, a4, a6, xn ); addTristrip( xn, a5, a7, zn ); addTristrip( zn, a1, a3, xp ); osgToy::FacetingVisitor::facet( *this ); }
int main() { // Några saker som ska fungera: UIntVector a(10); // initiering med 7 element std::cout << "a(10)"<< a.length << std::endl; std::cout << "kopiering" << std::endl; UIntVector b(a); // kopieringskonstruktor std::cout << "kopiering" << std::endl; a = a; std::cout << "s**t" << std::endl; UIntVector c = a; // kopieringskonstruktor //Extra tester för alla Requirments a = b; // tilldelning genom kopiering a[5] = 7; // tilldelning till element const UIntVector e(100000); // konstant objekt med 10 element int i = e[5]; // const int oper[](int) const körs i = a[0]; // vektorn är nollindexerad i = a[5]; // int oper[](int) körs a[5]++; // öka värdet till 8 //Extra tester för alla Requirments std::cout << "(1)TEST" << std::endl; int aa = e[9]; int ab = e[0]; std::cout << "(1)S**T" << aa << ab << std::endl; std::cout << "(2)TEST" << std::endl; for(long int i = 0; i < 100000; i++) { e[i]; } std::cout << "(2)S**T" << std::endl; std::cout << "(3)TEST" << std::endl; UIntVector a3(10); UIntVector b3(0); UIntVector c3(0); b3 = a3; a3 = c3; std::cout << "(3)S**T" << std::endl; std::cout << "(4) START" << std::endl; std::initializer_list<unsigned int> list = {1,2,3}; UIntVector a4(list); UIntVector b4(0); a4 = b4; std::cout << "length a" << a4.size() << "len b " << b4.size() << std::endl; std::cout << "(4) S**T" << std::endl; std::cout << "(5)TEST" << std::endl; UIntVector b5(list); UIntVector a5(std::move(b5)); std::cout << "(5)S**T" << std::endl; std::cout << "(6)TEST" << std::endl; UIntVector a6(30); UIntVector b6(a6); std::cout << "(6)S**T" << std::endl; std::cout << "(7)TEST" << std::endl; UIntVector a7(1); std::cout << "a) len innan " <<a7.length << std::endl; UIntVector b7(std::move(a7)); std::cout << "b) len " <<b7.length << std::endl; std::cout << "a) len " <<a7.length << std::endl; std::cout << "(7)S**T" << std::endl; std::cout << "(8)TEST" << std::endl; UIntVector a8(10); a8.reset(); UIntVector b8(11); std::cout << "a) INNAN len " <<a8.size() << "ptr " << a8.vector_ptr <<std::endl; UIntVector c8(std::move(a8)); std::cout << "c) len " <<c8.size() << "ptr" << c8.vector_ptr <<std::endl; std::cout << "a) len " <<a8.size() << "ptr " << a8.vector_ptr <<std::endl; std::cout << "(8)S**T" << std::endl; std::cout << "(9)TEST COPY TO SELF" << std::endl; b8 = b8; std::cout << "(9)S**T" << std::endl; try { i = e[10]; // försöker hämta element som ligger utanför e } catch (std::out_of_range e) { std::cout << e.what() << std::endl; } #if 0 // Diverse saker att testa e[5] = 3; // fel: (kompilerar ej) tilldelning till const b = b; // hmm: se till att inte minnet som skall behållas frigörs #endif return 0; }
int main(int argc,char **argv) { setlocale(LC_ALL,"RUSSIAN"); SDL_DisplayMode displayMode; if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { cout << "SDL_Init Error: " << SDL_GetError() << endl; return 1; } int request = SDL_GetDesktopDisplayMode(0,&displayMode); SDL_Window *win = SDL_CreateWindow("Trubi", 300, 300,800, 800, SDL_WINDOW_SHOWN); if (win == nullptr) { cout << "SDL_CreateWindow Error: " << SDL_GetError() << endl; return 1; } SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (ren == nullptr) { cout << "SDL_CreateRenderer Error: " << SDL_GetError() << endl; return 1; } vector<DPipe> DPIPES(13); vector<DoublePipe> DOUBPIPES(6); DPipe background(400,400,800,800); DPipe a0(70,300,100,40); DPipe a1(170,300,100,40); DPipe a2(270,300,100,40); DPipe a3(370,400,100,40); DPipe a4(370,500,100,40); DPipe a5(470,600,100,40); DPipe a6(570,600,100,40); DPipe a7(670,500,100,40); DPipe a8(670,400,100,40); DPipe a9(370,200,100,40); DPipe a10(470,100,100,40); DPipe a11(570,100,100,40); DPipe a12(670,200,100,40); DPipe kletka(370,300,100,100); DoublePipe b0(370,300,70,40); DoublePipe b1(370,600,70,40); DoublePipe b2(670,600,70,40); DoublePipe b3(670,300,70,40); DoublePipe b4(370,100,70,40); DoublePipe b5(670,100,70,40); DPIPES[0]=a0; DPIPES[1]=a1; DPIPES[2]=a2; DPIPES[3]=a3; DPIPES[4]=a4; DPIPES[5]=a5; DPIPES[6]=a6; DPIPES[7]=a7; DPIPES[8]=a8; DPIPES[9]=a9; DPIPES[10]=a10; DPIPES[11]=a11; DPIPES[12]=a12; DOUBPIPES[0]=b0; DOUBPIPES[1]=b1; DOUBPIPES[2]=b2; DOUBPIPES[3]=b3; DOUBPIPES[4]=b4; DOUBPIPES[5]=b5; SDL_RenderClear(ren); background.default_create(ren,"newbackground.bmp"); for(int i=0;i<DPIPES.size();++i) { DPIPES[i].default_create(ren,"text1.bmp"); } for(int i=0;i<DOUBPIPES.size();++i) { DOUBPIPES[i].default_create1(ren,"double1.bmp","double2.bmp"); } SDL_RenderPresent(ren); bool quit=false; while(!quit) { while(SDL_PollEvent(&event)) { SDL_PumpEvents(); if(event.type == SDL_QUIT) quit=true; else if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button==SDL_BUTTON_LEFT) { for(int i=0;i<DPIPES.size();++i) { if(DPIPES[i].ismouse()) { SDL_RenderClear(ren); background.default_create(ren,"newbackground.bmp"); nochangesDoub(ren,DOUBPIPES); somechanges(ren,DPIPES,i); } } for(int i=0;i<DOUBPIPES.size();++i) { if(DOUBPIPES[i].ismouse()) { SDL_RenderClear(ren); background.default_create(ren,"newbackground.bmp"); nochanges(ren,DPIPES); somechangesDoub(ren,DOUBPIPES,i); } } } } } return 1; }
void test() { // This function tests C++0x 5.16 // p1 (contextually convert to bool) int i1 = ToBool() ? 0 : 1; // p2 (one or both void, and throwing) i1 ? throw 0 : throw 1; i1 ? test() : throw 1; i1 ? throw 0 : test(); i1 ? test() : test(); i1 = i1 ? throw 0 : 0; i1 = i1 ? 0 : throw 0; i1 ? 0 : test(); // expected-error {{right operand to ? is void, but left operand is of type 'int'}} i1 ? test() : 0; // expected-error {{left operand to ? is void, but right operand is of type 'int'}} (i1 ? throw 0 : i1) = 0; // expected-error {{expression is not assignable}} (i1 ? i1 : throw 0) = 0; // expected-error {{expression is not assignable}} // p3 (one or both class type, convert to each other) // b1 (lvalues) Base base; Derived derived; Convertible conv; Base &bar1 = i1 ? base : derived; Base &bar2 = i1 ? derived : base; Base &bar3 = i1 ? base : conv; Base &bar4 = i1 ? conv : base; // these are ambiguous BadBase bb; BadDerived bd; (void)(i1 ? bb : bd); // expected-error {{conditional expression is ambiguous; 'BadBase' can be converted to 'BadDerived' and vice versa}} (void)(i1 ? bd : bb); // expected-error {{conditional expression is ambiguous}} // curiously enough (and a defect?), these are not // for rvalues, hierarchy takes precedence over other conversions (void)(i1 ? BadBase() : BadDerived()); (void)(i1 ? BadDerived() : BadBase()); // b2.1 (hierarchy stuff) extern const Base constret(); extern const Derived constder(); // should use const overload A a1((i1 ? constret() : Base()).trick()); A a2((i1 ? Base() : constret()).trick()); A a3((i1 ? constret() : Derived()).trick()); A a4((i1 ? Derived() : constret()).trick()); // should use non-const overload i1 = (i1 ? Base() : Base()).trick(); i1 = (i1 ? Base() : Base()).trick(); i1 = (i1 ? Base() : Derived()).trick(); i1 = (i1 ? Derived() : Base()).trick(); // should fail: const lost (void)(i1 ? Base() : constder()); // expected-error {{incompatible operand types ('Base' and 'const Derived')}} (void)(i1 ? constder() : Base()); // expected-error {{incompatible operand types ('const Derived' and 'Base')}} Priv priv; Fin fin; (void)(i1 ? Base() : Priv()); // expected-error{{private base class}} (void)(i1 ? Priv() : Base()); // expected-error{{private base class}} (void)(i1 ? Base() : Fin()); // expected-error{{ambiguous conversion from derived class 'Fin' to base class 'Base':}} (void)(i1 ? Fin() : Base()); // expected-error{{ambiguous conversion from derived class 'Fin' to base class 'Base':}} (void)(i1 ? base : priv); // expected-error {{private base class}} (void)(i1 ? priv : base); // expected-error {{private base class}} (void)(i1 ? base : fin); // expected-error {{ambiguous conversion from derived class 'Fin' to base class 'Base':}} (void)(i1 ? fin : base); // expected-error {{ambiguous conversion from derived class 'Fin' to base class 'Base':}} // b2.2 (non-hierarchy) i1 = i1 ? I() : i1; i1 = i1 ? i1 : I(); I i2(i1 ? I() : J()); I i3(i1 ? J() : I()); // "the type [it] woud have if E2 were converted to an rvalue" vfn pfn = i1 ? F() : test; pfn = i1 ? test : F(); (void)(i1 ? A() : B()); // expected-error {{conversion from 'B' to 'A' is ambiguous}} (void)(i1 ? B() : A()); // expected-error {{conversion from 'B' to 'A' is ambiguous}} (void)(i1 ? 1 : Ambig()); // expected-error {{conversion from 'Ambig' to 'int' is ambiguous}} (void)(i1 ? Ambig() : 1); // expected-error {{conversion from 'Ambig' to 'int' is ambiguous}} // By the way, this isn't an lvalue: &(i1 ? i1 : i2); // expected-error {{address expression must be an lvalue or a function designator}} // p4 (lvalue, same type) Fields flds; int &ir1 = i1 ? flds.i1 : flds.i2; (i1 ? flds.b1 : flds.i2) = 0; (i1 ? flds.i1 : flds.b2) = 0; (i1 ? flds.b1 : flds.b2) = 0; // p5 (conversion to built-in types) // GCC 4.3 fails these double d1 = i1 ? I() : K(); pfn = i1 ? F() : G(); DFnPtr pfm; pfm = i1 ? DFnPtr() : &Base::fn1; pfm = i1 ? &Base::fn1 : DFnPtr(); // p6 (final conversions) i1 = i1 ? i1 : ir1; int *pi1 = i1 ? &i1 : 0; pi1 = i1 ? 0 : &i1; i1 = i1 ? i1 : EVal; i1 = i1 ? EVal : i1; d1 = i1 ? 'c' : 4.0; d1 = i1 ? 4.0 : 'c'; Base *pb = i1 ? (Base*)0 : (Derived*)0; pb = i1 ? (Derived*)0 : (Base*)0; pfm = i1 ? &Base::fn1 : &Derived::fn2; pfm = i1 ? &Derived::fn2 : &Base::fn1; pfm = i1 ? &Derived::fn2 : 0; pfm = i1 ? 0 : &Derived::fn2; const int (MixedFieldsDerived::*mp1) = i1 ? &MixedFields::ci : &MixedFieldsDerived::i; const volatile int (MixedFields::*mp2) = i1 ? &MixedFields::ci : &MixedFields::cvi; (void)(i1 ? &MixedFields::ci : &MixedFields::vi); // Conversion of primitives does not result in an lvalue. &(i1 ? i1 : d1); // expected-error {{address expression must be an lvalue or a function designator}} (void)&(i1 ? flds.b1 : flds.i1); // expected-error {{address of bit-field requested}} (void)&(i1 ? flds.i1 : flds.b1); // expected-error {{address of bit-field requested}} unsigned long test0 = 5; test0 = test0 ? (long) test0 : test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}} test0 = test0 ? (int) test0 : test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? (short) test0 : test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}} test0 = test0 ? test0 : (long) test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}} test0 = test0 ? test0 : (int) test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? test0 : (short) test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}} test0 = test0 ? test0 : (long) 10; test0 = test0 ? test0 : (int) 10; test0 = test0 ? test0 : (short) 10; test0 = test0 ? (long) 10 : test0; test0 = test0 ? (int) 10 : test0; test0 = test0 ? (short) 10 : test0; int test1; test0 = test0 ? EVal : test0; test1 = test0 ? EVal : (int) test0; test0 = test0 ? EVal : test1; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? test1 : EVal; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test1 = test0 ? EVal : (int) test0; test1 = test0 ? (int) test0 : EVal; // Note the thing that this does not test: since DR446, various situations // *must* create a separate temporary copy of class objects. This can only // be properly tested at runtime, though. }
/// add axioms corresponding to the String.compareTo java function /// \par parameters: function application with two string arguments /// \return a integer expression exprt string_constraint_generatort::add_axioms_for_compare_to( const function_application_exprt &f) { string_exprt s1=add_axioms_for_string_expr(args(f, 2)[0]); string_exprt s2=add_axioms_for_string_expr(args(f, 2)[1]); const typet &return_type=f.type(); symbol_exprt res=fresh_symbol("compare_to", return_type); typet index_type=s1.length().type(); // In the lexicographic comparison, x is the first point where the two // strings differ. // We add axioms: // a1 : res==0 => |s1|=|s2| // a2 : forall i<|s1|. s1[i]==s2[i] // a3 : exists x. // res!=0 ==> x> 0 && // ((|s1| <= |s2| &&x<|s1|) || (|s1| >= |s2| &&x<|s2|) // &&res=s1[x]-s2[x] ) // || cond2: // (|s1|<|s2| &&x=|s1|) || (|s1| > |s2| &&x=|s2|) &&res=|s1|-|s2|) // a4 : forall i<x. res!=0 => s1[i]=s2[i] assert(return_type.id()==ID_signedbv); equal_exprt res_null=equal_exprt(res, from_integer(0, return_type)); implies_exprt a1(res_null, s1.axiom_for_has_same_length_as(s2)); axioms.push_back(a1); symbol_exprt i=fresh_univ_index("QA_compare_to", index_type); string_constraintt a2(i, s1.length(), res_null, equal_exprt(s1[i], s2[i])); axioms.push_back(a2); symbol_exprt x=fresh_exist_index("index_compare_to", index_type); equal_exprt ret_char_diff( res, minus_exprt( typecast_exprt(s1[x], return_type), typecast_exprt(s2[x], return_type))); equal_exprt ret_length_diff( res, minus_exprt( typecast_exprt(s1.length(), return_type), typecast_exprt(s2.length(), return_type))); or_exprt guard1( and_exprt(s1.axiom_for_is_shorter_than(s2), s1.axiom_for_is_strictly_longer_than(x)), and_exprt(s1.axiom_for_is_longer_than(s2), s2.axiom_for_is_strictly_longer_than(x))); and_exprt cond1(ret_char_diff, guard1); or_exprt guard2( and_exprt(s2.axiom_for_is_strictly_longer_than(s1), s1.axiom_for_has_length(x)), and_exprt(s1.axiom_for_is_strictly_longer_than(s2), s2.axiom_for_has_length(x))); and_exprt cond2(ret_length_diff, guard2); implies_exprt a3( not_exprt(res_null), and_exprt( binary_relation_exprt(x, ID_ge, from_integer(0, return_type)), or_exprt(cond1, cond2))); axioms.push_back(a3); string_constraintt a4(i, x, not_exprt(res_null), equal_exprt(s1[i], s2[i])); axioms.push_back(a4); return res; }