1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.squid.math;
import org.junit.Before;
import org.junit.Test;
import org.sonar.squid.api.SourceCode;
import org.sonar.squid.api.SourceFile;
import org.sonar.squid.measures.Metric;
import java.util.Arrays;
import java.util.Map;
import static org.junit.Assert.assertEquals;
public class MeasuresDistributionTest {
private MeasuresDistribution distribution;
@Before
public void setup() {
SourceFile file0 = newFile("File0.java", 0);
SourceFile file1 = newFile("File1.java", 1);
SourceFile file8 = newFile("File8.java", 8);
SourceFile file10 = newFile("File10.java", 10);
SourceFile file20 = newFile("File20.java", 20);
SourceFile file21 = newFile("File21.java", 21);
SourceFile file30 = newFile("File3.java", 30);
distribution = new MeasuresDistribution(Arrays.<SourceCode>asList(file0, file1, file8, file10, file20, file21, file30));
}
private SourceFile newFile(String filename, int complexity) {
SourceFile file0 = new SourceFile(filename);
file0.setMeasure(Metric.COMPLEXITY, complexity);
return file0;
}
@Test
public void testComplexityDistribution() {
Map<Integer, Integer> intervals = distribution.distributeAccordingTo(Metric.COMPLEXITY, 1, 10, 18, 25);
assertEquals(4, intervals.size());
assertEquals(2, (int) intervals.get(1)); // between 1 included and 10 excluded
assertEquals(1, (int) intervals.get(10));// between 10 included and 18 excluded
assertEquals(2, (int) intervals.get(18));
assertEquals(1, (int) intervals.get(25)); // >= 25
}
}
|