Clover Coverage Report
Coverage timestamp: Fri Feb 14 2014 07:28:57 UTC
192   537   84   2.67
2   400   0.44   72
72     1.17  
1    
 
  QedeqBoSetTest       Line # 49 192 84 62% 0.62030077
 
  (13)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2014, 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.bo.common;
17   
18    import java.util.Iterator;
19   
20    import org.qedeq.base.test.QedeqTestCase;
21    import org.qedeq.base.utility.EqualsUtility;
22    import org.qedeq.kernel.bo.common.Element2Latex;
23    import org.qedeq.kernel.bo.common.Element2Utf8;
24    import org.qedeq.kernel.bo.common.ModuleReferenceList;
25    import org.qedeq.kernel.bo.module.InternalKernelServices;
26    import org.qedeq.kernel.bo.module.KernelModuleReferenceList;
27    import org.qedeq.kernel.bo.module.KernelQedeqBo;
28    import org.qedeq.kernel.bo.module.ModuleConstantsExistenceChecker;
29    import org.qedeq.kernel.bo.module.ModuleLabels;
30    import org.qedeq.kernel.se.base.module.Qedeq;
31    import org.qedeq.kernel.se.common.ModuleAddress;
32    import org.qedeq.kernel.se.common.ModuleDataException;
33    import org.qedeq.kernel.se.common.ModuleService;
34    import org.qedeq.kernel.se.common.Service;
35    import org.qedeq.kernel.se.common.SourceFileException;
36    import org.qedeq.kernel.se.common.SourceFileExceptionList;
37    import org.qedeq.kernel.se.state.AbstractState;
38    import org.qedeq.kernel.se.state.DependencyState;
39    import org.qedeq.kernel.se.state.FormallyProvedState;
40    import org.qedeq.kernel.se.state.LoadingImportsState;
41    import org.qedeq.kernel.se.state.LoadingState;
42    import org.qedeq.kernel.se.state.WellFormedState;
43   
44    /**
45    * Test class.
46    *
47    * @author Michael Meyling
48    */
 
