Sfoglia il codice sorgente

Add unit test for RollingList

git-svn-id: http://svn.dmdirc.com/trunk@4418 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 anni fa
parent
commit
366b474e7a
1 ha cambiato i file con 120 aggiunte e 0 eliminazioni
  1. 120
    0
      test/com/dmdirc/util/RollingListTest.java

+ 120
- 0
test/com/dmdirc/util/RollingListTest.java Vedi File

@@ -0,0 +1,120 @@
1
+/*
2
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util;
24
+
25
+import org.junit.Test;
26
+import static org.junit.Assert.*;
27
+
28
+public class RollingListTest extends junit.framework.TestCase {
29
+
30
+    @Test
31
+    public void testIsEmpty() {
32
+        final RollingList<String> rl = new RollingList<String>(1);
33
+        assertTrue(rl.isEmpty());
34
+        assertTrue(rl.getList().isEmpty());
35
+        
36
+        rl.add("Foo");
37
+        assertFalse(rl.isEmpty());
38
+        assertFalse(rl.getList().isEmpty());
39
+    }
40
+    
41
+    @Test
42
+    public void testRolling() {
43
+        final RollingList<String> rl = new RollingList<String>(1);
44
+        
45
+        rl.add("Foo");
46
+        rl.add("Bar");
47
+        rl.add("Baz");
48
+
49
+        assertEquals("Baz", rl.get(0));
50
+        assertEquals(1, rl.getList().size());
51
+        assertFalse(rl.contains("Bar"));
52
+    }
53
+    
54
+    @Test
55
+    public void testClear() {
56
+        final RollingList<String> rl = new RollingList<String>(3);
57
+        
58
+        rl.add("Foo");
59
+        rl.add("Bar");
60
+        rl.add("Baz");
61
+        rl.clear();
62
+        
63
+        assertTrue(rl.isEmpty());
64
+        assertTrue(rl.getList().isEmpty());
65
+    }
66
+    
67
+    @Test
68
+    public void testPositions() {
69
+        final RollingList<String> rl = new RollingList<String>(3);
70
+        
71
+        rl.add("Foo");
72
+        rl.add("Bar");
73
+        rl.add("Baz");
74
+        
75
+        assertEquals(0, rl.getPosition());
76
+        
77
+        rl.seekToEnd();
78
+        assertEquals(3, rl.getPosition());
79
+        
80
+        rl.seekToStart();
81
+        assertEquals(0, rl.getPosition());
82
+    }
83
+    
84
+    @Test
85
+    public void testPrevNext() {
86
+        final RollingList<String> rl = new RollingList<String>(3);
87
+        
88
+        rl.add("Foo");
89
+        rl.add("Bar");
90
+        rl.add("Baz");
91
+        
92
+        assertEquals("Bar", rl.getNext());
93
+        assertEquals("Baz", rl.getNext());
94
+        assertFalse(rl.hasNext());
95
+        assertTrue(rl.hasPrevious());
96
+        
97
+        assertEquals("Bar", rl.getPrevious());
98
+        assertEquals("Foo", rl.getPrevious());
99
+        assertFalse(rl.hasPrevious());
100
+        assertTrue(rl.hasNext());
101
+    }
102
+    
103
+    @Test
104
+    public void testEmpty() {
105
+        final RollingList<String> rl = new RollingList<String>(1, "Meep");
106
+        rl.add("Foo");
107
+        
108
+        assertEquals("Meep", rl.getNext());
109
+        assertFalse(rl.hasNext());
110
+        
111
+        rl.add("Bar");
112
+        
113
+        // The position moves when adding
114
+        assertTrue(rl.hasNext());
115
+        assertFalse(rl.hasPrevious());
116
+        assertEquals("Meep", rl.getNext());
117
+        assertEquals("Bar", rl.getPrevious());
118
+    }
119
+
120
+}

Loading…
Annulla
Salva