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 MemMeter.
37 *
38 * @author Sebastian Graf, University of Konstanz
39 */
40 public final class MemMeterTest {
41
42 /**
43 * Constant for epsilon for testCases. Memory can change...
44 */
45 private static final double EPSILON = 16384;
46
47 /**
48 * Byte meter variable.
49 */
50 private transient MemMeter byteMeter;
51
52 /**
53 * KibiByte meter variable.
54 */
55 private transient MemMeter kibiByteMeter;
56
57 /**
58 * MebiByte meter variable.
59 */
60 private transient MemMeter mebiByteMeter;
61
62 /**
63 * Simple setUp.
64 */
65 @Before
66 public void setUp() {
67 byteMeter = new MemMeter(Memory.Byte);
68 kibiByteMeter = new MemMeter(Memory.KibiByte);
69 mebiByteMeter = new MemMeter(Memory.Mebibyte);
70 }
71
72 /**
73 * Test method for {@link org.perfidix.meter.MemMeter#getValue()}.
74 */
75 @Test
76 public void testGetValue() {
77 final double dataB1 = byteMeter.getValue();
78 final double dataKB1 = kibiByteMeter.getValue();
79 final double dataMB1 = mebiByteMeter.getValue();
80
81 assertTrue("Data check for byte", dataB1 > EPSILON / Memory.Byte.getNumberOfBytes());
82 assertTrue("Data check for KibiByte", dataKB1 > EPSILON / Memory.KibiByte.getNumberOfBytes());
83 assertTrue("Data check for MebiByte", dataMB1 > EPSILON / Memory.Mebibyte.getNumberOfBytes());
84 }
85
86 /**
87 * Test method for {@link org.perfidix.meter.MemMeter#getUnit()}.
88 */
89 @Test
90 public void testGetUnit() {
91 assertEquals("Data check for unit for byte", Memory.Byte.getUnit(), byteMeter.getUnit());
92 assertEquals("Data check for unit for kibiByte", Memory.KibiByte.getUnit(), kibiByteMeter.getUnit());
93 assertEquals("Data check for unit for mebiByte", Memory.Mebibyte.getUnit(), mebiByteMeter.getUnit());
94 }
95
96 /**
97 * Test method for {@link org.perfidix.meter.MemMeter#getUnitDescription()}.
98 */
99 @Test
100 public void testGetDescription() {
101 assertEquals("Data check for describtion for byte", Memory.Byte.getUnitDescription(), byteMeter
102 .getUnitDescription());
103 assertEquals("Data check for describtion for kibiByte", Memory.KibiByte.getUnitDescription(),
104 kibiByteMeter.getUnitDescription());
105 assertEquals("Data check for describtion for mebiByte", Memory.Mebibyte.getUnitDescription(),
106 mebiByteMeter.getUnitDescription());
107
108 }
109 }