TEST( ElemMatchObjectMatchExpression, MatchesElementMultiple ) { BSONObj baseOperand1 = BSON( "b" << 5 ); BSONObj baseOperand2 = BSON( "b" << 6 ); BSONObj baseOperand3 = BSON( "c" << 7 ); BSONObj notMatch1 = BSON( "a" << BSON_ARRAY( BSON( "b" << 5 << "c" << 7 ) ) ); BSONObj notMatch2 = BSON( "a" << BSON_ARRAY( BSON( "b" << 6 << "c" << 7 ) ) ); BSONObj notMatch3 = BSON( "a" << BSON_ARRAY( BSON( "b" << BSON_ARRAY( 5 << 6 ) ) ) ); BSONObj match = BSON( "a" << BSON_ARRAY( BSON( "b" << BSON_ARRAY( 5 << 6 ) << "c" << 7 ) ) ); auto_ptr<ComparisonMatchExpression> eq1( new ComparisonMatchExpression() ); ASSERT( eq1->init( "b", ComparisonMatchExpression::EQ, baseOperand1[ "b" ] ).isOK() ); auto_ptr<ComparisonMatchExpression> eq2( new ComparisonMatchExpression() ); ASSERT( eq2->init( "b", ComparisonMatchExpression::EQ, baseOperand2[ "b" ] ).isOK() ); auto_ptr<ComparisonMatchExpression> eq3( new ComparisonMatchExpression() ); ASSERT( eq3->init( "c", ComparisonMatchExpression::EQ, baseOperand3[ "c" ] ).isOK() ); auto_ptr<AndMatchExpression> andOp( new AndMatchExpression() ); andOp->add( eq1.release() ); andOp->add( eq2.release() ); andOp->add( eq3.release() ); ElemMatchObjectMatchExpression op; ASSERT( op.init( "a", andOp.release() ).isOK() ); ASSERT( !op.matchesSingleElement( notMatch1[ "a" ] ) ); ASSERT( !op.matchesSingleElement( notMatch2[ "a" ] ) ); ASSERT( !op.matchesSingleElement( notMatch3[ "a" ] ) ); ASSERT( op.matchesSingleElement( match[ "a" ] ) ); }
int main(int argc, char *argv[]) { Pooma::initialize(argc, argv); Pooma::Tester tester(argc, argv); Interval<1> n1(1,5); Interval<1> n2(4,8); Interval<1> n3(10,20); Interval<2> a(n1,n2); Interval<3> b(n1,n2,n3); Range<1> r1(1,5); Range<1> r2(4,8,2); Range<1> r3(5,9,2); Range<1> r4(10,20,5); Range<2> ra(r1,r2); Range<2> rb(r1,r3); Range<3> rc(r1,r2,r3); tester.out() << "1: touches(" << a[0] << "," << a[1] << ") ? "; tester.out() << touches(a[0], a[1]) << std::endl; tester.check( touches(a[0], a[1]) ); tester.out() << "0: touches(" << a[0] << "," << b[2] << ") ? "; tester.out() << touches(a[0], b[2]) << std::endl; tester.check( touches(a[0], b[2])==0); tester.out() << "1: touches(" << a[0] << "," << ra[0] << ") ? "; tester.out() << touches(a[0], ra[0]) << std::endl; tester.check(touches(a[0], ra[0])); tester.out() << "1: touches(" << ra[0] << "," << ra[1] << ") ? "; tester.out() << touches(ra[0], ra[1]) << std::endl; tester.check( touches(ra[0], ra[1])); tester.out() << "0: touches(" << r2 << "," << r3 << ") ? "; tester.out() << touches(r2, r3) << std::endl; tester.check( touches(r2, r3)==0); tester.out() << "0: touches(" << ra << "," << rb << ") ? "; tester.out() << touches(ra, rb) << std::endl; tester.check( touches(ra, rb) ==0); tester.out() << "1: touches(" << rc << "," << rc << ") ? "; tester.out() << touches(rc, rc) << std::endl; tester.check( touches(rc, rc) ); tester.out() << "------------------------------------" << std::endl; tester.check(" touches ", true); Interval<1> c1(1,10); Interval<1> c2(3,8); Interval<1> c3(5,15); Interval<2> ca(c1, c1); Interval<2> cb(c1, c2); Range<1> cr1(2,20,2); Range<1> cr2(4,16,4); Range<1> cr3(3,15,2); Range<1> cr4(5,15,5); tester.out() << "1: contains(" << c1 << "," << c2 << ") ? "; tester.out() << contains(c1,c2) << std::endl; tester.check(contains(c1,c2)); tester.out() << "0: contains(" << c2 << "," << c1 << ") ? "; tester.out() << contains(c2,c1) << std::endl; tester.check(contains(c2,c1)==0); tester.out() << "0: contains(" << c1 << "," << c3 << ") ? "; tester.out() << contains(c1,c3) << std::endl; tester.check(contains(c1,c3)==0); tester.out() << "1: contains(" << ca << "," << cb << ") ? "; tester.out() << contains(ca,cb) << std::endl; tester.check(contains(ca,cb)); tester.out() << "0: contains(" << cb << "," << ca << ") ? "; tester.out() << contains(cb,ca) << std::endl; tester.check(contains(cb,ca)==0); tester.out() << "1: contains(" << cr1 << "," << cr2 << ") ? "; tester.out() << contains(cr1,cr2) << std::endl; tester.check( contains(cr1,cr2)); tester.out() << "0: contains(" << cr1 << "," << cr3 << ") ? "; tester.out() << contains(cr1,cr3) << std::endl; tester.check(contains(cr1,cr3)==0); tester.out() << "1: contains(" << c3 << "," << cr4 << ") ? "; tester.out() << contains(c3,cr4) << std::endl; tester.check(contains(c3,cr4)); tester.out() << "0: contains(" << cr4 << "," << c3 << ") ? "; tester.out() << contains(cr4,c3) << std::endl; tester.check(contains(cr4,c3)==0); tester.out() << "------------------------------------" << std::endl; Interval<2> s1, s2; Range<2> sr1, sr2; split(cb, s1, s2); tester.out() << "split(" << cb << ") = " << s1 << " and " << s2 << std::endl; tester.check(s1==Interval<2>(Interval<1>(1,5),Interval<1>(3,5))); tester.check(s2==Interval<2>(Interval<1>(6,10),Interval<1>(6,8))); split(rb, sr1, sr2); tester.out() << "split(" << rb << ") = " << sr1 << " and " << sr2 << std::endl; tester.check(sr1==Range<2>(Range<1>(1,2),Range<1>(5,5,2))); tester.check(sr2==Range<2>(Range<1>(3,5),Range<1>(7,9,2))); tester.out() << "------------------------------------" << std::endl; tester.out() << "intersect(" << cb << "," << ca << ") = "; tester.out() << intersect(cb,ca) << std::endl; tester.check(intersect(cb,ca)==Interval<2>(Interval<1>(1,10), Interval<1>(3,8))); tester.out() << "intersect(" << rb << "," << ra << ") = "; tester.out() << intersect(rb,ra) << std::endl; Range<1> i1(1,16,3); Range<1> i2(17,3,-2); tester.out() << "intersect(" << i1 << "," << i2 << ") = "; tester.out() << intersect(i1,i2) << std::endl; tester.check( intersect(i1,i2) == Range<1>(7,14,6)); tester.out() << "intersect(" << i2 << "," << i1 << ") = "; tester.out() << intersect(i2,i1) << std::endl; tester.check( intersect(i2,i1) == Range<1>(13,7,-6)); tester.out() << "------------------------------------" << std::endl; Interval<1> eq1(1,5); Range<1> eq2 = -2 * eq1 + 3; Range<1> eq3(-8,8,4); Range<1> eq4 = 3 * eq1; Range<1> eq5 = 2 * eq1; Range<1> eq6 = 6 * eq1 + 1; tester.out() << "For " << eq1 << " --> " << eq4 << ", then " << eq3 << " --> "; tester.out() << equivSubset(eq1,eq4,eq3) << std::endl; tester.out() << "For " << eq4 << " --> " << eq6 << ", then " << eq3 << " --> "; tester.out() << equivSubset(eq4,eq6,eq3) << std::endl; tester.out() << "For " << eq1 << " --> " << eq2 << ", then " << eq3 << " --> "; tester.out() << equivSubset(eq1,eq2,eq3) << std::endl; tester.out() << "------------------------------------" << std::endl; NewDomain3<Interval<1>, Interval<1>, int>::SliceType_t ba; // tester.out() << "Created initial slice domain ba = " << ba << std::endl; ba = NewDomain3<Interval<1>, Interval<1>, int>::combineSlice(ba,eq1,eq1,7); tester.out() << "After taking slice, ba = " << ba << std::endl; int retval = tester.results("Domain Calc"); Pooma::finalize(); return retval; }
void run_test( int my_factory_events, int factories, int handlers, int maxq ) { struct timeval tv; struct timeval tv2; gettimeofday( &tv, NULL ); fprintf(stderr,"run_test %i %i %i %i [%x %x ... ", my_factory_events, factories, handlers, maxq, (unsigned int)tv.tv_sec, (unsigned int)tv.tv_usec ); pEventFactory pmeft1 ( new MyEventFactory( my_factory_events )) ; MyEventHandler *pe = new MyEventHandler(); pe->need_hook=true; pEventHandler peh1( pe ); pEventHandler phook1( new MyHookEventHandler() ); pEventFactory pmeft2 ( new MyEventFactory( my_factory_events )) ; pe = new MyEventHandler(); pe->need_hook=false; pEventHandler peh2( pe ); pEventFactory pmeft3 ( new MyEventFactory( my_factory_events )) ; pEventHandler phook3( new MyHookEventHandler() ); pe = new MyEventHandler(); pe->need_hook=true; pEventHandler peh3( pe ); { EventQueue eq1( pmeft1, peh1, phook1, factories, handlers, maxq ); EventQueue eq2( pmeft2, peh2, factories, handlers, maxq ); EventQueue eq3( pmeft3, peh3, phook3, factories, handlers, maxq ); eq1.wait(); eq2.wait(); eq3.wait(); } gettimeofday( &tv2, NULL ); time_t secs = tv2.tv_sec - tv.tv_sec ; time_t usecs = tv2.tv_usec - tv.tv_usec ; if( usecs < 0 ) { usecs += 1000000 ; secs -= 1 ; } fprintf(stderr,"%x %x ] secs %li msecs %li \n", (unsigned int)tv2.tv_sec, (unsigned int)tv2.tv_usec, secs, usecs ); if( MyEventHandler::errors ) { PANIC("MyEventHandler::errors"); } };