View Javadoc

1   // Copyright (C) 2000 Paco Gomez
2   // Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Philip Aston
3   // All rights reserved.
4   //
5   // This file is part of The Grinder software distribution. Refer to
6   // the file LICENSE which is part of The Grinder distribution for
7   // licensing details. The Grinder distribution is available on the
8   // Internet at http://grinder.sourceforge.net/
9   //
10  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
12  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13  // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
14  // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
15  // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16  // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
17  // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
19  // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
20  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
21  // OF THE POSSIBILITY OF SUCH DAMAGE.
22  
23  package net.grinder.statistics;
24  
25  import junit.framework.TestCase;
26  
27  
28  /**
29   * Unit test case for <code>TestStatisticsImplementation</code>.
30   *
31   * @author Philip Aston
32   * @see StatisticsSet
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  }