3 * Copyright (C) 2009-2018 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.computation.task.projectanalysis.qualitymodel;
22 import org.junit.Before;
23 import org.junit.Rule;
24 import org.junit.Test;
25 import org.junit.rules.ExpectedException;
27 import static org.assertj.core.api.Assertions.assertThat;
29 import static org.sonar.server.computation.task.projectanalysis.qualitymodel.Rating.A;
30 import static org.sonar.server.computation.task.projectanalysis.qualitymodel.Rating.B;
31 import static org.sonar.server.computation.task.projectanalysis.qualitymodel.Rating.C;
32 import static org.sonar.server.computation.task.projectanalysis.qualitymodel.Rating.D;
33 import static org.sonar.server.computation.task.projectanalysis.qualitymodel.Rating.E;
35 public class DebtRatingGridTest {
37 private DebtRatingGrid ratingGrid;
40 public ExpectedException throwable = ExpectedException.none();
44 double[] gridValues = new double[] {0.1, 0.2, 0.5, 1};
45 ratingGrid = new DebtRatingGrid(gridValues);
49 public void return_rating_matching_density() {
50 assertThat(ratingGrid.getRatingForDensity(0)).isEqualTo(A);
51 assertThat(ratingGrid.getRatingForDensity(0.05)).isEqualTo(A);
52 assertThat(ratingGrid.getRatingForDensity(0.09999999)).isEqualTo(A);
53 assertThat(ratingGrid.getRatingForDensity(0.1)).isEqualTo(B);
54 assertThat(ratingGrid.getRatingForDensity(0.15)).isEqualTo(B);
55 assertThat(ratingGrid.getRatingForDensity(0.2)).isEqualTo(C);
56 assertThat(ratingGrid.getRatingForDensity(0.25)).isEqualTo(C);
57 assertThat(ratingGrid.getRatingForDensity(0.5)).isEqualTo(D);
58 assertThat(ratingGrid.getRatingForDensity(0.65)).isEqualTo(D);
59 assertThat(ratingGrid.getRatingForDensity(1)).isEqualTo(E);
60 assertThat(ratingGrid.getRatingForDensity(1.01)).isEqualTo(E);
64 public void fail_on_invalid_density() {
65 throwable.expect(RuntimeException.class);
67 ratingGrid.getRatingForDensity(-1);
71 public void convert_int_to_rating() throws Exception {
72 assertThat(Rating.valueOf(1)).isEqualTo(A);
73 assertThat(Rating.valueOf(2)).isEqualTo(B);
74 assertThat(Rating.valueOf(3)).isEqualTo(C);
75 assertThat(Rating.valueOf(4)).isEqualTo(D);
76 assertThat(Rating.valueOf(5)).isEqualTo(E);
80 public void fail_to_concert_invalid_value() throws Exception {
81 throwable.expect(IllegalArgumentException.class);