Commit | Line | Data |
---|---|---|
255224d9 MD |
1 | package org.eclipse.linuxtools.tmf.ui.tests.statistics; |
2 | ||
5aaa97db | 3 | import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsValues; |
255224d9 MD |
4 | |
5 | import junit.framework.TestCase; | |
6 | ||
7 | /** | |
8 | * TmfStatistics Test Cases. | |
9 | */ | |
10 | public class TmfStatisticsTest extends TestCase { | |
11 | ||
12 | // ------------------------------------------------------------------------ | |
13 | // Fields | |
14 | // ------------------------------------------------------------------------ | |
15 | ||
5aaa97db | 16 | TmfStatisticsValues stats = new TmfStatisticsValues(); |
255224d9 MD |
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 | ||
255224d9 MD |
34 | /** |
35 | * Test incrementing the total counter by an amount | |
36 | */ | |
89c06060 AM |
37 | public void testSetValue() { |
38 | final int i = 100; | |
39 | ||
40 | /* Set the Global counter */ | |
41 | stats.setValue(true, i); | |
42 | assertEquals(i, stats.getTotal()); | |
43 | // Try to assign a negative number. Should do nothing. | |
44 | stats.setValue(true, -10); | |
45 | assertEquals(i, stats.getTotal()); | |
255224d9 MD |
46 | // Checks if the partial counter was affected |
47 | assertEquals(0, stats.getPartial()); | |
255224d9 | 48 | |
89c06060 AM |
49 | /* Set the time range counter */ |
50 | stats.resetTotalCount(); | |
51 | stats.setValue(false, i); | |
52 | assertEquals(i, stats.getPartial()); | |
53 | // Try to assign a negative number. Should do nothing. | |
54 | stats.setValue(false, -10); | |
55 | assertEquals(i, stats.getPartial()); | |
255224d9 MD |
56 | // Checks if the total counter was affected |
57 | assertEquals(0, stats.getTotal()); | |
58 | } | |
59 | ||
60 | /** | |
61 | * Test of the reset for the total counter | |
62 | */ | |
63 | public void testResetTotal() { | |
89c06060 | 64 | stats.setValue(true, 123); |
255224d9 MD |
65 | assertEquals(123, stats.getTotal()); |
66 | ||
67 | stats.resetTotalCount(); | |
68 | assertEquals(0, stats.getTotal()); | |
69 | ||
70 | // test when already at 0 | |
71 | stats.resetTotalCount(); | |
72 | assertEquals(0, stats.getTotal()); | |
255224d9 MD |
73 | } |
74 | ||
75 | /** | |
76 | * Test of the reset for the partial counter | |
77 | */ | |
78 | public void testResetPartial() { | |
89c06060 | 79 | stats.setValue(false, 456); |
255224d9 MD |
80 | assertEquals(456, stats.getPartial()); |
81 | ||
82 | stats.resetPartialCount(); | |
83 | assertEquals(0, stats.getPartial()); | |
84 | ||
85 | // test when already at 0 | |
86 | stats.resetPartialCount(); | |
87 | assertEquals(0, stats.getPartial()); | |
255224d9 MD |
88 | } |
89 | } |