예제 #1
0
  private void computeCoverages(
      String packageFilter,
      List<Map.Entry<String, ClassCoverage>> clsEntries,
      Coverage cls,
      Coverage mth,
      Coverage branch,
      Coverage block,
      Coverage line,
      Coverage insn) {
    for (Map.Entry<String, ClassCoverage> e : clsEntries) {
      if (e.getKey().startsWith(packageFilter)) {
        ClassCoverage cc = e.getValue();

        if (cc.isInterface()) {
          continue; // no code
        }

        cls.total++;

        if (cc.covered) {
          cls.covered++;
        }

        insn.add(cc.getCoveredInsn());
        line.add(cc.getCoveredLines());
        block.add(cc.getCoveredBasicBlocks());
        branch.add(cc.getCoveredBranches());
        mth.add(cc.getCoveredMethods());
      }
    }
  }
예제 #2
0
    void printCoverage(Coverage cov) {
      int nTotal = cov.total();
      int nCovered = cov.covered();

      String s;
      if (nTotal <= 0) {
        s = " -  ";
      } else {
        s = String.format("%.2f (%d/%d)", ((double) nCovered / nTotal), nCovered, nTotal);
      }
      pw.print(String.format("%1$-18s", s));
    }
예제 #3
0
    Coverage getCoveredBranches() {
      Coverage cov = new Coverage(0, 0);

      if (methods != null) {
        for (MethodCoverage mc : methods.values()) {
          Coverage c = mc.getCoveredBranches();
          cov.total += c.total;
          cov.covered += c.covered;
        }
      }

      return cov;
    }
예제 #4
0
    Coverage getCoveredMethods() {
      Coverage cov = new Coverage(0, 0);

      if (methods != null) {
        cov.total = methods.size();

        for (MethodCoverage mc : methods.values()) {
          if (mc.covered != null) {
            cov.covered++;
          }
        }
      }

      return cov;
    }
예제 #5
0
    void printCoverage(Coverage cov) {
      int nTotal = cov.total();
      int nCovered = cov.covered();

      if (nTotal <= 0) {
        pw.print("<td class=\"covered\">0</td>");
        pw.print("<td class=\"slash\">/</td>");
        pw.print("<td class=\"total\">0</td>");
        pw.println("<td></td>");
      } else {
        pw.print("<td class=\"covered\">" + nCovered + "</td>");
        pw.print("<td class=\"slash\">/</td>");
        pw.print("<td class=\"total\">" + nTotal + "</td>");
        pw.println("<td>" + HTMLPublisher.makeProgressBar(100 * nCovered / nTotal) + "</td>");
      }
    }
예제 #6
0
  @Test
  public void testCoverage() throws EligibleException {
    Coverage.all(DUMMY_PARAMS);

    verifyGet(Coverage.class, "https://gds.eligibleapi.com/v1.5/coverage/all", DUMMY_PARAMS);
    verifyNoMoreInteractions(networkMock);
  }
