1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sourceforge.pmd.stat;
24
25 import static org.junit.Assert.assertEquals;
26
27 import org.junit.Test;
28
29 import net.sourceforge.pmd.stat.Metric;
30
31 import java.util.Random;
32
33
34
35 public class MetricTest {
36 private String testName = "";
37 private Random random = new Random();
38
39 @Test
40 public void testGetMetricName() {
41 Metric IUT = new Metric(testName, 0, 0.0, 0.0, 0.0, 0.0, 0.0);
42
43 assertEquals(testName, IUT.getMetricName());
44 }
45
46 @Test
47 public void testGetCount() {
48 int count = random.nextInt();
49 Metric IUT = new Metric(testName, count, 0.0, 0.0, 0.0, 0.0, 0.0);
50 assertEquals(count, IUT.getCount());
51 }
52
53 @Test
54 public void testGetTotal() {
55 double total = random.nextDouble();
56 Metric IUT = new Metric(testName, 0, total, 0.0, 0.0, 0.0, 0.0);
57 assertEquals(total, IUT.getTotal(), 0.05);
58 }
59
60 @Test
61 public void testGetLowValue() {
62 double low = random.nextDouble();
63 Metric IUT = new Metric(testName, 0, 0.0, low, 0.0, 0.0, 0.0);
64 assertEquals(low, IUT.getLowValue(), 0.05);
65 }
66
67 @Test
68 public void testGetHighValue() {
69 double high = random.nextDouble();
70 Metric IUT = new Metric(testName, 0, 0.0, 0.0, high, 0.0, 0.0);
71 assertEquals(high, IUT.getHighValue(), 0.05);
72 }
73
74 @Test
75 public void testGetAverage() {
76 double mean = random.nextDouble();
77 Metric IUT = new Metric(testName, 0, 0.0, 0.0, 0.0, mean, 0.0);
78 assertEquals(mean, IUT.getAverage(), 0.05);
79 }
80
81 @Test
82 public void testGetStandardDeviation() {
83 double stdev = random.nextDouble();
84 Metric IUT = new Metric(testName, 0, 0.0, 0.0, 0.0, 0.0, stdev);
85 assertEquals(stdev, IUT.getStandardDeviation(), 0.05);
86 }
87
88 public static junit.framework.Test suite() {
89 return new junit.framework.JUnit4TestAdapter(MetricTest.class);
90 }
91 }