Search in sources :

Example 11 with ICounter

use of org.jacoco.core.analysis.ICounter in project jacoco by jacoco.

the class CounterImplTest method testGetMissedRatio2.

@Test
public void testGetMissedRatio2() {
    ICounter c = CounterImpl.getInstance(0, 20);
    assertEquals(0.0, c.getMissedRatio(), 0.0);
    assertEquals(0.0, c.getValue(CounterValue.MISSEDRATIO), 0.0);
}
Also used : ICounter(org.jacoco.core.analysis.ICounter) Test(org.junit.Test)

Example 12 with ICounter

use of org.jacoco.core.analysis.ICounter in project jacoco by jacoco.

the class CounterImplTest method testHashCode2.

@Test
public void testHashCode2() {
    ICounter c1 = CounterImpl.getInstance(300, 123);
    ICounter c2 = CounterImpl.getInstance(400, 123);
    assertFalse(c1.hashCode() == c2.hashCode());
}
Also used : ICounter(org.jacoco.core.analysis.ICounter) Test(org.junit.Test)

Example 13 with ICounter

use of org.jacoco.core.analysis.ICounter in project jacoco by jacoco.

the class MethodAnalyzer method visitEnd.

@Override
public void visitEnd() {
    // Wire jumps:
    for (final Jump j : jumps) {
        LabelInfo.getInstruction(j.target).setPredecessor(j.source, j.branch);
    }
    // Propagate probe values:
    for (final CoveredProbe p : coveredProbes) {
        p.instruction.setCovered(p.branch);
    }
    // Merge:
    for (final Instruction i : instructions) {
        final AbstractInsnNode m = i.getNode();
        final AbstractInsnNode r = findRepresentative(m);
        if (r != m) {
            ignored.add(m);
            nodeToInstruction.get(r).merge(i);
        }
    }
    // Report result:
    coverage.ensureCapacity(firstLine, lastLine);
    for (final Instruction i : instructions) {
        if (ignored.contains(i.getNode())) {
            continue;
        }
        final int total = i.getBranches();
        final int covered = i.getCoveredBranches();
        final ICounter instrCounter = covered == 0 ? CounterImpl.COUNTER_1_0 : CounterImpl.COUNTER_0_1;
        final ICounter branchCounter = total > 1 ? CounterImpl.getInstance(total - covered, covered) : CounterImpl.COUNTER_0_0;
        coverage.increment(instrCounter, branchCounter, i.getLine());
    }
    coverage.incrementMethodCounter();
}
Also used : ICounter(org.jacoco.core.analysis.ICounter) Instruction(org.jacoco.core.internal.flow.Instruction) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 14 with ICounter

use of org.jacoco.core.analysis.ICounter in project jacoco by jacoco.

the class MethodCoverageImpl method incrementMethodCounter.

/**
 * This method must be called exactly once after all instructions and
 * branches have been incremented for this method coverage node.
 */
public void incrementMethodCounter() {
    final ICounter base = this.instructionCounter.getCoveredCount() == 0 ? CounterImpl.COUNTER_1_0 : CounterImpl.COUNTER_0_1;
    this.methodCounter = this.methodCounter.increment(base);
    this.complexityCounter = this.complexityCounter.increment(base);
}
Also used : ICounter(org.jacoco.core.analysis.ICounter)

Example 15 with ICounter

use of org.jacoco.core.analysis.ICounter in project jacoco by jacoco.

the class CyclomaticComplexityTest method testTwoIf3.

@Test
public void testTwoIf3() throws Exception {
    instrument(TwoIf.class);
    target.test(-1);
    target.test(0);
    final ICounter complexity = analyze();
    assertEquals(CounterImpl.getInstance(1, 2), complexity);
}
Also used : ICounter(org.jacoco.core.analysis.ICounter) Test(org.junit.Test)

Aggregations

ICounter (org.jacoco.core.analysis.ICounter)50 Test (org.junit.Test)40 CounterEntity (org.jacoco.core.analysis.ICoverageNode.CounterEntity)2 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)1 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)1 ILine (org.jacoco.core.analysis.ILine)1 IMethodCoverage (org.jacoco.core.analysis.IMethodCoverage)1 IPackageCoverage (org.jacoco.core.analysis.IPackageCoverage)1 ISourceFileCoverage (org.jacoco.core.analysis.ISourceFileCoverage)1 Instruction (org.jacoco.core.internal.flow.Instruction)1 IReportVisitor (org.jacoco.report.IReportVisitor)1 ISourceFileLocator (org.jacoco.report.ISourceFileLocator)1 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)1