Example #1
0
TEST( AllElemMatchOp, Matches ) {
    BSONObj baseOperandgt1 = BSON( "$gt" << 1 );
    auto_ptr<ComparisonMatchExpression> gt1( new ComparisonMatchExpression() );
    ASSERT( gt1->init( "", ComparisonMatchExpression::GT, baseOperandgt1[ "$gt" ] ).isOK() );

    BSONObj baseOperandlt1 = BSON( "$lt" << 10 );
    auto_ptr<ComparisonMatchExpression> lt1( new ComparisonMatchExpression() );
    ASSERT( lt1->init( "", ComparisonMatchExpression::LT, baseOperandlt1[ "$lt" ] ).isOK() );

    auto_ptr<ElemMatchValueMatchExpression> elemMatch1( new ElemMatchValueMatchExpression() );
    elemMatch1->init( "x" );
    elemMatch1->add( gt1.release() );
    elemMatch1->add( lt1.release() );

    BSONObj baseOperandgt2 = BSON( "$gt" << 101 );
    auto_ptr<ComparisonMatchExpression> gt2( new ComparisonMatchExpression() );
    ASSERT( gt2->init( "", ComparisonMatchExpression::GT, baseOperandgt2[ "$gt" ] ).isOK() );

    BSONObj baseOperandlt2 = BSON( "$lt" << 110 );
    auto_ptr<ComparisonMatchExpression> lt2( new ComparisonMatchExpression() );
    ASSERT( lt2->init( "", ComparisonMatchExpression::LT, baseOperandlt2[ "$lt" ] ).isOK() );

    auto_ptr<ElemMatchValueMatchExpression> elemMatch2( new ElemMatchValueMatchExpression() );
    elemMatch2->init( "x" );
    elemMatch2->add( gt2.release() );
    elemMatch2->add( lt2.release() );

    AllElemMatchOp op;
    op.init( "x" );
    op.add( elemMatch1.release() );
    op.add( elemMatch2.release() );


    BSONObj nonArray = BSON( "x" << 4 );
    ASSERT( !op.matches( nonArray, NULL ) );
    BSONObj emptyArray = BSON( "x" << BSONArray() );
    ASSERT( !op.matches( emptyArray, NULL ) );
    BSONObj nonNumberArray = BSON( "x" << BSON_ARRAY( "q" ) );
    ASSERT( !op.matches( nonNumberArray, NULL ) );
    BSONObj singleMatch = BSON( "x" << BSON_ARRAY( 5 ) );
    ASSERT( !op.matches( singleMatch, NULL ) );
    BSONObj otherMatch = BSON( "x" << BSON_ARRAY( 105 ) );
    ASSERT( !op.matches( otherMatch, NULL ) );
    BSONObj bothMatch = BSON( "x" << BSON_ARRAY( 5 << 105 ) );
    ASSERT( op.matches( bothMatch, NULL ) );
    BSONObj neitherMatch = BSON( "x" << BSON_ARRAY( 0 << 200 ) );
    ASSERT( !op.matches( neitherMatch, NULL ) );
}
Example #2
0
/*! \brief Determine the RF distance of two trees
 * \todo UNTESTED!!!!!
 */
int RF_dist(string gt_string1,string gt_string2){
	int RF_dist_return=0;
	Net gt1(gt_string1);
	Net gt2(gt_string2);
	valarray <int> gt1_in_gt2(gt1.descndnt.size(),0);
	valarray <int> gt2_in_gt1(gt2.descndnt.size(),0);
	for (size_t node1_i=0;node1_i<gt1.descndnt2.size();node1_i++){
		for (size_t node2_i=0;node2_i<gt2.descndnt2.size();node2_i++){
			valarray <bool> comp=(gt1.descndnt2[node1_i]==gt2.descndnt2[node2_i]);
			if (comp.min()==1){
				//cout<<gt1.Net_nodes[node1_i].node_content<<endl;
				//cout<<gt2.Net_nodes[node2_i].node_content<<endl;
				gt1_in_gt2[node1_i]=1;
				gt2_in_gt1[node2_i]=1;
				//break;
			}
		}
	}
	RF_dist_return=gt1_in_gt2.size()-gt1_in_gt2.sum()+gt2_in_gt1.size()-gt2_in_gt1.sum();
	return RF_dist_return;
}