public double getBranchCoverageRate() { int branches = getNumberOfValidBranches(); int hit = (defaultHits > 0) ? 1 : 0; for (int i = hits.length - 1; i >= 0; hit += ((hits[i--] > 0) ? 1 : 0)); return ((double) hit) / branches; }
void addSwitch(int switchNumber, int min, int max, int maxBranches) { SwitchData sd = getSwitchData(switchNumber, new SwitchData( switchNumber, min, max, maxBranches)); if (sd.getMaxBranches() > maxBranches) { sd.setMaxBranches(maxBranches); } }
public int getNumberOfCoveredBranches() { int ret = 0; if (jumps != null) for (int i = jumps.size() - 1; i >= 0; i--) ret += ((JumpData) jumps.get(i)).getNumberOfCoveredBranches(); if (switches != null) for (int i = switches.size() - 1; i >= 0; i--) ret += ((SwitchData) switches.get(i)) .getNumberOfCoveredBranches(); return ret; }
private Collection<Long> hitArray(LineData ld) { ArrayList<Long> result = new ArrayList<Long>(); if ( ld.hasBranch() ) { for ( int i = 0; i < ld.getConditionSize(); i++ ) { Object xcd = ld.getConditionData( i ); if ( xcd instanceof SwitchData ) { SwitchData sd = (SwitchData) xcd; for( int j = 0; j < sd.getNumberOfValidBranches() - 1; j++ ) { result.add( sd.getHits( j ) ); } result.add( sd.getDefaultHits() ); } else { JumpData jd = (JumpData) xcd; result.add( jd.getTrueHits() ); result.add( jd.getFalseHits() ); } } } return result; }
synchronized SwitchData getSwitchData(int switchNumber, SwitchData data) { if (switches == null) { switches = new ArrayList<SwitchData>(); } if (switches.size() < switchNumber) { for (int i = switches.size(); i < switchNumber; switches .add(new SwitchData(i++, Integer.MAX_VALUE))); } if (switches.size() == switchNumber) { if (data != null) { switches.add(data); } else { switches.add(new SwitchData(switchNumber, Integer.MAX_VALUE)); } } return (SwitchData) switches.get(switchNumber); }
public String getConditionCoverage(int index) { Object branchData = getConditionData(index); if (branchData == null) { return StringUtil.getPercentValue(1.0); } else if (branchData instanceof JumpData) { JumpData jumpData = (JumpData) branchData; return StringUtil.getPercentValue(jumpData.getBranchCoverageRate()); } else { SwitchData switchData = (SwitchData) branchData; return StringUtil.getPercentValue(switchData .getBranchCoverageRate()); } }
void touchSwitch(int switchNumber, int branch) { getSwitchData(switchNumber, null).touchBranch(branch); }
private void dumpCondition(Object conditionData, String coverage) { increaseIndentation(); StringBuffer buffer = new StringBuffer("<condition"); if (conditionData instanceof JumpData) { JumpData jumpData = (JumpData) conditionData; buffer.append(" number=\"").append(jumpData.getConditionNumber()) .append("\""); buffer.append(" type=\"").append("jump").append("\""); buffer.append(" coverage=\"").append(coverage).append("\""); } else { SwitchData switchData = (SwitchData) conditionData; buffer.append(" number=\"").append(switchData.getSwitchNumber()) .append("\""); buffer.append(" type=\"").append("switch").append("\""); buffer.append(" coverage=\"").append(coverage).append("\""); } buffer.append("/>"); println(buffer.toString()); decreaseIndentation(); }
.size()) - 1; i >= 0; i--) ((SwitchData) this.switches.get(i)) .merge((SwitchData) lineData.switches.get(i)); for (int i = Math.min(this.switches.size(), lineData.switches .size()); i < lineData.switches.size(); i++)
public boolean equals(Object obj) { if (this == obj) return true; if ((obj == null) || !(obj.getClass().equals(this.getClass()))) return false; SwitchData switchData = (SwitchData) obj; getBothLocks(switchData); try { return (this.defaultHits == switchData.defaultHits) && (Arrays.equals(this.hits, switchData.hits)) && (this.switchNumber == switchData.switchNumber); } finally { lock.unlock(); switchData.lock.unlock(); } }
SwitchData lsd = (SwitchData) cd; result.addLineSwitch( lld.getLineNumber(), i, 0, 0 ); long[] prevBranchHits = new long[ lsd.getNumberOfValidBranches() - 1]; long prevDefaultHits = 0; if ( smaller != null ) { prevBranchHits[j] = Math.max( 0, ssd.getHits( j ) ); prevDefaultHits = ssd.getDefaultHits(); long diffBranchHits = lsd.getHits( j ) - prevBranchHits[j]; result.touchSwitch( lld.getLineNumber(), i, j, (int)diffBranchHits ); if ( diffBranchHits < 0 ) { long diffDefaultHits = lsd.getDefaultHits() - prevDefaultHits; if ( diffDefaultHits > 0 ) { result.touchSwitch( lld.getLineNumber(), i, -1, (int) diffDefaultHits );
synchronized SwitchData getSwitchData(int switchNumber, SwitchData data) { if (switches == null) { switches = new ArrayList<SwitchData>(); } if (switches.size() < switchNumber) { for (int i = switches.size(); i < switchNumber; switches .add(new SwitchData(i++, Integer.MAX_VALUE))); } if (switches.size() == switchNumber) { if (data != null) { switches.add(data); } else { switches.add(new SwitchData(switchNumber, Integer.MAX_VALUE)); } } return (SwitchData) switches.get(switchNumber); }
public String getConditionCoverage(int index) { Object branchData = getConditionData(index); if (branchData == null) { return StringUtil.getPercentValue(1.0); } else if (branchData instanceof JumpData) { JumpData jumpData = (JumpData) branchData; return StringUtil.getPercentValue(jumpData.getBranchCoverageRate()); } else { SwitchData switchData = (SwitchData) branchData; return StringUtil.getPercentValue(switchData .getBranchCoverageRate()); } }
void touchSwitch(int switchNumber, int branch, int hits) { getSwitchData(switchNumber, null).touchBranch(branch, hits); }
private void dumpCondition(Object conditionData, String coverage) { increaseIndentation(); StringBuffer buffer = new StringBuffer("<condition"); if (conditionData instanceof JumpData) { JumpData jumpData = (JumpData) conditionData; buffer.append(" number=\"").append(jumpData.getConditionNumber()) .append("\""); buffer.append(" type=\"").append("jump").append("\""); buffer.append(" coverage=\"").append(coverage).append("\""); } else { SwitchData switchData = (SwitchData) conditionData; buffer.append(" number=\"").append(switchData.getSwitchNumber()) .append("\""); buffer.append(" type=\"").append("switch").append("\""); buffer.append(" coverage=\"").append(coverage).append("\""); } buffer.append("/>"); println(buffer.toString()); decreaseIndentation(); }
.size()) - 1; i >= 0; i--) ((SwitchData) this.switches.get(i)) .merge((SwitchData) lineData.switches.get(i)); for (int i = Math.min(this.switches.size(), lineData.switches .size()); i < lineData.switches.size(); i++)
public void merge(BranchCoverageData coverageData) { SwitchData switchData = (SwitchData) coverageData; getBothLocks(switchData); try { defaultHits += switchData.defaultHits; for (int i = Math.min(hits.length, switchData.hits.length) - 1; i >= 0; i--) hits[i] += switchData.hits[i]; if (switchData.hits.length > hits.length) { long[] old = hits; hits = new long[switchData.hits.length]; System.arraycopy(old, 0, hits, 0, old.length); System.arraycopy(switchData.hits, old.length, hits, old.length, hits.length - old.length); } if ((this.keys.length == 0) && (switchData.keys.length > 0)) this.keys = switchData.keys; } finally { lock.unlock(); switchData.lock.unlock(); } }
public double getBranchCoverageRate() { int branches = getNumberOfValidBranches(); int hit = (defaultHits > 0) ? 1 : 0; for (int i = hits.length - 1; i >= 0; hit += ((hits[i--] > 0) ? 1 : 0)); return ((double) hit) / branches; }
void addSwitch(int switchNumber, int min, int max, int maxBranches) { SwitchData sd = getSwitchData(switchNumber, new SwitchData( switchNumber, min, max, maxBranches)); if (sd.getMaxBranches() > maxBranches) { sd.setMaxBranches(maxBranches); } }
void addSwitch(int switchNumber, int[] keys) { getSwitchData(switchNumber, new SwitchData(switchNumber, keys)); }