001: /* LongFPSetTestCase
002: *
003: * $Id: LongFPSetTestCase.java 3437 2005-05-06 02:49:04Z stack-sf $
004: *
005: * Created Wed Jan 21 09:00:29 CET 2004
006: *
007: * Copyright (C) 2004 Internet Archive.
008: *
009: * This file is part of the Heritrix web crawler (crawler.archive.org).
010: *
011: * Heritrix is free software; you can redistribute it and/or modify
012: * it under the terms of the GNU Lesser Public License as published by
013: * the Free Software Foundation; either version 2.1 of the License, or
014: * any later version.
015: *
016: * Heritrix is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
019: * GNU Lesser Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser Public License
022: * along with Heritrix; if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: */
025:
026: package org.archive.util.fingerprint;
027:
028: import junit.framework.TestCase;
029:
030: /**
031: * JUnit test suite for LongFPSet. This is an abstract class which defines
032: * the generic tests that test the {@link LongFPSet} interface. Subclasses
033: * may test specifics of {@link LongFPSet} subclass implementations
034: *
035: * @author <a href="mailto:me@jamesc.net">James Casey</a>
036: * @version $ Id:$
037: */
038: abstract public class LongFPSetTestCase extends TestCase {
039:
040: /** the unerlying FPSet we wish to test */
041: private LongFPSet fpSet;
042:
043: /**
044: * Create a new LongFPSetTest object
045: *
046: * @param testName the name of the test
047: */
048: public LongFPSetTestCase(final String testName) {
049: super (testName);
050: }
051:
052: public void setUp() {
053: fpSet = makeLongFPSet();
054: }
055:
056: abstract LongFPSet makeLongFPSet();
057:
058: /** check that we can add fingerprints */
059: public void testAdd() {
060: long l1 = (long) 1234;
061: long l2 = (long) 2345;
062:
063: assertEquals("empty set to start", 0, fpSet.count());
064: assertTrue("set changed on addition of l1", fpSet.add(l1));
065: assertTrue("set changed on addition of l2", fpSet.add(l2));
066: assertFalse("set didn't change on re-addition of l1", fpSet
067: .add(l1));
068: }
069:
070: /** check we can call add/remove/contains() with 0 as a value */
071: public void testWithZero() {
072: long zero = (long) 0;
073:
074: assertEquals("empty set to start", 0, fpSet.count());
075: assertFalse("zero is not there", fpSet.contains(zero));
076: assertTrue("zero added", fpSet.add(zero));
077:
078: // now one element
079: assertEquals("one fp in set", 1, fpSet.count());
080: assertTrue("zero is the element", fpSet.contains(zero));
081:
082: // and remove
083: assertTrue("zero removed", fpSet.remove(zero));
084: assertEquals("empty set again", 0, fpSet.count());
085: }
086:
087: /** check that contains() does what we expect */
088: public void testContains() {
089: long l1 = (long) 1234;
090: long l2 = (long) 2345;
091: long l3 = (long) 1334;
092:
093: assertEquals("empty set to start", 0, fpSet.count());
094: fpSet.add(l1);
095: fpSet.add(l2);
096:
097: assertTrue("contains l1", fpSet.contains(l1));
098: assertTrue("contains l2", fpSet.contains(l2));
099: assertFalse("does not contain l3", fpSet.contains(l3));
100: }
101:
102: /** test remove() works as expected */
103: public void testRemove() {
104: long l1 = (long) 1234;
105:
106: assertEquals("empty set to start", 0, fpSet.count());
107:
108: // remove before it's there
109: assertFalse("fp not in set", fpSet.remove(l1));
110: // now add
111: fpSet.add(l1);
112: // and remove again
113: assertTrue("fp was in set", fpSet.remove(l1));
114: // check set is empty again
115: assertEquals("empty set again", 0, fpSet.count());
116: }
117:
118: /** check count works ok */
119: public void testCount() {
120: final int NUM = 1000;
121: assertEquals("empty set to start", 0, fpSet.count());
122:
123: for (int i = 1; i < NUM; ++i) {
124: fpSet.add((long) i);
125: assertEquals("correct num", i, fpSet.count());
126: }
127: for (int i = NUM - 1; i > 0; --i) {
128: fpSet.remove((long) i);
129: assertEquals("correct num", i - 1, fpSet.count());
130: }
131: assertEquals("empty set to start", 0, fpSet.count());
132:
133: }
134: }
|