예제 #7
0
  // TODO: return correct splits from partitions
  @Override
  public ConnectorSplitSource getPartitionSplits(
      ConnectorTableHandle tableHandle, List<ConnectorPartition> partitions) {
    checkNotNull(partitions, "partitions is null");
    checkArgument(partitions.size() == 1, "Expected one partition but got %s", partitions.size());
    ConnectorPartition partition = partitions.get(0);

    checkArgument(
        partition instanceof RiakPartition, "partition is not an instance of RiakPartition");
    // RiakPartition riakPartition = (RiakPartition) partition;

    RiakTableHandle riakTableHandle = (RiakTableHandle) tableHandle;

    try {
      String parentTable = PRSubTable.parentTableName(riakTableHandle.getTableName());
      SchemaTableName parentSchemaTable =
          new SchemaTableName(riakTableHandle.getSchemaName(), parentTable);
      PRTable table = riakClient.getTable(parentSchemaTable);

      log.debug("> %s", table.getColumns().toString());
      // add all nodes at the cluster here
      List<ConnectorSplit> splits = Lists.newArrayList();
      String hosts = riakClient.getHosts();
      log.debug(hosts);

      if (riakConfig.getLocalNode() != null) {
        // TODO: make coverageSplits here

        // try {
        DirectConnection conn = directConnection;
        // conn.connect(riak);
        // conn.ping();
        Coverage coverage = new Coverage(conn);
        coverage.plan();
        List<SplitTask> splitTasks = coverage.getSplits();

        log.debug("print coverage plan==============");
        log.debug(coverage.toString());

        for (SplitTask split : splitTasks) {
          log.info("============printing split data at " + split.getHost() + "===============");
          // log.debug(((OtpErlangObject)split.getTask()).toString());
          log.info(split.toString());

          CoverageSplit coverageSplit =
              new CoverageSplit(
                  riakTableHandle, // maybe toplevel or subtable
                  table, // toplevel PRTable
                  split.getHost(),
                  split.toString(),
                  partition.getTupleDomain());

          // log.info(new JsonCodecFactory().jsonCodec(CoverageSplit.class).toJson(coverageSplit));
          splits.add(coverageSplit);
        }
      } else {
        // TODO: in Riak connector, you only need single access point for each presto worker???
        log.error("localNode must be set and working");
        log.debug(hosts);
        // splits.add(new CoverageSplit(connectorId, riakTableHandle.getSchemaName(),
        //        riakTableHandle.getTableName(), hosts,
        //        partition.getTupleDomain(),
        //        ((RiakPartition) partition).getIndexedColumns()));

      }
      log.debug(
          "table %s.%s has %d splits.",
          riakTableHandle.getSchemaName(), riakTableHandle.getTableName(), splits.size());

      Collections.shuffle(splits);
      return new FixedSplitSource(connectorId, splits);

    } catch (Exception e) {
      throw new TableNotFoundException(riakTableHandle.toSchemaTableName());
    }
    // this can happen if table is removed during a query

  }
  public List<HoldingsTree> fetchHoldingsTreeForBib(int bibId) throws Exception {
    List<HoldingsTree> holdingsTrees = new ArrayList<HoldingsTree>();

    holdingsPreparedStatement.setInt(1, bibId);
    ResultSet resultSet = holdingsPreparedStatement.executeQuery();
    Map<String, HoldingsTree> map = new HashMap<>();
    Map<String, ExtentOfOwnership> extentOfOwnershipMap = new HashMap<>();
    Set<String> uriSet = null;
    Set<String> noteSet = null;
    Set<String> donorSet = null;
    Set<String> coverageSet = null;
    Set<String> perpetualSet = null;
    Set<String> extentOfOwnershipNoteSet = null;
    Set<String> linkSet = null;

    while (resultSet.next()) {
      String holdingsType = resultSet.getString("HOLDINGS_TYPE");
      String id = resultSet.getString("HOLDINGS_ID");
      OleHoldings oleHoldings = null;
      if (map.containsKey(id)) {
        oleHoldings = map.get(id).getHoldings().getContentObject();
      } else {
        oleHoldings = new OleHoldings();
        Location location =
            getLocationDetails(
                resultSet.getString("LOCATION"), resultSet.getString("LOCATION_LEVEL"));
        oleHoldings.setLocation(location);
        oleHoldings.setHoldingsType(holdingsType);
        CallNumber callNumber = new CallNumber();
        callNumber.setNumber(resultSet.getString("CALL_NUMBER"));
        callNumber.setPrefix(resultSet.getString("CALL_NUMBER_PREFIX"));
        ShelvingOrder shelvingOrder = new ShelvingOrder();
        if (resultSet.getString("SHELVING_ORDER") != null
            && !"null".equals(resultSet.getString("SHELVING_ORDER"))) {
          shelvingOrder.setCodeValue(resultSet.getString("SHELVING_ORDER"));
          shelvingOrder.setFullValue(resultSet.getString("SHELVING_ORDER"));
        }
        callNumber.setShelvingOrder(shelvingOrder);
        ShelvingScheme shelvingScheme = new ShelvingScheme();
        if (resultSet.getString("CALL_NUMBER_TYPE_ID") != null) {
          String[] strings =
              callNumberType.get(resultSet.getString("CALL_NUMBER_TYPE_ID")).split("[|]");
          shelvingScheme.setCodeValue(strings[0]);
          shelvingScheme.setFullValue(strings[1]);
        }
        callNumber.setShelvingScheme(shelvingScheme);
        oleHoldings.setCallNumber(callNumber);
        oleHoldings.setCopyNumber(resultSet.getString("COPY_NUMBER"));
        HoldingsTree holdingsTree = new HoldingsTree();

        Holdings holdings = null;

        if (holdingsType.equalsIgnoreCase(PHoldings.PRINT)) {
          holdings = new PHoldings();

          if (resultSet.getString("RECEIPT_STATUS_ID") != null) {
            oleHoldings.setReceiptStatus(resultSet.getString("RECEIPT_STATUS_ID"));
          }
          extentOfOwnershipNoteSet = new HashSet<>();
          donorSet = coverageSet = perpetualSet = null;
        } else {
          holdings = new EHoldings();
          oleHoldings.setAccessStatus(resultSet.getString("ACCESS_STATUS"));
          oleHoldings.setImprint(resultSet.getString("IMPRINT"));
          Platform platform = new Platform();
          platform.setPlatformName(resultSet.getString("PLATFORM"));
          platform.setAdminUrl(resultSet.getString("ADMIN_URL"));
          platform.setAdminUserName(resultSet.getString("ADMIN_USERNAME"));
          platform.setAdminPassword(resultSet.getString("ADMIN_PASSWORD"));
          oleHoldings.setPlatform(platform);

          oleHoldings.setPublisher(resultSet.getString("PUBLISHER"));
          HoldingsAccessInformation holdingsAccessInformation = new HoldingsAccessInformation();

          holdingsAccessInformation.setProxiedResource(resultSet.getString("PROXIED_RESOURCE"));
          holdingsAccessInformation.setAccessUsername(resultSet.getString("ACCESS_USERNAME"));
          holdingsAccessInformation.setAccessPassword(resultSet.getString("ACCESS_PASSWORD"));
          holdingsAccessInformation.setNumberOfSimultaneousUser(
              resultSet.getString("NUMBER_SIMULT_USERS"));
          holdingsAccessInformation.setAccessLocation(resultSet.getString("CODE"));
          holdingsAccessInformation.setAuthenticationType(
              resultSet.getString("AUTHENTICATION_TYPE_ID"));
          oleHoldings.setHoldingsAccessInformation(holdingsAccessInformation);
          String statisticalSearchId = resultSet.getString("STAT_SEARCH_CODE_ID");
          if (StringUtils.isNotEmpty(statisticalSearchId)) {
            String[] strings = statisticalSearchCodeMap.get(statisticalSearchId).split("[|]");
            StatisticalSearchingCode statisticalSearchingCode = new StatisticalSearchingCode();
            statisticalSearchingCode.setCodeValue(strings[0]);
            statisticalSearchingCode.setFullValue(strings[1]);
            oleHoldings.setStatisticalSearchingCode(statisticalSearchingCode);
          }
          oleHoldings.setLocalPersistentLink(resultSet.getString("LOCAL_PERSISTENT_URI"));
          oleHoldings.setSubscriptionStatus(resultSet.getString("SUBSCRIPTION_STATUS"));
          oleHoldings.setInterLibraryLoanAllowed(Boolean.valueOf(resultSet.getString("ALLOW_ILL")));
          coverageSet = new HashSet<>();
          perpetualSet = new HashSet<>();
          donorSet = new HashSet<>();
          ExtentOfOwnership extentOfOwnership = new ExtentOfOwnership();
          Coverages coverages = new Coverages();
          PerpetualAccesses perpetualAccesses = new PerpetualAccesses();
          extentOfOwnership.setCoverages(coverages);
          extentOfOwnership.setPerpetualAccesses(perpetualAccesses);
          oleHoldings.getExtentOfOwnership().add(extentOfOwnership);
        }
        holdings.setHoldingsType(holdingsType);
        holdings.setId("who-" + id);
        holdings.setContentObject(oleHoldings);
        holdings.setCreatedBy(resultSet.getString("CREATED_BY"));
        holdings.setCreatedOn(resultSet.getString("DATE_CREATED"));
        if (resultSet.getString("STAFF_ONLY") != null) {
          holdings.setStaffOnly(
              (resultSet.getString("STAFF_ONLY").equalsIgnoreCase("Y")
                  ? Boolean.TRUE
                  : Boolean.FALSE));
        }
        holdings.setUpdatedBy(resultSet.getString("UPDATED_BY"));
        holdings.setUpdatedOn(resultSet.getString("DATE_UPDATED"));
        holdings.setLastUpdated(resultSet.getString("DATE_UPDATED"));

        uriSet = new HashSet<>();
        noteSet = new HashSet<>();
        linkSet = new HashSet<>();
        List<Item> itemList = fetchItemForHoldings(Integer.parseInt(id));
        holdingsTree.setHoldings(holdings);
        holdingsTree.getItems().addAll(itemList);

        map.put(id, holdingsTree);

        holdingsTrees.add(holdingsTree);
      }

      if (StringUtils.isNotEmpty(holdingsType) && holdingsType.equalsIgnoreCase(PHoldings.PRINT)) {
        if (uriSet.add(resultSet.getString("HOLDINGS_URI_ID"))) {
          Uri uri = new Uri();
          uri.setValue(resultSet.getString("TEXT"));
          oleHoldings.getUri().add(uri);
        }
        ExtentOfOwnership extentOfOwnership = null;
        if (extentOfOwnershipMap.containsKey(resultSet.getString("EXT_OWNERSHIP_ID"))) {
          extentOfOwnership = extentOfOwnershipMap.get(resultSet.getString("EXT_OWNERSHIP_ID"));
        } else {
          extentOfOwnership = new ExtentOfOwnership();
          if (StringUtils.isNotEmpty(resultSet.getString("EXT_OWNERSHIP_TYPE_ID"))) {
            String[] strings =
                extentOfOwnershipTypeMap
                    .get(resultSet.getString("EXT_OWNERSHIP_TYPE_ID"))
                    .split("[|]");
            extentOfOwnership.setType(strings[1]);
          }
          extentOfOwnershipMap.put(resultSet.getString("EXT_OWNERSHIP_ID"), extentOfOwnership);
          oleHoldings.getExtentOfOwnership().add(extentOfOwnership);
        }
        String extOwnershipNoteId = resultSet.getString("EXT_OWNERSHIP_NOTE_ID");
        if (extentOfOwnershipNoteSet != null
            && StringUtils.isNotEmpty(extOwnershipNoteId)
            && extentOfOwnershipNoteSet.add(resultSet.getString("EXT_OWNERSHIP_NOTE_ID"))) {
          Note note = new Note();
          note.setValue(resultSet.getString(83));
          note.setType(resultSet.getString(82));

          extentOfOwnership.getNote().add(note);
        }
      } else {
        if (linkSet.add(resultSet.getString("HOLDINGS_URI_ID"))) {
          Link link = new Link();
          link.setUrl(resultSet.getString("URI"));
          link.setText(resultSet.getString("TEXT"));
          oleHoldings.getLink().add(link);
        }
        if (oleHoldings.getExtentOfOwnership() != null
            && oleHoldings.getExtentOfOwnership().size() > 0) {
          if (coverageSet != null && coverageSet.add(resultSet.getString("HOLDINGS_COVERAGE_ID"))) {
            Coverage coverage = new Coverage();
            coverage.setCoverageStartIssue(resultSet.getString("COVERAGE_START_ISSUE"));
            coverage.setCoverageStartDate(resultSet.getString("COVERAGE_START_DATE"));
            coverage.setCoverageStartVolume(resultSet.getString("COVERAGE_START_VOLUME"));
            coverage.setCoverageEndIssue(resultSet.getString("HOLDINGS_COVERAGE_ID"));
            coverage.setCoverageEndDate(resultSet.getString("COVERAGE_END_DATE"));
            coverage.setCoverageEndVolume(resultSet.getString("COVERAGE_END_VOLUME"));
            oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().add(coverage);
          }

          if (perpetualSet != null
              && perpetualSet.add(resultSet.getString("HOLDINGS_PERPETUAL_ACCESS_ID"))) {
            PerpetualAccess perpetualAccess = new PerpetualAccess();
            perpetualAccess.setPerpetualAccessStartDate(
                resultSet.getString("PERPETUAL_ACCESS_START_DATE"));
            perpetualAccess.setPerpetualAccessStartIssue(
                resultSet.getString("PERPETUAL_ACCESS_START_ISSUE"));
            perpetualAccess.setPerpetualAccessStartVolume(
                resultSet.getString("PERPETUAL_ACCESS_START_VOLUME"));
            perpetualAccess.setPerpetualAccessEndDate(
                resultSet.getString("PERPETUAL_ACCESS_END_DATE"));
            perpetualAccess.setPerpetualAccessEndVolume(
                resultSet.getString("PERPETUAL_ACCESS_END_VOLUME"));
            perpetualAccess.setPerpetualAccessEndIssue(
                resultSet.getString("PERPETUAL_ACCESS_END_ISSUE"));
            oleHoldings
                .getExtentOfOwnership()
                .get(0)
                .getPerpetualAccesses()
                .getPerpetualAccess()
                .add(perpetualAccess);
          }
        }
        if (donorSet != null && donorSet.add(resultSet.getString("HOLDINGS_DONOR_ID"))) {
          DonorInfo donorInfo = new DonorInfo();
          donorInfo.setDonorCode(resultSet.getString("DONOR_CODE"));
          donorInfo.setDonorNote(resultSet.getString("DONOR_NOTE"));
          donorInfo.setDonorPublicDisplay(resultSet.getString("DONOR_DISPLAY_NOTE"));
          oleHoldings.getDonorInfo().add(donorInfo);
        }
      }

      if (noteSet.add(resultSet.getString("HOLDINGS_NOTE_ID"))) {
        Note note = new Note();
        note.setValue(resultSet.getString("NOTE"));
        note.setType(resultSet.getString("TYPE"));
        oleHoldings.getNote().add(note);
      }
    }
    resultSet.close();
    return holdingsTrees;
  }
