-
Notifications
You must be signed in to change notification settings - Fork 76
Do not use color for unchanged coverage #777 #789
Changes from 2 commits
2b01fe1
c81ac95
023f33a
8781e08
c0a2b1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -544,18 +544,25 @@ public String formatDelta(final Baseline baseline, final Metric metric) { | |
* @param metric | ||
* the metric to check | ||
* | ||
* @return {@code true} if the trend is positive, {@code false} otherwise | ||
* @return {@code roundedDeltaValue} if the trend is positive or negative, {@code 0} otherwise | ||
*/ | ||
@SuppressWarnings("unused") // Called by jelly view | ||
public boolean isPositiveTrend(final Baseline baseline, final Metric metric) { | ||
public double getTrend(final Baseline baseline, final Metric metric) { | ||
var delta = getDelta(baseline, metric); | ||
if (delta.isPresent()) { | ||
if (delta.get().compareTo(Fraction.ZERO) > 0) { | ||
return metric.getTendency() == MetricTendency.LARGER_IS_BETTER; | ||
double deltaValue = delta.get().doubleValue(); | ||
// to apply rounding off for boundary delta values | ||
double roundedDelta = Math.round(deltaValue * 100.0) / 100.0; | ||
uhafner marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if (-0.1 < roundedDelta && roundedDelta < 0.1) { | ||
|
||
// for var(--text-color) | ||
return 0; | ||
} | ||
else { | ||
// for var(--red or --green) | ||
return roundedDelta; | ||
} | ||
return metric.getTendency() == MetricTendency.SMALLER_IS_BETTER; | ||
} | ||
return true; | ||
return 0; // default to zero | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -60,11 +60,14 @@ | |||||
<li>${formatter.formatValueWithMetric(value)} | ||||||
<j:if test="${it.hasDelta(baseline, value.metric)}"> | ||||||
<j:choose> | ||||||
<j:when test="${it.isPositiveTrend(baseline, value.metric)}"> | ||||||
<j:when test="${it.getTrend(baseline, value.metric) > 0}"> | ||||||
|
<j:when test="${it.getTrend(baseline, value.metric) > 0}"> | |
<j:when test="${it.getTrend(baseline, value.metric) gt 0}"> |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<j:when test="${it.getTrend(baseline, value.metric) < 0}"> | |
<j:when test="${it.getTrend(baseline, value.metric) lt 0}"> |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -30,6 +30,38 @@ | |||||||||||
*/ | ||||||||||||
@DefaultLocale("en") | ||||||||||||
class CoverageBuildActionTest { | ||||||||||||
private CoverageBuildAction createCoverageBuildActionWithDelta() { | ||||||||||||
Node module = new ModuleNode("module"); | ||||||||||||
|
||||||||||||
var coverageBuilder = new CoverageBuilder(); | ||||||||||||
var percent50 = coverageBuilder.setMetric(Metric.BRANCH).setCovered(1).setMissed(1).build(); | ||||||||||||
var percent80 = coverageBuilder.setMetric(Metric.LINE).setCovered(8).setMissed(2).build(); | ||||||||||||
var percent30 = coverageBuilder.setMetric(Metric.INSTRUCTION).setCovered(3).setMissed(7).build(); | ||||||||||||
var percent35 = coverageBuilder.setMetric(Metric.CLASS).setCovered(35).setMissed(65).build(); | ||||||||||||
|
||||||||||||
module.addValue(percent50); | ||||||||||||
module.addValue(percent80); | ||||||||||||
module.addValue(percent30); | ||||||||||||
module.addValue(percent35); | ||||||||||||
|
||||||||||||
var deltas = new TreeMap<Metric, Fraction>(); | ||||||||||||
var lineDelta = percent80.getCoveredPercentage().subtract(percent50.getCoveredPercentage()); | ||||||||||||
deltas.put(Metric.LINE, lineDelta); | ||||||||||||
var branchDelta = percent50.getCoveredPercentage().subtract(percent80.getCoveredPercentage()); | ||||||||||||
deltas.put(Metric.BRANCH, branchDelta); | ||||||||||||
var instructionDelta = percent30.getCoveredPercentage().subtract(percent30.getCoveredPercentage()); | ||||||||||||
deltas.put(Metric.INSTRUCTION, instructionDelta); | ||||||||||||
var classDelta = percent35.getCoveredPercentage().subtract(percent30.getCoveredPercentage()); | ||||||||||||
deltas.put(Metric.CLASS, classDelta); | ||||||||||||
deltas.put(Metric.FILE, Fraction.getFraction(99,1000)); // to test for boundary case | ||||||||||||
|
||||||||||||
var coverages = List.of(percent50, percent80, percent30, percent35); | ||||||||||||
|
||||||||||||
return spy(new CoverageBuildAction(mock(FreeStyleBuild.class), CoverageRecorder.DEFAULT_ID, | ||||||||||||
StringUtils.EMPTY, StringUtils.EMPTY, module, new QualityGateResult(), | ||||||||||||
createLog(), "-", deltas, coverages, deltas, coverages, deltas, coverages, false)); | ||||||||||||
} | ||||||||||||
|
||||||||||||
@Test | ||||||||||||
void shouldNotLoadResultIfCoverageValuesArePersistedInAction() { | ||||||||||||
Node module = new ModuleNode("module"); | ||||||||||||
|
@@ -88,4 +120,46 @@ void shouldCreateViewModel() { | |||||||||||
assertThat(action.getTarget()).extracting(CoverageViewModel::getNode).isSameAs(root); | ||||||||||||
assertThat(action.getTarget()).extracting(CoverageViewModel::getOwner).isSameAs(action.getOwner()); | ||||||||||||
} | ||||||||||||
|
||||||||||||
@Test | ||||||||||||
void shouldReturnPositiveTrendForLineMetric() { | ||||||||||||
CoverageBuildAction action = createCoverageBuildActionWithDelta(); | ||||||||||||
double trend = action.getTrend(Baseline.PROJECT, Metric.LINE); | ||||||||||||
assertThat(trend).isEqualTo(0.3); // deltaValue = 0.3 | ||||||||||||
|
CoverageBuildAction action = createCoverageBuildActionWithDelta(); | |
double trend = action.getTrend(Baseline.PROJECT, Metric.LINE); | |
assertThat(trend).isEqualTo(0.3); // deltaValue = 0.3 | |
CoverageBuildAction action = createCoverageBuildActionWithDelta(Baseline.PROJECT, Metric.LINE, Fraction.of("0.001"); | |
assertThat(action.getTrend(Baseline.PROJECT, Metric.LINE)).isPositive(); |
and then
CoverageBuildAction action = createCoverageBuildActionWithDelta(Baseline.PROJECT, Metric.LINE, Fraction.of("0.0009");
assertThat(action.getTrend(Baseline.PROJECT, Metric.LINE)).isZero();
So move the interesting parts to the focus of the reader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be helpful to add here:
assertThat(action.formatDelta(Baseline.PROJECT, Metric.LINE)).isEqualTo("+0.10%");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests look good now!
Just a couple of analysis warnings remaining...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.