tmf: Updates statistics test cases
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / statistics / TmfStatisticsTest.java
CommitLineData
255224d9
MD
1package org.eclipse.linuxtools.tmf.ui.tests.statistics;
2
3import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatistics;
4
5import junit.framework.TestCase;
6
7/**
8 * TmfStatistics Test Cases.
9 */
10public class TmfStatisticsTest extends TestCase {
11
12 // ------------------------------------------------------------------------
13 // Fields
14 // ------------------------------------------------------------------------
15
16 TmfStatistics stats = new TmfStatistics();
17
18 // ------------------------------------------------------------------------
19 // Checks initial state
20 // ------------------------------------------------------------------------
21
22 /**
23 * Test the initial state of the counters
24 */
25 public void testInitialState() {
26 assertEquals(0, stats.getTotal());
27 assertEquals(0, stats.getPartial());
28 }
29
30 // ------------------------------------------------------------------------
31 // Increment Total no parameter
32 // ------------------------------------------------------------------------
33
34 /**
35 * Test incrementing the total counter
36 */
37 public void testIncrementTotal() {
38 for (int i = 1; i < 10; ++i) {
39 stats.incrementTotal();
40 assertEquals(i, stats.getTotal());
41 }
42 // Checks if the partial counter was affected
43 assertEquals(0, stats.getPartial());
44 }
45
46 /**
47 * Test incrementing the total counter by an amount
48 */
49 public void testIncrementTotal1Arg() {
50 int i = 1, expected = 0;
51 while (expected < 100) {
52 expected += i;
53 stats.incrementTotal(i);
54 assertEquals(expected, stats.getTotal());
55 i += i;
56 }
57 // Increment by a negative number do nothing
58 stats.incrementTotal(-10);
59 assertEquals(expected, stats.getTotal());
60
61 // Checks if the partial counter was affected
62 assertEquals(0, stats.getPartial());
63 }
64
65 /**
66 * Test incrementing the partial counter
67 */
68 public void testIncrementPartial() {
69 for (int i = 1; i < 10; ++i) {
70 stats.incrementPartial();
71 assertEquals(i, stats.getPartial());
72 }
73 // Checks if the total counter was affected
74 assertEquals(0, stats.getTotal());
75 }
76
77 /**
78 * Test incrementing the partial counter by a certain amount
79 */
80 public void testIncrementPartial1Arg() {
81 int i = 1, expected = 0;
82 while (expected < 100) {
83 expected += i;
84 stats.incrementPartial(i);
85 assertEquals(expected, stats.getPartial());
86 i += i;
87 }
88 // Increment by a negative number. It should do nothing.
89 stats.incrementPartial(-10);
90 assertEquals(expected, stats.getPartial());
91
92 // Checks if the total counter was affected
93 assertEquals(0, stats.getTotal());
94 }
95
96 /**
97 * Test of the reset for the total counter
98 */
99 public void testResetTotal() {
100 stats.incrementTotal(123);
101 assertEquals(123, stats.getTotal());
102
103 stats.resetTotalCount();
104 assertEquals(0, stats.getTotal());
105
106 // test when already at 0
107 stats.resetTotalCount();
108 assertEquals(0, stats.getTotal());
109
110 // The counters should still be in a usable state
111 stats.incrementPartial();
112 stats.incrementPartial(3);
113 assertEquals(4, stats.getPartial());
114
115 stats.incrementTotal();
116 stats.incrementTotal(2);
117 assertEquals(3, stats.getTotal());
118 }
119
120 /**
121 * Test of the reset for the partial counter
122 */
123 public void testResetPartial() {
124 stats.incrementPartial(456);
125 assertEquals(456, stats.getPartial());
126
127 stats.resetPartialCount();
128 assertEquals(0, stats.getPartial());
129
130 // test when already at 0
131 stats.resetPartialCount();
132 assertEquals(0, stats.getPartial());
133
134 // The counters should still be in a usable state
135 stats.incrementPartial();
136 stats.incrementPartial(2);
137 assertEquals(3, stats.getPartial());
138
139 stats.incrementTotal();
140 stats.incrementTotal(3);
141 assertEquals(4, stats.getTotal());
142 }
143}
This page took 0.091109 seconds and 5 git commands to generate.