TupleCombiner implements Cloneable<TupleCombiner> { public Collection<Tuple> getTuples( FunctionInputDef inputDef) { List<VarDef> combinedVars = getCombinedVars( inputDef); return getCombinedTuples( combinedVars, getTuples( combinedVars, getTupleSize())); } TupleCombiner();  TupleCombiner( int tupleSize); void setTupleSize( int tupleSize); int getTupleSize(); String[] getIncluded(); TupleCombiner addIncludedVar( String varNamePattern); TupleCombiner removeIncludedVar( String varNamePattern); TupleCombiner removeAllIncludedVars(); String[] getExcluded(); TupleCombiner addExcludedVar( String varNamePattern); TupleCombiner removeExcludedVar( String varNamePattern); TupleCombiner removeAllExcludedVars(); Iterator<TupleRef> getOnceTuples(); TupleCombiner addOnceTuple( TupleRef tupleRef); TupleCombiner removeOnceTuple( TupleRef tupleRef); TupleCombiner removeAllOnceTuples(); Collection<Tuple> getTuples( FunctionInputDef inputDef); static Collection<Tuple> getTuples( List<VarDef> varDefs, int tupleSize); List<VarDef> getCombinedVars( FunctionInputDef inputDef); boolean isEligible( IVarDef varDef); String toString(); TupleCombiner cloneOf(); boolean equals( Object object); int hashCode();  }
@Test public void getTuples_CombinesValid() { VarValueDef value11 = new VarValueDef( "value-1-1"); VarValueDef value12 = new VarValueDef( "value-1-2"); VarValueDef value13 = new VarValueDef( "value-1-3", VarValueDef.Type.FAILURE); VarDef var1 = new VarDef( "var-1").addValue( value11).addValue( value12).addValue( value13); VarValueDef value21 = new VarValueDef( "value-2-1", VarValueDef.Type.FAILURE); VarValueDef value22 = new VarValueDef( "value-2-2"); VarDef var2 = new VarDef( "var-2").addValue( value21).addValue( value22); VarValueDef value31 = new VarValueDef( "value-3-1"); VarValueDef value32 = new VarValueDef( "value-3-2"); VarDef var3 = new VarDef( "var-3").addValue( value31).addValue( value32); List<VarDef> varDefs = new ArrayList<VarDef>(); varDefs.add( var1); varDefs.add( var2); varDefs.add( var3); Collection<Tuple> tuples = TupleCombiner.getTuples( varDefs, 3); Collection<Tuple> expectedTuples = new ArrayList<Tuple>(); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value11), new VarBindingDef( var2, value22), new VarBindingDef( var3, value31))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value11), new VarBindingDef( var2, value22), new VarBindingDef( var3, value32))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value12), new VarBindingDef( var2, value22), new VarBindingDef( var3, value31))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value12), new VarBindingDef( var2, value22), new VarBindingDef( var3, value32))); assertThat( "Tuples", tuples, containsMembers( expectedTuples)); }
@Test public void getTuples_AllPairs() { VarValueDef value11 = new VarValueDef( "value-1-1"); VarValueDef value12 = new VarValueDef( "value-1-2"); VarDef var1 = new VarDef( "var-1").addValue( value11).addValue( value12); VarValueDef value21 = new VarValueDef( "value-2-1"); VarValueDef value22 = new VarValueDef( "value-2-2"); VarDef var2 = new VarDef( "var-2").addValue( value21).addValue( value22); VarValueDef value31 = new VarValueDef( "value-3-1"); VarValueDef value32 = new VarValueDef( "value-3-2"); VarDef var3 = new VarDef( "var-3").addValue( value31).addValue( value32); List<VarDef> varDefs = new ArrayList<VarDef>(); varDefs.add( var1); varDefs.add( var2); varDefs.add( var3); Collection<Tuple> tuples = TupleCombiner.getTuples( varDefs, 2); Collection<Tuple> expectedTuples = new ArrayList<Tuple>(); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value11), new VarBindingDef( var2, value21))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value11), new VarBindingDef( var2, value22))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value11), new VarBindingDef( var3, value31))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value11), new VarBindingDef( var3, value32))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value12), new VarBindingDef( var2, value21))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value12), new VarBindingDef( var2, value22))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value12), new VarBindingDef( var3, value31))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value12), new VarBindingDef( var3, value32))); expectedTuples.add ( new Tuple ( new VarBindingDef( var2, value21), new VarBindingDef( var3, value31))); expectedTuples.add ( new Tuple ( new VarBindingDef( var2, value21), new VarBindingDef( var3, value32))); expectedTuples.add ( new Tuple ( new VarBindingDef( var2, value22), new VarBindingDef( var3, value31))); expectedTuples.add ( new Tuple ( new VarBindingDef( var2, value22), new VarBindingDef( var3, value32))); assertThat( "Tuples", tuples, containsMembers( expectedTuples)); }
@Test public void getTuples_AllPairsCompatible() { VarValueDef value11 = new VarValueDef( "value-1-1").addProperties( "R1", "V1"); VarValueDef value12 = new VarValueDef( "value-1-2").addProperties( "R1", "V2"); VarDef var1 = new VarDef( "var-1").addValue( value11).addValue( value12); VarValueDef value21 = new VarValueDef( "value-2-1").addProperties( "R2", "V1"); VarValueDef value22 = new VarValueDef( "value-2-2").addProperties( "R2", "V2"); VarDef var2 = new VarDef( "var-2").addValue( value21).addValue( value22); VarValueDef value31 = new VarValueDef( "value-3-1").addProperties( "R3", "V1"); VarValueDef value32 = new VarValueDef( "value-3-2").addProperties( "R3", "V2"); VarDef var3 = new VarDef( "var-3").addValue( value31).addValue( value32); value11.setCondition( new Not( new ContainsAny( "R2"))); value22.setCondition( new AllOf( new ContainsAny( "U1"), new Not( new ContainsAll( "R3", "V1")))); value31.setCondition( new AnyOf( new Not( new ContainsAny( "R1")), new Not( new ContainsAll( "R2", "R3")))); List<VarDef> varDefs = new ArrayList<VarDef>(); varDefs.add( var1); varDefs.add( var2); varDefs.add( var3); Collection<Tuple> tuples = TupleCombiner.getTuples( varDefs, 2); Collection<Tuple> expectedTuples = new ArrayList<Tuple>(); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value11), new VarBindingDef( var3, value31))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value11), new VarBindingDef( var3, value32))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value12), new VarBindingDef( var2, value21))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value12), new VarBindingDef( var2, value22))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value12), new VarBindingDef( var3, value31))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value12), new VarBindingDef( var3, value32))); expectedTuples.add ( new Tuple ( new VarBindingDef( var2, value21), new VarBindingDef( var3, value31))); expectedTuples.add ( new Tuple ( new VarBindingDef( var2, value21), new VarBindingDef( var3, value32))); expectedTuples.add ( new Tuple ( new VarBindingDef( var2, value22), new VarBindingDef( var3, value32))); assertThat( "Tuples", tuples, containsMembers( expectedTuples)); }
@Test public void getTuples_AllPermutations() { VarValueDef value11 = new VarValueDef( "value-1-1"); VarValueDef value12 = new VarValueDef( "value-1-2"); VarDef var1 = new VarDef( "var-1").addValue( value11).addValue( value12); VarValueDef value21 = new VarValueDef( "value-2-1"); VarValueDef value22 = new VarValueDef( "value-2-2"); VarDef var2 = new VarDef( "var-2").addValue( value21).addValue( value22); VarValueDef value31 = new VarValueDef( "value-3-1"); VarValueDef value32 = new VarValueDef( "value-3-2"); VarDef var3 = new VarDef( "var-3").addValue( value31).addValue( value32); List<VarDef> varDefs = new ArrayList<VarDef>(); varDefs.add( var1); varDefs.add( var2); varDefs.add( var3); Collection<Tuple> tuples = TupleCombiner.getTuples( varDefs, 0); Collection<Tuple> expectedTuples = new ArrayList<Tuple>(); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value11), new VarBindingDef( var2, value21), new VarBindingDef( var3, value31))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value11), new VarBindingDef( var2, value21), new VarBindingDef( var3, value32))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value11), new VarBindingDef( var2, value22), new VarBindingDef( var3, value31))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value11), new VarBindingDef( var2, value22), new VarBindingDef( var3, value32))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value12), new VarBindingDef( var2, value21), new VarBindingDef( var3, value31))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value12), new VarBindingDef( var2, value21), new VarBindingDef( var3, value32))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value12), new VarBindingDef( var2, value22), new VarBindingDef( var3, value31))); expectedTuples.add ( new Tuple ( new VarBindingDef( var1, value12), new VarBindingDef( var2, value22), new VarBindingDef( var3, value32))); assertThat( "Tuples", tuples, containsMembers( expectedTuples)); }
@Test public void getTuples_MinVars() { List<VarDef> varDefs = new ArrayList<VarDef>(); varDefs.add( new VarDef( "var-1").addValue( new VarValueDef( "value-1-1"))); varDefs.add( new VarDef( "var-2").addValue( new VarValueDef( "value-2-1"))); expectFailure( IllegalArgumentException.class) .when( () -> TupleCombiner.getTuples( varDefs, 3)) .then( failure -> { assertThat( "Failure message", failure.getMessage(), is( "Can't create 3-tuples for 2 combined variables")); }); }
@Test public void getTuples_ValidValues() { List<VarDef> varDefs = new ArrayList<VarDef>(); varDefs.add( new VarDef( "var-1").addValue( new VarValueDef( "value-1-1"))); varDefs.add( new VarDef( "var-2").addValue( new VarValueDef( "value-2-1", VarValueDef.Type.FAILURE))); expectFailure( IllegalStateException.class) .when( () -> TupleCombiner.getTuples( varDefs, 2)) .then( failure -> { assertThat( "Failure message", failure.getMessage(), is( "Can't complete tuples -- no valid values defined for var=VarDef[var-2]")); }); }