예제 #9
0
    void printMethodCoverages(ClassCoverage cc) {
      String space = "  ";
      boolean result = true;

      if (cc.methods == null) {
        return;
      }

      ArrayList<Map.Entry<MethodInfo, MethodCoverage>> mthEntries =
          Misc.createSortedEntryList(
              cc.methods,
              new Comparator<Map.Entry<MethodInfo, MethodCoverage>>() {

                public int compare(
                    Map.Entry<MethodInfo, MethodCoverage> o1,
                    Map.Entry<MethodInfo, MethodCoverage> o2) {
                  int a = o2.getValue().getCoveredInsn().percent();
                  int b = o1.getValue().getCoveredInsn().percent();

                  if (a == b) {
                    return o2.getKey().getUniqueName().compareTo(o1.getKey().getUniqueName());
                  } else {
                    return a - b;
                  }
                }
              });

      Coverage emptyCoverage = new Coverage(0, 0);

      for (Map.Entry<MethodInfo, MethodCoverage> e : mthEntries) {
        MethodCoverage mc = e.getValue();
        MethodInfo mi = mc.getMethodInfo();
        Coverage insnCoverage = mc.getCoveredInsn();
        Coverage lineCoverage = mc.getCoveredLines();
        Coverage branchCoverage = mc.getCoveredBranches();

        result = result && insnCoverage.isFullyCovered();

        pw.print(space);
        printCoverage(insnCoverage);

        pw.print(space);
        printCoverage(lineCoverage);

        pw.print(space);
        printCoverage(mc.getCoveredBasicBlocks());

        pw.print(space);
        printCoverage(branchCoverage);

        pw.print(space);
        printCoverage(emptyCoverage);

        pw.print(space);
        pw.print(mi.getLongName());
        pw.println();

        if (showMethodBodies
            && (!insnCoverage.isFullyCovered() || !branchCoverage.isFullyCovered())) {
          printBodyCoverage(mc);
        }
      }
    }
