View Javadoc
1   package org.djutils.stats.summarizers;
2   
3   import static org.junit.Assert.assertEquals;
4   
5   import org.junit.Test;
6   
7   /**
8    * Test the Counter class.
9    * <p>
10   * Copyright (c) 2002-2022 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
11   * for project information <a href="https://simulation.tudelft.nl/" target="_blank"> https://simulation.tudelft.nl</a>. The DSOL
12   * project is distributed under a three-clause BSD-style license, which can be found at
13   * <a href="https://simulation.tudelft.nl/dsol/3.0/license.html" target="_blank">
14   * https://simulation.tudelft.nl/dsol/3.0/license.html</a>.
15   * <br>
16   * @author <a href="https://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
17   */
18  public class CounterTest
19  {
20      /** Test the counter. */
21      @Test
22      public void testCounter()
23      {
24          String description = "counter description";
25          Counter counter = new Counter(description);
26          assertEquals(description, counter.toString());
27          assertEquals(description, counter.getDescription());
28  
29          assertEquals(0L, counter.getN());
30          assertEquals(0L, counter.getCount());
31  
32          counter.register(2);
33          assertEquals(1L, counter.getN());
34          assertEquals(2L, counter.getCount());
35  
36          counter.initialize();
37          assertEquals(0L, counter.getN());
38          assertEquals(0L, counter.getCount());
39  
40          long value = 0;
41          for (int i = 0; i < 100; i++)
42          {
43              counter.register(2 * i);
44              value += 2 * i;
45          }
46          assertEquals(100, counter.getN());
47          assertEquals(value, counter.getCount());
48      }
49  }