/** * Create a random individual * * @param size */ private TestCase getRandomTestCase(int size) { TestCase test = new DefaultTestCase(); int num = 0; TestFactory testFactory = TestFactory.getInstance(); // Then add random stuff while (test.size() < size && num < Properties.MAX_ATTEMPTS) { testFactory.insertRandomStatement(test, test.size() - 1); num++; } //logger.debug("Randomized test case:" + test.toCode()); return test; }
/** * With exponentially decreasing probability, insert statements at random * position * * @return */ public boolean mutationInsert() { boolean changed = false; final double ALPHA = Properties.P_STATEMENT_INSERTION; //0.5; int count = 0; TestFactory testFactory = TestFactory.getInstance(); while (Randomness.nextDouble() <= Math.pow(ALPHA, count) && (!Properties.CHECK_MAX_LENGTH || size() < Properties.CHROMOSOME_LENGTH)) { count++; // Insert at position as during initialization (i.e., using helper sequences) int position = testFactory.insertRandomStatement(test, getLastMutatableStatement()); if (position >= 0 && position < test.size()) { changed = true; mutationHistory.addMutationEntry(new TestMutationHistoryEntry( TestMutationHistoryEntry.TestMutation.INSERTION, test.getStatement(position))); } } return changed; }
/** * Create a random individual * * @param size */ private TestCase getRandomTestCase(int size) { boolean tracerEnabled = ExecutionTracer.isEnabled(); if (tracerEnabled) ExecutionTracer.disable(); TestCase test = getNewTestCase(); int num = 0; // Choose a random length in 0 - size int length = Randomness.nextInt(size); while (length == 0) length = Randomness.nextInt(size); TestFactory testFactory = TestFactory.getInstance(); // Then add random stuff while (test.size() < length && num < Properties.MAX_ATTEMPTS) { testFactory.insertRandomStatement(test, test.size() - 1); num++; } if (logger.isDebugEnabled()) logger.debug("Randomized test case:" + test.toCode()); if (tracerEnabled) ExecutionTracer.enable(); return test; }