예제 #10
0
    void printRequirementsCoverage() {
      HashMap<String, Integer> reqMethods = getGlobalRequirementsMethods();

      String space = "  ";
      Coverage bbAll = new Coverage(0, 0);
      Coverage insnAll = new Coverage(0, 0);
      Coverage branchAll = new Coverage(0, 0);
      Coverage mthAll = new Coverage(0, 0);
      Coverage reqAll = new Coverage(0, 0);

      reqAll.total = reqMethods.size();
      mthAll.total = computeTotalRequirementsMethods(reqMethods);

      pw.println();
      pw.println();
      pw.println(
          "--------------------------------- requirements coverage -----------------------------------");
      pw.println(
          "bytecode            basic-block         branch              methods             requirement");
      pw.println(
          "-------------------------------------------------------------------------------------------");

      for (String id : Misc.getSortedKeyStrings(reqMethods)) {

        Coverage bbCoverage = new Coverage(0, 0);
        Coverage insnCoverage = new Coverage(0, 0);
        Coverage branchCoverage = new Coverage(0, 0);
        Coverage reqMth = new Coverage(reqMethods.get(id), 0);

        if (requirements != null && requirements.containsKey(id)) {
          reqAll.covered++;
          for (MethodCoverage mc : requirements.get(id)) {
            insnCoverage.add(mc.getCoveredInsn());
            bbCoverage.add(mc.getCoveredBasicBlocks());
            branchCoverage.add(mc.getCoveredBranches());

            mthAll.covered++;
            reqMth.covered++;
          }

          printCoverage(insnCoverage);
          pw.print(space);
          printCoverage(bbCoverage);
          pw.print(space);
          printCoverage(branchCoverage);
          pw.print(space);
          printCoverage(reqMth);
          pw.print("\"" + id + "\"");

          pw.println();

          if (showMethods) {
            for (MethodCoverage mc : requirements.get(id)) {

              pw.print(space);
              printCoverage(mc.getCoveredInsn());
              pw.print(space);
              printCoverage(mc.getCoveredBasicBlocks());
              pw.print(space);
              printCoverage(mc.getCoveredBranches());
              pw.print(space);

              pw.print(mc.getMethodInfo().getFullName());
              pw.println();
            }
          }
        } else { // requirement not covered
          pw.print(" -                   -                   -                  ");

          printCoverage(reqMth);
          pw.print("\"" + id + "\"");
          pw.println();
        }

        insnAll.add(insnCoverage);
        bbAll.add(bbCoverage);
        branchAll.add(branchCoverage);
      }

      pw.println();
      pw.println(
          "------------------------------------------------------------------------------------------");

      printCoverage(insnAll);
      pw.print(space);
      printCoverage(bbAll);
      pw.print(space);
      printCoverage(branchAll);
      pw.print(space);
      printCoverage(mthAll);
      pw.print(space);
      printCoverage(reqAll);
      pw.print(" total");

      pw.println();
    }
