| 1 25 26 package org.archive.util.fingerprint; 27 28 import junit.framework.TestCase; 29 30 38 abstract public class LongFPSetTestCase extends TestCase { 39 40 41 private LongFPSet fpSet; 42 43 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 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 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 assertEquals("one fp in set", 1, fpSet.count()); 79 assertTrue("zero is the element", fpSet.contains(zero)); 80 81 assertTrue("zero removed", fpSet.remove(zero)); 83 assertEquals("empty set again", 0, fpSet.count()); 84 } 85 86 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 102 public void testRemove() { 103 long l1 = (long) 1234; 104 105 assertEquals("empty set to start", 0, fpSet.count()); 106 107 assertFalse("fp not in set", fpSet.remove(l1)); 109 fpSet.add(l1); 111 assertTrue("fp was in set", fpSet.remove(l1)); 113 assertEquals("empty set again", 0, fpSet.count()); 115 } 116 117 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 135 | Popular Tags |