@Test public void testBasicSimilarityDifferentLength() { TestCase test1 = new DefaultTestCase(); TestCase test2 = new DefaultTestCase(); PrimitiveStatement<?> aInt = new IntPrimitiveStatement(test1, 42); test1.addStatement(aInt); PrimitiveStatement<?> aInt2 = new IntPrimitiveStatement(test1, 42); test1.addStatement(aInt2); PrimitiveStatement<?> bInt = new IntPrimitiveStatement(test2, 42); test2.addStatement(bInt); double score = DiversityObserver.getNeedlemanWunschScore(test1, test2); Assert.assertTrue(score <= 0); }
public VariableReference appendIntPrimitive(int intValue) { IntPrimitiveStatement primitiveStmt = new IntPrimitiveStatement(tc, intValue); tc.addStatement(primitiveStmt); return primitiveStmt.getReturnValue(); }
private void after(IntPrimitiveStatement statement, Scope scope) { int valueOf = statement.getValue(); VariableReference varRef = statement.getReturnValue(); String varRefName = varRef.getName(); IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf, Integer.MIN_VALUE, Integer.MAX_VALUE); symb_expressions.put(varRefName, integerVariable); Integer integer_instance; try { integer_instance = (Integer) varRef.getObject(scope); } catch (CodeUnderTestException e) { throw new EvosuiteError(e); } ReferenceConstant integerRef = newIntegerReference(integer_instance, integerVariable); symb_references.put(varRefName, integerRef); }
IntPrimitiveStatement x = new IntPrimitiveStatement(tc, LOOP_3); VariableReference loop = tc.addStatement(x); VariableReference boolRef = tc.addStatement(new BooleanPrimitiveStatement(tc,true)); x.setValue(LOOP_5); execute(tc); x.setValue(LOOP_7); execute(tc); x.setValue(LOOP_5); execute(tc); x.setValue(LOOP_3); execute(tc); x.setValue(LOOP_0); execute(tc);
test1 = testNew; oldFitness = newFitness; System.out.println(""+i+":"+((IntPrimitiveStatement)test1.getTestCase().getStatement(1)).getValue()); System.out.println(" "+((IntPrimitiveStatement)test1.getTestCase().getStatement(2)).getValue()); if(newFitness == 0.0) { System.out.println("Iterations: "+i);
assert (p instanceof IntPrimitiveStatement); IntPrimitiveStatement ip = (IntPrimitiveStatement) p; ip.setValue(value.intValue());
Integer.class); List<VariableReference> constParam = new ArrayList<VariableReference>(); constParam.add(ps1.getReturnValue()); ConstructorStatement cs1 = new ConstructorStatement(test, intConstructor, constParam); callParam.add(ps1.getReturnValue());
/** {@inheritDoc} */ @Override public void increment() { increment(1); }
@SuppressWarnings("unused") private void mutateTransformedBoolean(TestCase test) { if (Randomness.nextDouble() > Properties.RANDOM_PERTURBATION) { boolean done = false; for (Statement s : test) { if (s instanceof MethodStatement) { MethodStatement ms = (MethodStatement) s; List<VariableReference> parameters = ms.getParameterReferences(); int index = parameters.indexOf(retval); if (index >= 0) { Method m = ms.getMethod().getMethod(); org.objectweb.asm.Type[] types = org.objectweb.asm.Type.getArgumentTypes(m); if (types[index].equals(org.objectweb.asm.Type.BOOLEAN_TYPE)) { logger.warn("MUTATING"); ((IntPrimitiveStatement) this).negate(); done = true; break; } } } } if (!done) randomize(); } else { randomize(); } }
test1 = testNew; oldFitness = newFitness; System.out.println(""+i+":"+((IntPrimitiveStatement)test1.getTestCase().getStatement(1)).getValue()); System.out.println(" "+((IntPrimitiveStatement)test1.getTestCase().getStatement(2)).getValue()); if(newFitness == 0.0) { System.out.println("Iterations: "+i);
/** {@inheritDoc} */ @Override public void decrement() { increment(-1); }
/** * {@inheritDoc} */ @Override public boolean mutate(TestCase test, TestFactory factory) { if (!hasMoreThanOneValue()) return false; T oldVal = value; while (value == oldVal && value != null) { if (Randomness.nextDouble() <= Properties.RANDOM_PERTURBATION) { // When using TT, then an integer may represent a boolean, // and we would lose "negation" as a mutation if (Properties.TT && getClass().equals(IntPrimitiveStatement.class)) { if (Randomness.nextDouble() <= Properties.RANDOM_PERTURBATION) { // mutateTransformedBoolean(test); ((IntPrimitiveStatement) this).negate(); } else randomize(); } else { randomize(); } } else delta(); } return true; }
@Test public void testBasicSimilarity() { TestCase test1 = new DefaultTestCase(); TestCase test2 = new DefaultTestCase(); PrimitiveStatement<?> aInt = new IntPrimitiveStatement(test1, 42); test1.addStatement(aInt); PrimitiveStatement<?> bInt = new IntPrimitiveStatement(test2, 42); test2.addStatement(bInt); double score = DiversityObserver.getNeedlemanWunschScore(test1, test2); Assert.assertTrue(score > 0); }
test1 = testNew; oldFitness = newFitness; System.out.println(""+i+":"+((IntPrimitiveStatement)test1.getTestCase().getStatement(1)).getValue()); if(newFitness == 0.0) { System.out.println("Iterations: "+i);
@Test public void testBasicSimilarityDifferentTypes() { TestCase test1 = new DefaultTestCase(); TestCase test2 = new DefaultTestCase(); PrimitiveStatement<?> aInt = new IntPrimitiveStatement(test1, 42); test1.addStatement(aInt); PrimitiveStatement<?> aInt2 = new IntPrimitiveStatement(test1, 42); test1.addStatement(aInt2); PrimitiveStatement<?> bInt = new IntPrimitiveStatement(test2, 42); test2.addStatement(bInt); Constructor<?> c = Object.class.getConstructors()[0]; ConstructorStatement cs = new ConstructorStatement(test2, new GenericConstructor(c, Object.class), new ArrayList<VariableReference>()); test2.addStatement(cs); double score = DiversityObserver.getNeedlemanWunschScore(test1, test2); Assert.assertTrue(score <= 0); }
test1 = testNew; oldFitness = newFitness; System.out.println(""+i+":"+((IntPrimitiveStatement)test1.getTestCase().getStatement(1)).getValue()); if(newFitness == 0.0) { System.out.println("Iterations: "+i);
statement = new BooleanPrimitiveStatement(tc); } else if (clazz == int.class) { statement = new IntPrimitiveStatement(tc); } else if (clazz == char.class) { statement = new CharPrimitiveStatement(tc);
test1 = testNew; oldFitness = newFitness; System.out.println(""+i+":"+((IntPrimitiveStatement)test1.getTestCase().getStatement(1)).getValue()); System.out.println(" "+((IntPrimitiveStatement)test1.getTestCase().getStatement(2)).getValue()); if(newFitness == 0.0) { System.out.println("Iterations: "+i);
private TestCase getTwoIntTest(int x, int y, int x1, int y1) throws NoSuchMethodException, SecurityException, ConstructionFailedException, ClassNotFoundException { Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS); GenericClass clazz = new GenericClass(sut); DefaultTestCase test = new DefaultTestCase(); GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz); TestFactory testFactory = TestFactory.getInstance(); VariableReference callee = testFactory.addConstructor(test, gc, 0, 0); test.addStatement(new IntPrimitiveStatement(test, x)); test.addStatement(new IntPrimitiveStatement(test, y)); VariableReference wrongIntVar1 = test.addStatement(new IntPrimitiveStatement(test, x1)); VariableReference wrongIntVar2 = test.addStatement(new IntPrimitiveStatement(test, y1)); Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class, int.class}); GenericMethod method = new GenericMethod(m, sut); MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] {wrongIntVar1, wrongIntVar2})); test.addStatement(ms); return test; }
test1 = testNew; oldFitness = newFitness; System.out.println(""+i+":"+((IntPrimitiveStatement)test1.getTestCase().getStatement(1)).getValue()); if(newFitness == 0.0) { System.out.println("Iterations: "+i);