예제 #11
0
    void printRequirementsCoverage() {
      HashMap<String, Integer> reqMethods = getGlobalRequirementsMethods();

      Coverage bbAll = new Coverage(0, 0);
      Coverage insnAll = new Coverage(0, 0);
      Coverage branchAll = new Coverage(0, 0);
      Coverage mthAll = new Coverage(0, 0);
      Coverage reqAll = new Coverage(0, 0);

      reqAll.total = reqMethods.size();
      mthAll.total = computeTotalRequirementsMethods(reqMethods);

      pw.println("      <p><b>Requirements Coverage</b></p>");
      pw.println("      <table>");
      pw.println(
          "         <tr><th colspan=\"4\">Instructions</th><th colspan=\"4\">Basic Block</th><th colspan=\"4\">Branch</th><th colspan=\"4\">Methods</th><th colspan=\"4\">Requirement</th></tr>");

      for (String id : Misc.getSortedKeyStrings(reqMethods)) {

        Coverage bbCoverage = new Coverage(0, 0);
        Coverage insnCoverage = new Coverage(0, 0);
        Coverage branchCoverage = new Coverage(0, 0);
        Coverage reqMth = new Coverage(reqMethods.get(id), 0);

        if (requirements != null && requirements.containsKey(id)) {
          reqAll.covered++;
          for (MethodCoverage mc : requirements.get(id)) {
            insnCoverage.add(mc.getCoveredInsn());
            bbCoverage.add(mc.getCoveredBasicBlocks());
            branchCoverage.add(mc.getCoveredBranches());

            mthAll.covered++;
            reqMth.covered++;
          }

          pw.print("         <tr>");

          printCoverage(insnCoverage);
          printCoverage(bbCoverage);
          printCoverage(branchCoverage);
          printCoverage(reqMth);
          pw.print("\"" + id + "\"");

          pw.print("</tr>");

          pw.println();

          if (showMethods) {
            for (MethodCoverage mc : requirements.get(id)) {

              pw.print("         <tr>");

              printCoverage(mc.getCoveredInsn());
              printCoverage(mc.getCoveredBasicBlocks());
              printCoverage(mc.getCoveredBranches());

              pw.print("<td align=\"left\" colspan=\"4\" style=\"padding-right: 10px;\">");

              pw.print(mc.getMethodInfo().getFullName());

              pw.print("</tr>");

              pw.println();
            }
          }
        } else { // requirement not covered
          pw.print(
              "         <tr><td colspan=\"4\"></td><td colspan=\"4\"></td><td colspan=\"4\"></td>");

          printCoverage(reqMth);
          pw.print("\"" + id + "\"");

          pw.print("</tr>");

          pw.println();
        }

        insnAll.add(insnCoverage);
        bbAll.add(bbCoverage);
        branchAll.add(branchCoverage);
      }

      pw.print("         <tr>");

      printCoverage(insnAll);
      printCoverage(bbAll);
      printCoverage(branchAll);
      printCoverage(mthAll);
      printCoverage(reqAll);
      pw.print(" total");

      pw.println("</tr>");
      pw.println("      </table>");
    }
