Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
203   407   47   9.67
0   314   0.23   21
21     2.24  
1    
 
  DefaultElementListTest       Line # 28 203 47 87.5% 0.875
 
  (17)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.kernel.se.dto.list;
17   
18    import java.util.Vector;
19   
20    import org.qedeq.base.test.QedeqTestCase;
21    import org.qedeq.kernel.se.base.list.Element;
22   
23    /**
24    * Test class.
25    *
26    * @author Michael Meyling
27    */
 
28    public class DefaultElementListTest extends QedeqTestCase {
29   
30    private DefaultElementList empty;
31   
32    private DefaultElementList one;
33   
34    private DefaultElementList two;
35   
36    private DefaultElementList three;
37   
38    private DefaultElementList withNone;
39   
40    private DefaultElementList withOne;
41   
42    private DefaultElementList withTwo;
43   
44    private DefaultElementList withTwo2;
45   
 
46  0 toggle public DefaultElementListTest(){
47  0 super();
48    }
49   
 
50  17 toggle public DefaultElementListTest(final String name){
51  17 super(name);
52    }
53   
 
54  17 toggle protected void setUp() throws Exception {
55  17 super.setUp();
56  17 empty = new DefaultElementList("");
57  17 one = new DefaultElementList("one");
58  17 two = new DefaultElementList("two");
59  17 three = new DefaultElementList("two");
60  17 withNone = new DefaultElementList("", new Element[] {});
61  17 withOne = new DefaultElementList("one", new Element[] { new DefaultAtom("atom")});
62  17 withTwo = new DefaultElementList("two", new Element[] { new DefaultAtom("atom"),
63    new DefaultElementList("deep")});
64  17 withTwo2 = new DefaultElementList("two");
65  17 withTwo2.add(new DefaultAtom("atom"));
66  17 withTwo2.add(new DefaultElementList("deep"));
67    }
68   
 
69  17 toggle protected void tearDown() throws Exception {
70  17 empty = null;
71  17 one = null;
72  17 two = null;
73  17 three = null;
74  17 super.tearDown();
75    }
76   
77   
78    /**
79    * Test constructor.
80    */
 
81  1 toggle public void testConstructor() throws Exception {
82  1 try {
83  1 new DefaultElementList(null);
84  0 fail("Exception expected");
85    } catch (Exception e) {
86    // ok
87    }
88  1 try {
89  1 new DefaultElementList(null, (Element[]) null);
90  0 fail("Exception expected");
91    } catch (Exception e) {
92    // ok
93    }
94  1 try {
95  1 new DefaultElementList("operator", (Element[]) null);
96  0 fail("Exception expected");
97    } catch (Exception e) {
98    // ok
99    }
100  1 assertFalse(new DefaultElementList("one").equals(new DefaultAtom("on")));
101    }
102   
 
103  1 toggle public void testGetElement() {
104  1 try {
105  1 empty.getElement(0);
106  0 fail("Exception expected");
107    } catch (Exception e) {
108    // ok
109    }
110  1 try {
111  1 one.getElement(0);
112  0 fail("Exception expected");
113    } catch (Exception e) {
114    // ok
115    }
116  1 try {
117  1 one.getElement(-1);
118  0 fail("Exception expected");
119    } catch (Exception e) {
120    // ok
121    }
122  1 assertEquals(new DefaultAtom("atom"), withTwo.getElement(0));
123  1 assertEquals(new DefaultElementList("deep"), withTwo.getElement(1));
124  1 try {
125  1 withTwo.getElement(2);
126  0 fail("Exception expected");
127    } catch (Exception e) {
128    // ok
129    }
130  1 withTwo.remove(0);
131  1 assertEquals(new DefaultElementList("deep"), withTwo.getElement(0));
132  1 try {
133  1 withTwo.getElement(1);
134  0 fail("Exception expected");
135    } catch (Exception e) {
136    // ok
137    }
138    }
139   
 
140  1 toggle public void testSize() {
141  1 assertEquals(0, empty.size());
142  1 assertEquals(0, one.size());
143  1 assertEquals(1, withOne.size());
144  1 assertEquals(2, withTwo.size());
145    }
146   
 
147  1 toggle public void testGetElements() {
148  1 assertEquals(new Vector() {}, empty.getElements());
149  1 Vector result = new Vector();
150  1 result.add(new DefaultAtom("atom"));
151  1 result.add(new DefaultElementList("deep"));
152  1 assertEquals(result, withTwo.getElements());
153    }
154   
 
155  1 toggle public void testCopy() {
156  1 Element copy = withTwo.copy();
157  1 assertEquals(withTwo, copy);
158  1 assertFalse(withTwo == copy);
159  1 copy = empty.copy();
160  1 assertEquals(empty, copy);
161  1 assertFalse(empty == copy);
162    }
163   
 
164  1 toggle public void testAddAndSizeAndInsertAndRemove() {
165  1 try {
166  1 empty.add(null);
167  0 fail("Exception expected");
168    } catch (Exception e) {
169    // ok
170    }
171  1 try {
172  1 empty.remove(0);
173  0 fail("Exception expected");
174    } catch (Exception e) {
175    // ok
176    }
177  1 try {
178  1 withTwo.remove(-1);
179  0 fail("Exception expected");
180    } catch (Exception e) {
181    // ok
182    }
183  1 try {
184  1 withTwo.insert(0, null);
185  0 fail("Exception expected");
186    } catch (Exception e) {
187    // ok
188    }
189  1 assertEquals(0, one.size());
190  1 assertEquals(2, withTwo.size());
191  1 withTwo.add(new DefaultAtom("atom"));
192  1 assertEquals(3, withTwo.size());
193  1 assertFalse(withTwo.equals(withTwo2));
194  1 withTwo.remove(0);
195  1 assertFalse(withTwo.equals(withTwo2));
196  1 withTwo.remove(0);
197  1 assertFalse(withTwo.equals(withOne));
198  1 try {
199  1 withTwo.remove(1);
200  0 fail("Exception expected");
201    } catch (Exception e) {
202    // ok
203    }
204  1 assertFalse(withTwo.equals(withOne));
205  1 withTwo.remove(0);
206  1 assertEquals(new DefaultElementList("two"), withTwo);
207  1 withTwo.insert(0, new DefaultAtom("atom"));
208  1 withTwo.insert(1, new DefaultElementList("deep"));
209  1 assertEquals(withTwo2, withTwo);
210  1 withTwo.insert(2, new DefaultAtom("multi"));
211  1 withTwo.remove(2);
212  1 assertEquals(withTwo2, withTwo);
213    }
214   
 
215  1 toggle public void testGetList() {
216  1 assertEquals(empty, empty.getList());
217  1 assertEquals(one, one.getList());
218  1 assertEquals(two, two.getList());
219  1 assertEquals(two, three.getList());
220  1 assertEquals(withOne, withOne.getList());
221    }
222   
 
223  1 toggle public void testGetAtom() {
224  1 try {
225  1 empty.getAtom();
226  0 fail("Exception expected");
227    } catch (Exception e) {
228    // ok
229    }
230  1 try {
231  1 two.getAtom();
232  0 fail("Exception expected");
233    } catch (Exception e) {
234    // ok
235    }
236    }
237   
 
238  1 toggle public void testIsList() {
239  1 assertTrue(empty.isList());
240  1 assertTrue(one.isList());
241  1 assertTrue(two.isList());
242    }
243   
 
244  1 toggle public void testIsAtom() {
245  1 assertFalse(empty.isAtom());
246  1 assertFalse(one.isAtom());
247  1 assertFalse(two.isAtom());
248    }
249   
 
250  1 toggle public void testReplace1() {
251  1 assertEquals(empty, empty.replace(null, null));
252  1 assertEquals(empty, empty.replace(one, null));
253  1 assertEquals(empty, empty.replace(one, two));
254  1 assertEquals(two, one.replace(one, two));
255  1 assertEquals(one, one.replace(two, one));
256  1 assertEquals(one, one.replace(new DefaultElementList("neu", new Element[]{ one}), two));
257  1 Element list = new DefaultElementList("two", new Element[] { new DefaultAtom("atom"),
258    new DefaultElementList("deep")});
259  1 assertEquals(list, one.replace(one, list));
260  1 assertEquals("one ( \"ATOM\")", withOne.replace(new DefaultAtom("atom"),
261    new DefaultAtom("ATOM")).toString());
262    }
263   
 
264  1 toggle public void testReplace2() {
265  1 try {
266  1 empty.replace(0, null);
267  0 fail("Exception expected");
268    } catch (Exception e) {
269    // ok
270    }
271  1 try {
272  1 empty.replace(0, new DefaultAtom("one"));
273  0 fail("Exception expected");
274    } catch (Exception e) {
275    // ok
276    }
277  1 try {
278  1 withOne.replace(-1, new DefaultAtom("one"));
279  0 fail("Exception expected");
280    } catch (Exception e) {
281    // ok
282    }
283  1 try {
284  1 empty.replace(0, new DefaultAtom("one"));
285  0 fail("Exception expected");
286    } catch (Exception e) {
287    // ok
288    }
289  1 try {
290  1 empty.replace(1, new DefaultAtom("one"));
291  0 fail("Exception expected");
292    } catch (Exception e) {
293    // ok
294    }
295  1 try {
296  1 withOne.replace(1, new DefaultAtom("one"));
297  0 fail("Exception expected");
298    } catch (Exception e) {
299    // ok
300    }
301  1 try {
302  1 withTwo.replace(2, new DefaultAtom("one"));
303  0 fail("Exception expected");
304    } catch (Exception e) {
305    // ok
306    }
307  1 withOne.replace(0, new DefaultAtom("expected"));
308  1 assertEquals(new DefaultAtom("expected"), withOne.getElement(0));
309    }
310   
311   
 
312  1 toggle public void testInsert() {
313  1 try {
314  1 empty.insert(1, new DefaultAtom("one"));
315  0 fail("Exception expected");
316    } catch (Exception e) {
317    // ok
318    }
319  1 try {
320  1 empty.insert(-1, new DefaultAtom("one"));
321  0 fail("Exception expected");
322    } catch (Exception e) {
323    // ok
324    }
325  1 empty.insert(0, new DefaultAtom("one"));
326  1 assertEquals(new DefaultElementList("", new Element[] {new DefaultAtom("one") }), empty);
327  1 try {
328  1 withOne.insert(2, new DefaultAtom("one"));
329  0 fail("Exception expected");
330    } catch (Exception e) {
331    // ok
332    }
333  1 try {
334  1 withTwo.insert(3, new DefaultAtom("one"));
335  0 fail("Exception expected");
336    } catch (Exception e) {
337    // ok
338    }
339    }
340   
 
341  1 toggle public void testGetOperator() throws Exception {
342  1 assertEquals("", empty.getOperator());
343  1 assertEquals("one", one.getOperator());
344  1 assertEquals("two", two.getOperator());
345  1 assertEquals("two", three.getOperator());
346  1 assertEquals("", withNone.getOperator());
347  1 assertEquals("one", withOne.getOperator());
348  1 assertEquals("two", withTwo.getOperator());
349  1 assertEquals("two", withTwo2.getOperator());
350    }
351   
352    /**
353    * Test toString.
354    */
 
355  1 toggle public void testToString() throws Exception {
356  1 assertEquals("", empty.toString());
357  1 assertEquals("one", one.toString());
358  1 assertEquals("two", two.toString());
359  1 assertEquals("two", three.toString());
360  1 assertEquals("", withNone.toString());
361  1 assertEquals("one ( \"atom\")", withOne.toString());
362  1 assertEquals("two ( \"atom\", deep)", withTwo.toString());
363  1 assertEquals("two ( \"atom\", deep)", withTwo2.toString());
364    }
365   
366    /**
367    * Test hashCode.
368    */
 
369  1 toggle public void testHashCode() throws Exception {
370  1 assertTrue(0 == empty.hashCode());
371  1 assertFalse(empty.hashCode() == one.hashCode());
372  1 assertFalse(two.hashCode() == one.hashCode());
373  1 assertTrue(two.hashCode() == three.hashCode());
374  1 assertFalse(withNone.hashCode() == one.hashCode());
375  1 assertTrue(withNone.hashCode() == empty.hashCode());
376  1 assertFalse(withOne.hashCode() == withTwo.hashCode());
377  1 assertFalse(withOne.hashCode() == withTwo2.hashCode());
378  1 assertTrue(withTwo.hashCode() == withTwo2.hashCode());
379    }
380   
381    /**
382    * Test equals.
383    */
 
384  1 toggle public void testEquals() throws Exception {
385  1 assertFalse(empty.equals(null));
386  1 assertFalse(empty.equals(one));
387  1 assertFalse(empty.equals(two));
388  1 assertFalse(empty.equals(three));
389  1 assertFalse(one.equals(null));
390  1 assertTrue(one.equals(one));
391  1 assertFalse(one.equals(two));
392  1 assertFalse(one.equals(three));
393  1 assertFalse(two.equals(null));
394  1 assertFalse(two.equals(one));
395  1 assertTrue(two.equals(two));
396  1 assertTrue(two.equals(three));
397  1 assertFalse(three.equals(null));
398  1 assertFalse(three.equals(one));
399  1 assertTrue(three.equals(two));
400  1 assertTrue(three.equals(three));
401  1 assertTrue(withTwo.equals(withTwo2));
402  1 assertTrue(empty.equals(withNone));
403  1 assertFalse(empty.equals(""));
404  1 assertFalse(withTwo.equals(withOne));
405    }
406   
407    }