TupleGenerator implements ITestCaseGenerator { public FunctionTestDef getTests( FunctionInputDef inputDef, FunctionTestDef baseTests) { try { logger_.info( "{}: Preparing constraint info", inputDef); createPropertyProviders( inputDef); logger_.info( "{}: Generating test cases", inputDef); List<TestCaseDef> baseCases = getBaseCases( inputDef, baseTests); RandSeq randSeq = getRandomSeed()==null? null : new RandSeq( getRandomSeed()); VarTupleSet validTuples = getValidTupleSet( randSeq, inputDef); List<TestCaseDef> validCases = getBaseValidCases( inputDef, validTuples, baseCases); validCases.addAll( getValidCases( inputDef, validTuples)); VarTupleSet failureTuples = getFailureTupleSet( randSeq, inputDef); List<TestCaseDef> failureCases = getBaseFailureCases( inputDef, validTuples, failureTuples, baseCases); failureCases.addAll( getFailureCases( inputDef, failureTuples, validTuples)); FunctionTestDef testDef = new FunctionTestDef( inputDef.getName()); List<TestCaseDef> testCaseDefs = new ArrayList<TestCaseDef>(); testCaseDefs.addAll( validCases); testCaseDefs.addAll( failureCases); Collections.sort( testCaseDefs); int nextId = -1; for( TestCaseDef testCase : testCaseDefs) { Integer id = testCase.getId(); nextId = id==null? nextId + 1 : id.intValue(); testDef.addTestCase( testCase.createTestCase( nextId)); } logger_.info( "{}: Completed {} test cases", inputDef, testCaseDefs.size()); return testDef; } catch( Exception e) { logger_.error( String.valueOf( inputDef) + ": Can't create test cases", e); throw new RuntimeException( String.valueOf( inputDef) + ": Can't create test cases", e); } } TupleGenerator();  TupleGenerator( int tupleSize); void setDefaultTupleSize( int tupleSize); int getDefaultTupleSize(); void setCombiners( List<TupleCombiner> combiners); List<TupleCombiner> getCombiners(); void addCombiner( TupleCombiner combiner); void setRandomSeed( Long seed); Long getRandomSeed(); FunctionTestDef getTests( FunctionInputDef inputDef, FunctionTestDef baseTests); String toString(); ITestCaseGenerator cloneOf(); boolean equals( Object object); int hashCode();  }
@Test public void getTests_Basic() { SystemInputDef systemInputDef = getSystemInputDefBasic(); FunctionInputDef functionInputDef = systemInputDef.getFunctionInputDef( "Make"); TupleGenerator generator = new TupleGenerator(); FunctionTestDef functionTestDef = generator.getTests( functionInputDef, null); assertTestCasesComplete( functionInputDef, functionTestDef); TupleCombiner combiner = new TupleCombiner(); Collection<Tuple> tuplesExpected = combiner.getTuples( functionInputDef); assertThat ( "Tuples included", getTuplesIncluded( tuplesExpected, functionTestDef), containsMembers( tuplesExpected)); }
@Test public void getTests_Constrained() { SystemInputDef systemInputDef = getSystemInputDefConstrained(); FunctionInputDef functionInputDef = systemInputDef.getFunctionInputDef( "Make"); TupleGenerator generator = new TupleGenerator(); FunctionTestDef functionTestDef = generator.getTests( functionInputDef, null); assertTestCasesComplete( functionInputDef, functionTestDef); TupleCombiner combiner = new TupleCombiner(); Collection<Tuple> tuplesExpected = combiner.getTuples( functionInputDef); assertThat ( "Tuples included", getTuplesIncluded( tuplesExpected, functionTestDef), containsMembers( tuplesExpected)); assertIncluded( functionTestDef, 0, tuplesFor( functionInputDef, "Shape", "Square", "Color")); assertIncluded( functionTestDef, 0, tuplesFor( functionInputDef, "Size", "Medium", "Color")); assertIncluded( functionTestDef, 0, tuplesFor( functionInputDef, "Size", "Large", "Color")); assertIncluded( functionTestDef, 0, tupleFor( functionInputDef).bind( "Color.Lightness", "Dark").bind( "Shape", "Circle").build()); assertIncluded( functionTestDef, 0, tupleFor( functionInputDef).bind( "Color.Lightness", "Bright").bind( "Shape", "Heart").build()); assertIncluded( functionTestDef, 0, tupleFor( functionInputDef).bind( "Size", "Medium").bind( "Shape", "Circle").build()); assertIncluded( functionTestDef, 0, tupleFor( functionInputDef).bind( "Size", "Medium").bind( "Shape", "Heart").build()); assertIncluded( functionTestDef, 0, tupleFor( functionInputDef).bind( "Size", "Large").bind( "Shape", "Square").build()); }
@Test public void getTests_Failures() { SystemInputDef systemInputDef = getSystemInputDefFailures(); FunctionInputDef functionInputDef = systemInputDef.getFunctionInputDef( "Make"); TupleGenerator generator = new TupleGenerator(); FunctionTestDef functionTestDef = generator.getTests( functionInputDef, null); assertTestCasesComplete( functionInputDef, functionTestDef); TupleCombiner combiner = new TupleCombiner(); Collection<Tuple> tuplesExpected = combiner.getTuples( functionInputDef); assertThat ( "Tuples included", getTuplesIncluded( tuplesExpected, functionTestDef), containsMembers( tuplesExpected)); assertIncluded( functionTestDef, 1, "Color.Lightness", "Transparent", false); assertIncluded( functionTestDef, 1, "Color.Saturation", "Undefined", false); assertIncluded( functionTestDef, 1, "Size", "Ginormous", false); }