tmf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.tests / src / org / eclipse / tracecompass / tmf / ui / tests / statistics / TmfStatisticsTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Alexandre Montplaisir - Port to JUnit4
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.ui.tests.statistics;
14
15 import static org.junit.Assert.assertEquals;
16
17 import org.eclipse.tracecompass.tmf.ui.viewers.statistics.model.TmfStatisticsValues;
18 import org.junit.Test;
19
20 /**
21 * TmfStatistics Test Cases.
22 */
23 public class TmfStatisticsTest {
24
25 private TmfStatisticsValues stats = new TmfStatisticsValues();
26
27 /**
28 * Test the initial state of the counters
29 */
30 @Test
31 public void testInitialState() {
32 assertEquals(0, stats.getTotal());
33 assertEquals(0, stats.getPartial());
34 }
35
36 /**
37 * Test incrementing the total counter by an amount
38 */
39 @Test
40 public void testSetValue() {
41 final int i = 100;
42
43 /* Set the Global counter */
44 stats.setValue(true, i);
45 assertEquals(i, stats.getTotal());
46 // Try to assign a negative number. Should do nothing.
47 stats.setValue(true, -10);
48 assertEquals(i, stats.getTotal());
49 // Checks if the partial counter was affected
50 assertEquals(0, stats.getPartial());
51
52 /* Set the time range counter */
53 stats.resetTotalCount();
54 stats.setValue(false, i);
55 assertEquals(i, stats.getPartial());
56 // Try to assign a negative number. Should do nothing.
57 stats.setValue(false, -10);
58 assertEquals(i, stats.getPartial());
59 // Checks if the total counter was affected
60 assertEquals(0, stats.getTotal());
61 }
62
63 /**
64 * Test of the reset for the total counter
65 */
66 @Test
67 public void testResetTotal() {
68 stats.setValue(true, 123);
69 assertEquals(123, stats.getTotal());
70
71 stats.resetTotalCount();
72 assertEquals(0, stats.getTotal());
73
74 // test when already at 0
75 stats.resetTotalCount();
76 assertEquals(0, stats.getTotal());
77 }
78
79 /**
80 * Test of the reset for the partial counter
81 */
82 @Test
83 public void testResetPartial() {
84 stats.setValue(false, 456);
85 assertEquals(456, stats.getPartial());
86
87 stats.resetPartialCount();
88 assertEquals(0, stats.getPartial());
89
90 // test when already at 0
91 stats.resetPartialCount();
92 assertEquals(0, stats.getPartial());
93 }
94 }
This page took 0.032889 seconds and 5 git commands to generate.