1 /**
2 * Copyright (c) 2012, University of Konstanz, Distributed Systems Group
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the University of Konstanz nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 package org.perfidix.meter;
28
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertTrue;
31
32 import org.junit.Before;
33 import org.junit.Test;
34
35 /**
36 * Testcase for TimeMeter.
37 *
38 * @author Sebastian Graf, University of Konstanz
39 */
40 public final class TimeMeterTest {
41
42 /**
43 * Instance for nano seconds.
44 */
45 private transient TimeMeter nano;
46
47 /**
48 * Instance for milli seconds.
49 */
50 private transient TimeMeter milli;
51
52 /**
53 * Instance for seconds.
54 */
55 private transient TimeMeter second;
56
57 /**
58 * Instance for minutes.
59 */
60 private transient TimeMeter minute;
61
62 /**
63 * Simple setUp.
64 */
65 @Before
66 public void setUp() {
67 nano = new TimeMeter(Time.NanoSeconds);
68 milli = new TimeMeter(Time.MilliSeconds);
69 second = new TimeMeter(Time.Seconds);
70 minute = new TimeMeter(Time.Minutes);
71 }
72
73 /**
74 * Test method for {@link org.perfidix.meter.TimeMeter#getValue()}.
75 */
76 @Test
77 public void testGetValue() {
78 final double dataNano1 = nano.getValue();
79 final double dataMilli1 = milli.getValue();
80 final double dataSecond1 = second.getValue();
81 final double dataMinute1 = minute.getValue();
82
83 final double dataNano2 = nano.getValue() - dataNano1;
84 final double dataMilli2 = milli.getValue() - dataMilli1;
85 final double dataSecond2 = second.getValue() - dataSecond1;
86 final double dataMinute2 = minute.getValue() - dataMinute1;
87
88 assertTrue("nanovalue has to be larger than 0", dataNano2 > 0);
89 assertTrue("millivalue has to be larger than 0", dataMilli2 > 0);
90 assertTrue("secondvalue has to be larger than 0", dataSecond2 > 0);
91 assertTrue("minutevalue has to be larger than 0", dataMinute2 > 0);
92 }
93
94 /**
95 * Test method for {@link org.perfidix.meter.TimeMeter#getUnit()}.
96 */
97 @Test
98 public void testGetUnit() {
99 assertEquals("Unit for nanos", Time.NanoSeconds.getUnit(), nano.getUnit());
100 assertEquals("Unit for millis", Time.MilliSeconds.getUnit(), milli.getUnit());
101 assertEquals("Unit for seconds", Time.Seconds.getUnit(), second.getUnit());
102 assertEquals("Unit for minutes", Time.Minutes.getUnit(), minute.getUnit());
103 }
104
105 /**
106 * Test method for {@link org.perfidix.meter.TimeMeter#getUnitDescription()} .
107 */
108 @Test
109 public void testGetDescription() {
110 assertEquals("Description for nanos", Time.NanoSeconds.getUnitDescription(), nano
111 .getUnitDescription());
112 assertEquals("Description for millis", Time.MilliSeconds.getUnitDescription(), milli
113 .getUnitDescription());
114 assertEquals("Description for seconds", Time.Seconds.getUnitDescription(), second
115 .getUnitDescription());
116 assertEquals("Description for minutes", Time.Minutes.getUnitDescription(), minute
117 .getUnitDescription());
118
119 }
120
121 }