Commit | Line | Data |
---|---|---|
90ed5958 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2014 Ericsson |
90ed5958 AM |
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 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.ui.tests.statistics; |
255224d9 | 14 | |
90ed5958 | 15 | import static org.junit.Assert.assertEquals; |
255224d9 | 16 | |
2bdf0193 | 17 | import org.eclipse.tracecompass.tmf.ui.viewers.statistics.model.TmfStatisticsValues; |
90ed5958 | 18 | import org.junit.Test; |
255224d9 MD |
19 | |
20 | /** | |
21 | * TmfStatistics Test Cases. | |
22 | */ | |
90ed5958 | 23 | public class TmfStatisticsTest { |
255224d9 | 24 | |
90ed5958 | 25 | private TmfStatisticsValues stats = new TmfStatisticsValues(); |
255224d9 MD |
26 | |
27 | /** | |
28 | * Test the initial state of the counters | |
29 | */ | |
90ed5958 | 30 | @Test |
255224d9 MD |
31 | public void testInitialState() { |
32 | assertEquals(0, stats.getTotal()); | |
33 | assertEquals(0, stats.getPartial()); | |
34 | } | |
35 | ||
255224d9 MD |
36 | /** |
37 | * Test incrementing the total counter by an amount | |
38 | */ | |
90ed5958 | 39 | @Test |
89c06060 AM |
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()); | |
255224d9 MD |
49 | // Checks if the partial counter was affected |
50 | assertEquals(0, stats.getPartial()); | |
255224d9 | 51 | |
89c06060 AM |
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()); | |
255224d9 MD |
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 | */ | |
90ed5958 | 66 | @Test |
255224d9 | 67 | public void testResetTotal() { |
89c06060 | 68 | stats.setValue(true, 123); |
255224d9 MD |
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()); | |
255224d9 MD |
77 | } |
78 | ||
79 | /** | |
80 | * Test of the reset for the partial counter | |
81 | */ | |
90ed5958 | 82 | @Test |
255224d9 | 83 | public void testResetPartial() { |
89c06060 | 84 | stats.setValue(false, 456); |
255224d9 MD |
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()); | |
255224d9 MD |
93 | } |
94 | } |