예제 #12
0
    void printMethodCoverages(ClassCoverage cc) {
      String classNameTree = "cc-" + cc.className.replace('.', '-') + '-';
      int line, lineNumbers[];
      boolean result = true;

      if (cc.methods == null) {
        return;
      }

      ArrayList<Map.Entry<MethodInfo, MethodCoverage>> mthEntries =
          Misc.createSortedEntryList(
              cc.methods,
              new Comparator<Map.Entry<MethodInfo, MethodCoverage>>() {

                public int compare(
                    Map.Entry<MethodInfo, MethodCoverage> o1,
                    Map.Entry<MethodInfo, MethodCoverage> o2) {
                  int a = o2.getValue().getCoveredInsn().percent();
                  int b = o1.getValue().getCoveredInsn().percent();

                  if (a == b) {
                    return o2.getKey().getUniqueName().compareTo(o1.getKey().getUniqueName());
                  } else {
                    return a - b;
                  }
                }
              });

      for (Map.Entry<MethodInfo, MethodCoverage> e : mthEntries) {
        MethodCoverage mc = e.getValue();
        MethodInfo mi = mc.getMethodInfo();
        Coverage insnCoverage = mc.getCoveredInsn();
        Coverage lineCoverage = mc.getCoveredLines();
        Coverage branchCoverage = mc.getCoveredBranches();

        result = result && insnCoverage.isFullyCovered();

        HTMLPublisher.writeTableTreeNodeBegin(
            pw, classNameTree + HTMLPublisher.escape(mi.getLongName()));
        pw.print("            <td class=\"firstCol\">");

        lineNumbers = mi.getLineNumbers();
        if ((lineNumbers != null) && (lineNumbers.length > 0)) {
          line = lineNumbers[0];
        } else {
          line = 0;
        }

        ((HTMLPublisher) publisher).writeSourceAnchor(pw, mi.getSourceFileName(), line);

        pw.print(HTMLPublisher.escape(mi.getLongName()));
        pw.println("</a></td>");

        pw.print("            ");

        printCoverage(insnCoverage);
        printCoverage(lineCoverage);
        printCoverage(mc.getCoveredBasicBlocks());
        printCoverage(branchCoverage);

        pw.println();
        HTMLPublisher.writeTableTreeNodeEnd(pw);
      }
    }
