diff options
author | Léo Geoffroy <leo.geoffroy@sonarsource.com> | 2024-08-09 15:20:44 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-08-26 20:03:05 +0000 |
commit | f47e4cc9197bc07818510b16f3998ae1da9e8b2a (patch) | |
tree | 6b62d698038a709f1e1cdf9acbf98d6447706154 /server/sonar-server-common | |
parent | 305b3d5937ece0b9aeaaa931fc0d9a4c1e6ba52b (diff) | |
download | sonarqube-f47e4cc9197bc07818510b16f3998ae1da9e8b2a.tar.gz sonarqube-f47e4cc9197bc07818510b16f3998ae1da9e8b2a.zip |
SONAR-22727 Add new software qualities maintainability measures
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r-- | server/sonar-server-common/src/main/java/org/sonar/server/measure/DebtRatingGrid.java | 11 | ||||
-rw-r--r-- | server/sonar-server-common/src/test/java/org/sonar/server/measure/DebtRatingGridTest.java | 15 |
2 files changed, 26 insertions, 0 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/measure/DebtRatingGrid.java b/server/sonar-server-common/src/main/java/org/sonar/server/measure/DebtRatingGrid.java index 247a1829f98..4bbc2b54ac7 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/measure/DebtRatingGrid.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/measure/DebtRatingGrid.java @@ -78,6 +78,17 @@ public class DebtRatingGrid { .orElseThrow(() -> new IllegalArgumentException(format("Invalid value '%s'", value))); } + /** + * Computes a rating from A to D, where E is converted to D. + */ + public Rating getAToDRatingForDensity(double value) { + return ratingBounds.entrySet().stream() + .filter(e -> e.getValue().match(value)) + .map(e -> e.getKey() == E ? D : e.getKey()) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException(format("Invalid value '%s'", value))); + } + public double getGradeLowerBound(Rating rating) { if (rating.getIndex() > 1) { return gridValues[rating.getIndex() - 2]; diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/measure/DebtRatingGridTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/measure/DebtRatingGridTest.java index 8a312cba599..6557e108815 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/measure/DebtRatingGridTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/measure/DebtRatingGridTest.java @@ -55,6 +55,21 @@ public class DebtRatingGridTest { } @Test + public void getAToDRatingForDensity_returnsValueBetweenAAndD() { + assertThat(ratingGrid.getAToDRatingForDensity(0)).isEqualTo(A); + assertThat(ratingGrid.getAToDRatingForDensity(0.05)).isEqualTo(A); + assertThat(ratingGrid.getAToDRatingForDensity(0.09999999)).isEqualTo(A); + assertThat(ratingGrid.getAToDRatingForDensity(0.1)).isEqualTo(A); + assertThat(ratingGrid.getAToDRatingForDensity(0.15)).isEqualTo(B); + assertThat(ratingGrid.getAToDRatingForDensity(0.2)).isEqualTo(B); + assertThat(ratingGrid.getAToDRatingForDensity(0.25)).isEqualTo(C); + assertThat(ratingGrid.getAToDRatingForDensity(0.5)).isEqualTo(C); + assertThat(ratingGrid.getAToDRatingForDensity(0.65)).isEqualTo(D); + assertThat(ratingGrid.getAToDRatingForDensity(1)).isEqualTo(D); + assertThat(ratingGrid.getAToDRatingForDensity(1.01)).isEqualTo(D); + } + + @Test public void density_matching_exact_grid_values() { assertThat(ratingGrid.getRatingForDensity(0.1)).isEqualTo(A); assertThat(ratingGrid.getRatingForDensity(0.2)).isEqualTo(B); |