49    public class QedeqBoSetTest extends QedeqTestCase {
50   
51    private static final String URL1 = "http://www.qedeq.org/current/sample/qedeq_sample1.xml";
52   
53    private static final String URL2 = "http://www.qedeq.org/current/sample/qedeq_sample2.xml";
54   
55    private static final String URL4 = "http://www.qedeq.org/current/sample/qedeq_sample4.xml";
56   
57   
58    /** {} */
59    private QedeqBoSet empty;
60   
61    /** {"one"} */
62    private QedeqBoSet one;
63   
64    /** {"two"} */
65    private QedeqBoSet two;
66   
67    /** {"two"} */
68    private QedeqBoSet two2;
69   
70    /** {"one", "two"} */
71    private QedeqBoSet oneTwo;
72   
 
73  0 toggle public QedeqBoSetTest(){
74  0 super();
75    }
76   
 
77  13 toggle public QedeqBoSetTest(final String name){
78  13 super(name);
79    }
80   
 
81  13 toggle protected void setUp() throws Exception {
82  13 super.setUp();
83  13 initAttributes();
84    }
85   
86    /**
87    *
88    */
 
89  16 toggle private void initAttributes() {
90  16 empty = new QedeqBoSet();
91  16 one = new QedeqBoSet(new KernelQedeqBo[] {createKernelQedeqBo(URL1)});
92  16 two = new QedeqBoSet(new KernelQedeqBo[] {createKernelQedeqBo(URL2)});
93  16 two2 = new QedeqBoSet();
94  16 two2.add(createKernelQedeqBo(URL2));
95  16 oneTwo = new QedeqBoSet();
96  16 oneTwo.add(createKernelQedeqBo(URL1));
97  16 oneTwo.add(createKernelQedeqBo(URL2));
98    }
99   
 
100  13 toggle protected void tearDown() throws Exception {
101  13 empty = null;
102  13 one = null;
103  13 two = null;
104  13 two2 = null;
105  13 oneTwo = null;
106  13 super.tearDown();
107    }
108   
109   
110    /**
111    * Test constructor.
112    */
 
113  1 toggle public void testConstructor() {
114  1 try {
115  1 new QedeqBoSet((KernelQedeqBo) null);
116  0 fail("Exception expected");
117    } catch (Exception e) {
118    // ok
119    }
120  1 try {
121  1 new QedeqBoSet((QedeqBoSet) null);
122  0 fail("Exception expected");
123    } catch (Exception e) {
124    // ok
125    }
126  1 try {
127  1 new QedeqBoSet((KernelQedeqBo) null);
128  0 fail("Exception expected");
129    } catch (Exception e) {
130    // ok
131    }
132  1 assertEquals(one, new QedeqBoSet(createKernelQedeqBo(URL1)));
133  1 assertEquals(one, new QedeqBoSet(new QedeqBoSet(new QedeqBoSet(createKernelQedeqBo(
134    URL1)))));
135    }
136   
 
137  1 toggle public void testSetOperations() {
138  1 KernelQedeqBo o = createKernelQedeqBo(URL1);
139  1 KernelQedeqBo t = createKernelQedeqBo(URL2);
140  1 assertTrue(one.contains(o));
141  1 KernelQedeqBo otto = createKernelQedeqBo(URL4);
142  1 assertFalse(one.contains(otto));
143  1 one.remove(o);
144  1 assertEquals(empty, one);
145  1 one.remove(otto);
146  1 assertEquals(empty, one);
147  1 assertTrue(one.isEmpty());
148  1 assertFalse(two.isEmpty());
149  1 two.add(o);
150  1 assertEquals(two, oneTwo);
151  1 one.add(o);
152  1 assertTrue(one.contains(o));
153  1 assertFalse(one.contains(t));
154  1 one.intersection(oneTwo);
155  1 assertTrue(one.contains(o));
156  1 assertFalse(one.contains(t));
157  1 one.add(oneTwo);
158  1 assertTrue(one.contains(o));
159  1 assertTrue(one.contains(t));
160  1 assertEquals(2, one.size());
161    }
162   
 
163  1 toggle public void testSetOperations2() {
164  1 try {
165  1 one.add((KernelQedeqBo) null);
166  0 fail("Exception expected");
167    } catch (Exception e) {
168    // ok
169    }
170  1 try {
171  1 one.add((QedeqBoSet) null);
172  0 fail("Exception expected");
173    } catch (Exception e) {
174    // ok
175    }
176  1 try {
177  1 one.intersection(null);
178  0 fail("Exception expected");
179    } catch (Exception e) {
180    // ok
181    }
182    }
183   
 
184  1 toggle public void testRemoveSet() {
185  1 try {
186  1 one.remove((QedeqBoSet) null);
187  0 fail("Exception expected");
188    } catch (Exception e) {
189    // ok
190    }
191  1 assertEquals(oneTwo, oneTwo.remove(empty));
192  1 assertEquals(2, oneTwo.size());
193  1 assertEquals(one, one.remove(one));
194  1 assertEquals(0, one.size());
195  1 initAttributes();
196  1 assertEquals(oneTwo, oneTwo.remove(one));
197  1 assertEquals(new QedeqBoSet(createKernelQedeqBo(URL2)), oneTwo);
198  1 initAttributes();
199  1 assertEquals(oneTwo, oneTwo.remove(two));
200  1 assertEquals(oneTwo, new QedeqBoSet(createKernelQedeqBo(URL1)));
201  1 initAttributes();
202  1 assertEquals(2, oneTwo.size());
203  1 assertEquals(oneTwo, oneTwo.remove(createKernelQedeqBo(URL4)));
204  1 assertEquals(2, oneTwo.size());
205    }
206   
 
207  1 toggle public void testRemove() {
208  1 try {
209  1 one.remove((KernelQedeqBo) null);
210  0 fail("Exception expected");
211    } catch (Exception e) {
212    // ok
213    }
214  1 assertEquals(one, one.remove(createKernelQedeqBo(URL2)));
215  1 assertEquals(1, one.size());
216  1 assertEquals(two, two.remove(createKernelQedeqBo(URL2)));
217  1 assertEquals(empty, two);
218  1 assertEquals(0, two.size());
219  1 assertEquals(oneTwo, oneTwo.remove(createKernelQedeqBo(URL2)));
220    }
221   
 
222  1 toggle public void testAdd() {
223  1 try {
224  1 one.add((KernelQedeqBo) null);
225  0 fail("Exception expected");
226    } catch (Exception e) {
227    // ok
228    }
229  1 assertEquals(one, one.add(createKernelQedeqBo(URL2)));
230  1 assertEquals(2, one.size());
231  1 assertEquals(oneTwo, one);
232  1 assertEquals(one, one.add(createKernelQedeqBo(URL2)));
233  1 assertEquals(2, one.size());
234  1 assertEquals(oneTwo, one);
235    }
236   
 
237  1 toggle public void testAdd2() {
238  1 try {
239  1 one.add((QedeqBoSet) null);
240  0 fail("Exception expected");
241    } catch (Exception e) {
242    // ok
243    }
244  1 assertEquals(one, one.add(new QedeqBoSet(createKernelQedeqBo(URL2))));
245  1 assertEquals(2, one.size());
246  1 assertEquals(oneTwo, one);
247  1 assertEquals(one, one.add(new QedeqBoSet(createKernelQedeqBo(URL2))));
248  1 assertEquals(2, one.size());
249  1 assertEquals(oneTwo, one);
250    }
251   
 
252  1 toggle public void testContains() {
253  1 try {
254  1 one.contains(null);
255  0 fail("Exception expected");
256    } catch (Exception e) {
257    // ok
258    }
259  1 assertFalse(empty.contains(createKernelQedeqBo(URL2)));
260  1 assertFalse(one.contains(createKernelQedeqBo(URL2)));
261  1 assertTrue(one.contains(createKernelQedeqBo(URL1)));
262  1 assertTrue(oneTwo.contains(createKernelQedeqBo(URL1)));
263  1 assertTrue(oneTwo.contains(createKernelQedeqBo(URL2)));
264    }
265   
 
266  1 toggle public void testIsEmpty() {
267  1 assertTrue(empty.isEmpty());
268  1 assertFalse(oneTwo.isEmpty());
269    }
270   
 
271  1 toggle public void testIterator() {
272  1 Iterator iterator = empty.iterator();
273  1 assertFalse(iterator.hasNext());
274  1 Iterator iterator2 = one.iterator();
275  1 assertTrue(iterator2.hasNext());
276  1 assertEquals(createKernelQedeqBo(URL1), iterator2.next());
277  1 assertFalse(iterator2.hasNext());
278    }
279   
280    /**
281    * Test toString.
282    */
 
283  1 toggle public void testToString() {
284  1 assertEquals("{}", empty.toString());
285  1 assertEquals("{" + URL1 + "}", one.toString());
286  1 assertEquals("{" + URL2 + "}", two.toString());
287  1 assertEquals("{" + URL2 + "}", two2.toString());
288  1 assertEquals("{" + URL4 + "}", new QedeqBoSet(createKernelQedeqBo(URL4)).toString());
289  1 assertTrue(("{" + URL1 + ", " + URL2 + "}").equals(oneTwo.toString())
290    || ("{\"" + URL2 + ", " + URL1 + "}").equals(oneTwo.toString()));
291    }
292   
293    /**
294    * Test hashCode.
295    */
 
296  1 toggle public void testHashCode() {
297  1 assertFalse(empty.hashCode() == two2.hashCode());
298  1 assertFalse(empty.hashCode() == one.hashCode());
299  1 assertFalse(two.hashCode() == one.hashCode());
300  1 assertTrue(two.hashCode() == two2.hashCode());
301    }
302   
303    /**
304    * Test equals.
305    */
 
306  1 toggle public void testEquals() {
307  1 assertFalse(empty.equals(null));
308  1 assertFalse(empty.equals(one));
309  1 assertFalse(empty.equals(two));
310  1 assertFalse(empty.equals(two2));
311  1 assertFalse(one.equals(null));
312  1 assertTrue(one.equals(one));
313  1 assertFalse(one.equals(two));
314  1 assertFalse(one.equals(two2));
315  1 assertFalse(two.equals(null));
316  1 assertFalse(two.equals(one));
317  1 assertTrue(two.equals(two));
318  1 assertTrue(two.equals(two2));
319  1 assertFalse(two2.equals(null));
320  1 assertFalse(two2.equals(one));
321  1 assertTrue(two2.equals(two));
322  1 assertTrue(two2.equals(two2));
323  1 assertTrue(empty.equals(new QedeqBoSet()));
324    }
325   
 
326  102 toggle private KernelQedeqBo createKernelQedeqBo(final String url) {
327  102 return new KernelQedeqBo() {
 
328  6 toggle public String toString() {
329  6 return url;
330    }
331   
 
332  147 toggle public int hashCode() {
333  147 return url.hashCode();
334    }
335   
 
336  31 toggle public boolean equals(final Object obj) {
337  31 if (obj instanceof KernelQedeqBo) {
338  31 return EqualsUtility.equals(((KernelQedeqBo) obj).getUrl(),
339    this.getUrl());
340    }
341  0 return false;
342   
343    }
344   
 
345  0 toggle public boolean hasBasicFailures() {
346  0 return false;
347    }
348   
 
349  0 toggle public boolean hasErrors() {
350  0 return false;
351    }
352   
 
353  0 toggle public boolean hasWarnings() {
354  0 return false;
355    }
356   
 
357  0 toggle public ModuleAddress getModuleAddress() {
358  0 return null;
359    }
360   
 
361  0 toggle public AbstractState getLastSuccessfulState() {
362  0 return null;
363    }
364   
 
365  0 toggle public AbstractState getCurrentState() {
366  0 return null;
367    }
368   
 
369  0 toggle public Service getCurrentlyRunningService() {
370  0 return null;
371    }
372   
 
373  0 toggle public LoadingState getLoadingState() {
374  0 return null;
375    }
376   
 
377  0 toggle public int getLoadingCompleteness() {
378  0 return 0;
379    }
380   
 
381  0 toggle public LoadingImportsState getLoadingImportsState() {
382  0 return null;
383    }
384   
 
385  0 toggle public DependencyState getDependencyState() {
386  0 return null;
387    }
388   
 
389  0 toggle public WellFormedState getWellFormedState() {
390  0 return null;
391    }
392   
 
393  0 toggle public FormallyProvedState getFormallyProvedState() {
394  0 return null;
395    }
396   
 
397  0 toggle public SourceFileExceptionList getErrors() {
398  0 return null;
399    }
400   
 
401  0 toggle public SourceFileExceptionList getWarnings() {
402  0 return null;
403    }
404   
 
405  0 toggle public String getStateDescription() {
406  0 return "unknown";
407    }
408   
 
409  0 toggle public String getName() {
410  0 String name = url.substring(url.lastIndexOf('/') + 1);
411  0 name = name.substring(0, name.lastIndexOf('.'));
412  0 return name;
413    }
414   
 
415  0 toggle public String getRuleVersion() {
416  0 return "1.00.00";
417    }
418   
 
419  62 toggle public String getUrl() {
420  62 return url;
421    }
422   
 
423  0 toggle public boolean isLoaded() {
424  0 return false;
425    }
426   
 
427  0 toggle public Qedeq getQedeq() {
428  0 return null;
429    }
430   
 
431  0 toggle public boolean hasLoadedImports() {
432  0 return false;
433    }
434   
 
435  0 toggle public boolean hasLoadedRequiredModules() {
436  0 return false;
437    }
438   
 
439  0 toggle public ModuleReferenceList getRequiredModules() {
440  0 return null;
441    }
442   
 
443  0 toggle public boolean isWellFormed() {
444  0 return false;
445    }
446   
 
447  0 toggle public boolean isFullyFormallyProved() {
448  0 return false;
449    }
450   
 
451  0 toggle public String[] getSupportedLanguages() {
452  0 return null;
453    }
454   
 
455  0 toggle public boolean isSupportedLanguage(String language) {
456  0 return false;
457    }
458   
 
459  0 toggle public String getOriginalLanguage() {
460  0 return null;
461    }
462   
 
463  0 toggle public InternalKernelServices getKernelServices() {
464  0 return null;
465    }
466   
 
467  0 toggle public KernelModuleReferenceList getKernelRequiredModules() {
468  0 return null;
469    }
470   
 
471  0 toggle public ModuleLabels getLabels() {
472  0 return null;
473    }
474   
 
475  0 toggle public Element2Latex getElement2Latex() {
476  0 return null;
477    }
478   
 
479  0 toggle public Element2Utf8 getElement2Utf8() {
480  0 return null;
481    }
482   
 
483  0 toggle public SourceFileException createSourceFileException(Service service, ModuleDataException exception) {
484  0 return null;
485    }
486   
 
487  0 toggle public void addPluginErrorsAndWarnings(ModuleService plugin, SourceFileExceptionList errors,
488    SourceFileExceptionList warnings) {
489    }
490   
 
491  0 toggle public void clearAllPluginErrorsAndWarnings() {
492    }
493   
 
494  0 toggle public ModuleConstantsExistenceChecker getExistenceChecker() {
495  0 return null;
496    }
497   
 
498  0 toggle public void setLoadingImportsFailureState(LoadingImportsState loadImportsFailed, SourceFileExceptionList sfl) {
499    }
500   
 
501  0 toggle public void setLoadingImportsProgressState(LoadingImportsState stateLoadImports) {
502    }
503   
 
504  0 toggle public void setLoadedImports(KernelModuleReferenceList imports) {
505    }
506   
 
507  0 toggle public void setDependencyFailureState(DependencyState loadRequiredFailed, SourceFileExceptionList sfl) {
508    }
509   
 
510  0 toggle public void setDependencyProgressState(DependencyState state) {
511    }
512   
 
513  0 toggle public void setLoadedRequiredModules() {
514    }
515   
 
516  0 toggle public void setWellfFormedFailureState(WellFormedState stateExternalCheckingFailed,
517    SourceFileExceptionList sfl) {
518    }
519   
 
520  0 toggle public void setWellFormedProgressState(WellFormedState stateInternalChecking) {
521    }
522   
 
523  0 toggle public void setFormallyProvedProgressState(FormallyProvedState state) {
524    }
525   
 
526  0 toggle public void setFormallyProvedFailureState(FormallyProvedState state, SourceFileExceptionList sfl) {
527    }
528   
 
529  0 toggle public void setExistenceChecker(ModuleConstantsExistenceChecker existence) {
530    }
531   
 
532  0 toggle public void setWellFormed(ModuleConstantsExistenceChecker checker) {
533    }
534   
535    };
536    }
537    }