예제 #13
0
 private static boolean testExternalNodeBasedCoverage() {
   try {
     final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
     final String ps1 =
         "((((A:0.1,B:0.7):0.2,C:1.0):2.0,D:1.7):1.3,((E:0.3,F:0.4):1.1,(G:0.5,H:0.6):1.2):1.4,X:2.0)";
     final Phylogeny p1 = factory.create(ps1, new NHXParser())[0];
     final List<Phylogeny> phylogenies = new ArrayList<Phylogeny>();
     final List<String> names = new ArrayList<String>();
     phylogenies.add(p1);
     names.add("A");
     names.add("A");
     final CoverageCalculationOptions options =
         new ExternalNodeBasedCoverageMethodOptions(
             "org.forester.pccx.BranchCountingBasedScoringMethod");
     final CoverageCalculator cc =
         CoverageCalculator.getInstance(new ExternalNodeBasedCoverageMethod(), options);
     Coverage cov = cc.calculateCoverage(phylogenies, names, false);
     if (!TestPccx.isEqual(
         cov.getScore(),
         (1.0 + 1.0 / 2 + 1.0 / 3 + 1.0 / 4 + 1.0 / 7 + 1.0 / 7 + 1.0 / 7 + 1.0 / 7 + 1.0 / 5)
             / 9)) {
       return false;
     }
     names.add("B");
     names.add("B");
     cov = cc.calculateCoverage(phylogenies, names, false);
     if (!TestPccx.isEqual(
         cov.getScore(),
         (1.0 + 1.0 + 1.0 / 3 + 1.0 / 4 + 1.0 / 7 + 1.0 / 7 + 1.0 / 7 + 1.0 / 7 + 1.0 / 5) / 9)) {
       return false;
     }
     names.add("G");
     cov = cc.calculateCoverage(phylogenies, names, false);
     if (!TestPccx.isEqual(
         cov.getScore(),
         (1.0 + 1.0 + 1.0 / 3 + 1.0 / 4 + 1.0 / 4 + 1.0 / 4 + 1.0 + 1.0 / 2 + 1.0 / 4) / 9)) {
       return false;
     }
     names.add("E");
     cov = cc.calculateCoverage(phylogenies, names, false);
     if (!TestPccx.isEqual(
         cov.getScore(),
         (1.0 + 1.0 + 1.0 / 3 + 1.0 / 4 + 1.0 + 1.0 / 2 + 1.0 + 1.0 / 2 + 1.0 / 4) / 9)) {
       return false;
     }
     names.add("X");
     cov = cc.calculateCoverage(phylogenies, names, false);
     if (!TestPccx.isEqual(
         cov.getScore(),
         (1.0 + 1.0 + 1.0 / 3 + 1.0 / 3 + 1.0 + 1.0 / 2 + 1.0 + 1.0 / 2 + 1.0) / 9)) {
       return false;
     }
     names.add("C");
     names.add("C");
     names.add("C");
     cov = cc.calculateCoverage(phylogenies, names, false);
     if (!TestPccx.isEqual(
         cov.getScore(), (1.0 + 1.0 + 1.0 + 1.0 / 3 + 1.0 + 1.0 / 2 + 1.0 + 1.0 / 2 + 1.0) / 9)) {
       return false;
     }
     names.add("D");
     cov = cc.calculateCoverage(phylogenies, names, false);
     if (!TestPccx.isEqual(
         cov.getScore(), (1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 / 2 + 1.0 + 1.0 / 2 + 1.0) / 9)) {
       return false;
     }
     names.add("F");
     cov = cc.calculateCoverage(phylogenies, names, false);
     if (!TestPccx.isEqual(
         cov.getScore(), (1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 / 2 + 1.0) / 9)) {
       return false;
     }
     names.add("H");
     cov = cc.calculateCoverage(phylogenies, names, false);
     if (!TestPccx.isEqual(
         cov.getScore(), (1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0) / 9)) {
       return false;
     }
     final CoverageExtender ce = new BasicExternalNodeBasedCoverageExtender();
     List<String> l =
         ce.find(
             phylogenies,
             null,
             0,
             new ExternalNodeBasedCoverageMethodOptions(
                 "org.forester.pccx.BranchCountingBasedScoringMethod"),
             null);
     if (!l.get(0).equals("X")) {
       return false;
     }
     if (!l.get(1).equals("A")) {
       return false;
     }
     if (!l.get(2).equals("E")) {
       return false;
     }
     if (!l.get(3).equals("G")) {
       return false;
     }
     if (!l.get(4).equals("C")) {
       return false;
     }
     if (!l.get(5).equals("D")) {
       return false;
     }
     if (!l.get(6).equals("B")) {
       return false;
     }
     if (!l.get(7).equals("F")) {
       return false;
     }
     if (!l.get(8).equals("H")) {
       return false;
     }
     final List<String> already_covered = new ArrayList<String>();
     already_covered.add("A");
     already_covered.add("X");
     already_covered.add("H");
     already_covered.add("C");
     l =
         ce.find(
             phylogenies,
             already_covered,
             0,
             new ExternalNodeBasedCoverageMethodOptions(
                 "org.forester.pccx.BranchCountingBasedScoringMethod"),
             null);
     if (!l.get(0).equals("E")) {
       return false;
     }
     if (!l.get(1).equals("D")) {
       return false;
     }
     if (!l.get(2).equals("B")) {
       return false;
     }
     if (!l.get(3).equals("F")) {
       return false;
     }
     if (!l.get(4).equals("G")) {
       return false;
     }
     final String ps2 =
         "((((A:0.1,B:0.7):0.2,C:1.0):2.0,D:1.7):1.3,((E:0.3,F:0.4):1.1,(G:0.5,H:0.6):1.2):1.4,X:2.0)";
     final String ps3 =
         "((((A:0.1,B:0.1):0.2,C:1.0):2.0,D:1.7):1.3,((E:0.3,F:0.4):1.1,(G:0.5,H:0.6):1.2):1.4,X:2.0)";
     final String ps4 =
         "((((A:0.1,B:0.05):0.2,C:1.0):2.0,D:1.7):1.3,((E:0.3,F:0.4):1.1,(G:0.5,H:0.6):1.2):1.4,X:2.0)";
     final Phylogeny p2 = factory.create(ps2, new NHXParser())[0];
     final Phylogeny p3 = factory.create(ps3, new NHXParser())[0];
     final Phylogeny p4 = factory.create(ps4, new NHXParser())[0];
     final List<Phylogeny> phylogenies2 = new ArrayList<Phylogeny>();
     final List<String> names2 = new ArrayList<String>();
     phylogenies2.add(p2);
     phylogenies2.add(p3);
     phylogenies2.add(p4);
     names2.add("A");
     names2.add("A");
     final CoverageCalculationOptions options2 =
         new ExternalNodeBasedCoverageMethodOptions(
             "org.forester.pccx.BranchLengthBasedScoringMethod");
     final CoverageCalculator cc2 =
         CoverageCalculator.getInstance(new ExternalNodeBasedCoverageMethod(), options2);
     Coverage cov2 = cc2.calculateCoverage(phylogenies2, names2, false);
     final double nf =
         1
             / (1 / 0.1 + 1 / 0.7 + 1 / 1.0 + 1 / 1.7 + 1 / 0.3 + 1 / 0.4 + 1 / 0.5 + 1 / 0.6
                 + 1 / 2.0);
     if (!TestPccx.isEqual(
         cov2.getScore(),
         (1 / 0.1
                 + (1 / 0.8 + 1 / 0.2 + 1 / 0.15) / 3
                 + 1 / 1.3
                 + 1 / 4.0
                 + 1 / 6.4
                 + 1 / 6.5
                 + 1 / 6.7
                 + 1 / 6.8
                 + 1 / 5.6)
             * nf)) {
       return false;
     }
     names2.add("C");
     cov2 = cc2.calculateCoverage(phylogenies2, names2, false);
     if (!TestPccx.isEqual(
         cov2.getScore(),
         (1 / 0.1
                 + (1 / 0.8 + 1 / 0.2 + 1 / 0.15) / 3
                 + 1 / 1.0
                 + 1 / 4.0
                 + 1 / 6.4
                 + 1 / 6.5
                 + 1 / 6.7
                 + 1 / 6.8
                 + 1 / 5.6)
             * nf)) {
       return false;
     }
     names2.add("E");
     cov2 = cc2.calculateCoverage(phylogenies2, names2, false);
     if (!TestPccx.isEqual(
         cov2.getScore(),
         (1 / 0.1
                 + (1 / 0.8 + 1 / 0.2 + 1 / 0.15) / 3
                 + 1 / 1.0
                 + +1 / 4.0
                 + 1 / 0.3
                 + 1 / 0.7
                 + 1 / 3.1
                 + 1 / 3.2
                 + 1 / 4.8)
             * nf)) {
       return false;
     }
     final CoverageCalculationOptions options_log =
         new ExternalNodeBasedCoverageMethodOptions(
             "org.forester.pccx.LogBranchLengthBasedScoringMethod");
     final CoverageCalculator cclog =
         CoverageCalculator.getInstance(new ExternalNodeBasedCoverageMethod(), options_log);
     final Coverage cov_log = cclog.calculateCoverage(phylogenies2, names2, false);
     if (!TestPccx.isEqual(cov_log.getScore(), 0.8534252108361485)) {
       return false;
     }
     final String ps10 =
         "((((A:0.1,B:0.7):0.2,C:1.0):2.0,D:1.7):1.3,((E:0.3,F:0.4):1.1,(G:0.5,H:0.6):1.2):1.4,((((I:0.1,J:0.7):0.2,K:1.0):2.0,L:1.7):1.3,((M:0.3,N:0.4,O:0.1,P:0.2):1.1,(Q:0.5,R:0.6):1.2):1.4,S:2.0):2.0)";
     final Phylogeny p10 = factory.create(ps10, new NHXParser())[0];
     final List<Phylogeny> phylogenies10 = new ArrayList<Phylogeny>();
     final List<String> names10 = new ArrayList<String>();
     phylogenies10.add(p10);
     names10.add("A");
     names10.add("B");
     names10.add("N");
     names10.add("O");
     final CoverageCalculationOptions options10 =
         new ExternalNodeBasedCoverageMethodOptions(
             "org.forester.pccx.BranchCountingBasedScoringMethod");
     final CoverageCalculator cc10 =
         CoverageCalculator.getInstance(new ExternalNodeBasedCoverageMethod(), options10);
     cc10.calculateCoverage(phylogenies10, names10, true);
   } catch (final Exception e) {
     e.printStackTrace(System.out);
     return false;
   }
   return true;
 }