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.grinder.statistics;
24
25 import junit.framework.TestCase;
26
27
28
29
30
31
32
33
34 public class TestTestStatisticsQueries extends TestCase {
35
36 private final StatisticsServices m_statisticsServices =
37 StatisticsServicesImplementation.getInstance();
38
39 public void testSingleton() throws Exception {
40 assertSame(m_statisticsServices.getTestStatisticsQueries(),
41 m_statisticsServices.getTestStatisticsQueries());
42 }
43
44 public void testTestStatisticsQueries() throws Exception {
45 final StatisticsIndexMap statisticsIndexMap =
46 m_statisticsServices.getStatisticsIndexMap();
47 final StatisticsIndexMap.LongIndex errorStatisticIndex =
48 statisticsIndexMap.getLongIndex("errors");
49 final StatisticsIndexMap.LongIndex untimedTestsIndex =
50 statisticsIndexMap.getLongIndex("untimedTests");
51 final StatisticsIndexMap.LongSampleIndex timedTestsIndex =
52 statisticsIndexMap.getLongSampleIndex("timedTests");
53
54 final StatisticsSet statistics0 =
55 new StatisticsSetImplementation(
56 m_statisticsServices.getStatisticsIndexMap());
57
58 final TestStatisticsQueries queries =
59 m_statisticsServices.getTestStatisticsQueries();
60
61 assertEquals(0, queries.getNumberOfErrors(statistics0));
62 assertEquals(0, queries.getNumberOfTests(statistics0));
63 assertTrue(Double.isNaN(queries.getAverageTestTime(statistics0)));
64
65 final StatisticsSet statistics1 =
66 new StatisticsSetImplementation(
67 m_statisticsServices.getStatisticsIndexMap());
68
69 assertTrue(statistics0 != statistics1);
70 assertEquals(statistics0, statistics1);
71
72 statistics0.addValue(errorStatisticIndex, 1);
73 assertEquals(1, queries.getNumberOfErrors(statistics0));
74 assertTrue(!statistics0.equals(statistics1));
75
76 statistics1.addValue(errorStatisticIndex, 1);
77 assertEquals(statistics0, statistics1);
78
79 statistics0.addValue(untimedTestsIndex, 1);
80 assertEquals(1, queries.getNumberOfTests(statistics0));
81 assertTrue(!statistics0.equals(statistics1));
82
83 statistics1.addValue(untimedTestsIndex, 1);
84 assertEquals(statistics0, statistics1);
85
86 statistics0.addSample(timedTestsIndex, 5);
87 statistics1.addSample(timedTestsIndex, 10);
88 assertEquals(2, queries.getNumberOfTests(statistics0));
89 assertTrue(!statistics0.equals(statistics1));
90
91 statistics0.addSample(timedTestsIndex, 10);
92 statistics1.addSample(timedTestsIndex, 5);
93 assertEquals(statistics0, statistics1);
94 assertEquals(7.5d, queries.getAverageTestTime(statistics1), 0.01);
95 }
96 }