Exemplo n.º 1
0
  @Override
  public Map<String, List<String>> generateReport(
      HeaderReport headerReport, AnswerReport answerReport, Filter filter) {
    Map<String, List<String>> headerContent = headerReport.getContent();
    List<String> questions = headerContent.get("Question ID");
    List<String> bugCoveringList = headerContent.get("Bug Covering");

    SessionDTO dto = new FileSessionDTO();
    Map<String, Microtask> microtasks =
        filter.apply((HashMap<String, Microtask>) dto.getMicrotasks());

    List<String> truePositive = new ArrayList<String>();
    List<String> falsePositive = new ArrayList<String>();
    List<String> trueNegative = new ArrayList<String>();
    List<String> falseNegative = new ArrayList<String>();
    List<String> idk = new ArrayList<String>();

    int[] aux = new int[5];

    for (int i = 0; i < questions.size(); i++) {
      Arrays.fill(aux, 0);
      Microtask microtask = microtasks.get(questions.get(i));
      String covering = bugCoveringList.get(i);
      for (Answer answer : microtask.getAnswerList()) {
        if (answer.getOption().equals(Answer.YES)) {
          if (covering.equals("yes")) aux[0]++;
          else aux[2]++;
        } else if (answer.getOption().equals(Answer.I_DONT_KNOW)) aux[4]++;
        else {
          if (covering.equals("no")) aux[1]++;
          else aux[3]++;
        }
      }
      truePositive.add(Integer.toString(aux[0]));
      trueNegative.add(Integer.toString(aux[1]));
      falsePositive.add(Integer.toString(aux[2]));
      falseNegative.add(Integer.toString(aux[3]));
      idk.add(Integer.toString(aux[4]));
    }
    this.correctnessContent.put("True Positives", truePositive);
    this.correctnessContent.put("True Negatives", trueNegative);
    this.correctnessContent.put("False Positives", falsePositive);
    this.correctnessContent.put("False Negatives", falseNegative);
    this.correctnessContent.put("IDK", idk);

    return this.correctnessContent;
  }
  @Test
  public void testMethodMap() {

    String fileName = "TinySample.java";
    String filePath =
        "C:/Users/Christian Adriano/Documents/GitHub/crowd-debug-firefly/samples-discarded/sample/tiny/";
    String fileContent = SourceFileReader.readFileToString(filePath + fileName);

    CodeSnippetFactory snippetFactory = new CodeSnippetFactory("TinySample.java", fileContent);

    Vector<CodeSnippet> list = snippetFactory.generateSnippetsForFile();
    if ((list == null) || (list.size() != 2))
      Assert.fail(
          "Null list of snippets or file does not match test data, actual size is: " + list.size());
    else {
      QuestionFactory questionFactory = new QuestionFactory();
      questionFactory.generateMicrotasks(list, "Bug report message", 0);
      Hashtable<Integer, Microtask> microtaskMap = questionFactory.getConcreteQuestions();

      FileDebugSession fileDebuggingSession =
          new FileDebugSession("TinySample.java", fileContent, microtaskMap);

      // Persist data
      MicrotaskStorage memento = MicrotaskStorage.initializeSingleton();
      ;
      memento.insert(fileName, fileDebuggingSession);

      // Generate the WorkerSession
      WorkerSessionFactory sessionFactory = new WorkerSessionFactory(10);
      HashMap<String, HashMap<String, ArrayList<Microtask>>> actualFileMethodMap =
          sessionFactory.getFileMethodMap();

      HashMap<String, ArrayList<Microtask>> methodMap = actualFileMethodMap.get("TinySample.java");
      Assert.assertNotNull(methodMap);

      ArrayList<Microtask> method1List = methodMap.get("TinySample");
      if (method1List == null || method1List.size() != 4)
        Assert.fail(
            "List of microtasks for method TinySample is wrong, actual size is: "
                + method1List.size());
      else {
        ArrayList<Microtask> method2List = methodMap.get("seedCounter");
        if (method2List == null || method2List.size() != 7)
          Assert.fail(
              "List of microtasks for method seedCounter is wrong, actual size is: "
                  + method2List.size());
        else {
          Microtask mtask1 = method1List.get(0);
          Assert.assertEquals(
              "First Microtask (ID=" + mtask1.getID().toString() + ") of TinySample does not match",
              0,
              mtask1.getID().toString().compareTo("0"));

          Microtask mtask2 = method2List.get(0);
          Assert.assertEquals(
              "First Microtask (ID="
                  + mtask2.getID().toString()
                  + ") of seedCounter does not match",
              0,
              mtask2.getID().toString().compareTo("4"));
        }
      }
    }
  }