1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package org.archive.util.fingerprint;
27
28 import junit.framework.TestCase;
29
30 /***
31 * JUnit test suite for LongFPSet. This is an abstract class which defines
32 * the generic tests that test the {@link LongFPSet} interface. Subclasses
33 * may test specifics of {@link LongFPSet} subclass implementations
34 *
35 * @author <a href="mailto:me@jamesc.net">James Casey</a>
36 * @version $ Id:$
37 */
38 abstract public class LongFPSetTestCase extends TestCase {
39
40 /*** the unerlying FPSet we wish to test */
41 private LongFPSet fpSet;
42
43 /***
44 * Create a new LongFPSetTest object
45 *
46 * @param testName the name of the test
47 */
48 public LongFPSetTestCase(final String testName) {
49 super(testName);
50 }
51
52 public void setUp() {
53 fpSet = makeLongFPSet();
54 }
55
56 abstract LongFPSet makeLongFPSet();
57
58 /*** check that we can add fingerprints */
59 public void testAdd() {
60 long l1 = (long)1234;
61 long l2 = (long)2345;
62
63 assertEquals("empty set to start", 0, fpSet.count());
64 assertTrue("set changed on addition of l1", fpSet.add(l1));
65 assertTrue("set changed on addition of l2", fpSet.add(l2));
66 assertFalse("set didn't change on re-addition of l1", fpSet.add(l1));
67 }
68
69 /*** check we can call add/remove/contains() with 0 as a value */
70 public void testWithZero() {
71 long zero = (long)0;
72
73 assertEquals("empty set to start", 0, fpSet.count());
74 assertFalse("zero is not there", fpSet.contains(zero));
75 assertTrue("zero added", fpSet.add(zero));
76
77
78 assertEquals("one fp in set", 1, fpSet.count());
79 assertTrue("zero is the element", fpSet.contains(zero));
80
81
82 assertTrue("zero removed", fpSet.remove(zero));
83 assertEquals("empty set again", 0, fpSet.count());
84 }
85
86 /*** check that contains() does what we expect */
87 public void testContains() {
88 long l1 = (long) 1234;
89 long l2 = (long) 2345;
90 long l3 = (long) 1334;
91
92 assertEquals("empty set to start", 0, fpSet.count());
93 fpSet.add(l1);
94 fpSet.add(l2);
95
96 assertTrue("contains l1", fpSet.contains(l1));
97 assertTrue("contains l2", fpSet.contains(l2));
98 assertFalse("does not contain l3", fpSet.contains(l3));
99 }
100
101 /*** test remove() works as expected */
102 public void testRemove() {
103 long l1 = (long) 1234;
104
105 assertEquals("empty set to start", 0, fpSet.count());
106
107
108 assertFalse("fp not in set", fpSet.remove(l1));
109
110 fpSet.add(l1);
111
112 assertTrue("fp was in set", fpSet.remove(l1));
113
114 assertEquals("empty set again", 0, fpSet.count());
115 }
116
117 /*** check count works ok */
118 public void testCount() {
119 final int NUM = 1000;
120 assertEquals("empty set to start", 0, fpSet.count());
121
122 for(int i = 1; i < NUM; ++i) {
123 fpSet.add((long)i);
124 assertEquals("correct num", i, fpSet.count());
125 }
126 for (int i = NUM - 1; i > 0; --i) {
127 fpSet.remove((long) i);
128 assertEquals("correct num", i -1, fpSet.count());
129 }
130 assertEquals("empty set to start", 0, fpSet.count());
131
132 }
133 }
134