}
public Metric create() {
+ if (ValueType.PERCENT.equals(this.type)) {
+ this.bestValue = (direction == DIRECTION_BETTER ? 100.0 : 0.0);
+ this.worstValue = (direction == DIRECTION_BETTER ? 0.0 : 100.0);
+ }
return new Metric(key, name, type, description, direction, domain, qualitative, worstValue, bestValue, optimizedBestValue, hidden, formula);
}
}
assertThat(metric.isHidden(), is(false));
assertThat(metric.isOptimizedBestValue(), is(false));
}
+
+ @Test
+ public void shouldCreatePercentMetricWithDefaultValues() {
+ Metric better = new Metric.Builder("foo", "Foo", Metric.ValueType.PERCENT)
+ .setDirection(Metric.DIRECTION_BETTER)
+ .create();
+ Metric worst = new Metric.Builder("foo", "Foo", Metric.ValueType.PERCENT)
+ .setDirection(Metric.DIRECTION_WORST)
+ .create();
+
+ assertThat(better.getBestValue(), is(100.0));
+ assertThat(better.getWorstValue(), is(0.0));
+ assertThat(worst.getBestValue(), is(0.0));
+ assertThat(worst.getWorstValue(), is(100.0));
+ }
+
}