Beispiel #1
0
  private static boolean greedySwitch(
      ArrayList<TestResult> testSuite, ArrayList<TestResult> unused) {
    TestResult max = unused.get(0);
    TestResult min = testSuite.get(0);

    for (TestResult i : testSuite) {
      if (i.getUniqueMutants().size() < min.getUniqueMutants().size()) {
        min = i;
      }
    }

    for (TestResult i : unused) {
      if (i.getUniqueMutants().size() > max.getUniqueMutants().size()) {
        max = i;
      }
    }

    if (min.getUniqueMutants().equals(0) && !(max.getUniqueMutants().equals(0))) {
      int testSuiteLoc = testSuite.indexOf(min);
      testSuite.remove(testSuiteLoc);
      testSuite.add(testSuiteLoc, max);

      int unusedLoc = unused.indexOf(max);
      unused.remove(unusedLoc);
      unused.add(unusedLoc, min);

      return true;
    }

    return false;
  }
Beispiel #2
0
  // Fitness function that gives higher score based on best time while maintining minimum mutant
  // score
  // Higher scores are better
  private static double fitnessOnTime(ArrayList<TestResult> solution, int targetScore) {
    double time = 0.0;
    int score = 0;

    for (TestResult i : solution) {
      score += i.getUniqueMutants().size();
      time += i.getTime();
    }

    if (score < targetScore) {
      return Double.MIN_VALUE;
    } else {
      return 1 / time;
    }
  }
Beispiel #3
0
  // Fitness function that gives higher score based on better mutantscore without going over target
  // time
  // Higher scores are better
  private static int fitnessOnScore(ArrayList<TestResult> solution, double targetTime) {
    double time = 0.0;
    int score = 0;

    for (TestResult i : solution) {
      score += i.getUniqueMutants().size();
      time += i.getTime();
    }

    if (time > targetTime) {
      return 0;
    } else {
      return score;
    }
  }
Beispiel #4
0
  private static void greedySolution(
      ArrayList<TestResult> testSuite, ArrayList<TestResult> unused) {

    try {
      BufferedReader in =
          new BufferedReader(
              new FileReader("C:/Users/100455689/Desktop/Thesis/Past Work/config.json"));

      in.readLine();
      String timeString = in.readLine().split(": ")[1].split(",")[0];
      double targetTime = Double.parseDouble(timeString);

      String scoreString = in.readLine().split(": ")[1];
      int targetScore = Integer.parseInt(scoreString);

      double time = 0;
      Iterator<TestResult> iter = testSuite.iterator();
      while (iter.hasNext()) {
        TestResult i = iter.next();
        double newTime = time + i.getTime();

        if (newTime <= targetTime) {
          time = newTime;
        } else {
          iter.remove();
          unused.add(i);
        }
      }

      boolean changed = true;
      while (changed) {
        changed = greedySwitch(testSuite, unused);
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
  }