01: /* ArrayLongFPCacheTest
02: *
03: * $Id: ArrayLongFPCacheTest.java 3870 2005-10-06 05:01:49Z gojomo $
04: *
05: * Created on Oct 5, 2005
06: *
07: * Copyright (C) 2005 Internet Archive.
08: *
09: * This file is part of the Heritrix web crawler (crawler.archive.org).
10: *
11: * Heritrix is free software; you can redistribute it and/or modify
12: * it under the terms of the GNU Lesser Public License as published by
13: * the Free Software Foundation; either version 2.1 of the License, or
14: * any later version.
15: *
16: * Heritrix is distributed in the hope that it will be useful,
17: * but WITHOUT ANY WARRANTY; without even the implied warranty of
18: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: * GNU Lesser Public License for more details.
20: *
21: * You should have received a copy of the GNU Lesser Public License
22: * along with Heritrix; if not, write to the Free Software
23: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: */
25: package org.archive.util.fingerprint;
26:
27: import junit.framework.TestCase;
28:
29: /**
30: * Unit tests for ArrayLongFPCache.
31: *
32: * @author gojomo
33: */
34: public class ArrayLongFPCacheTest extends TestCase {
35:
36: public void testAdd() {
37: long testVal = 123456L;
38: ArrayLongFPCache cache = new ArrayLongFPCache();
39: assertFalse("contains test value pre-add", cache
40: .contains(testVal));
41: assertFalse("contains test value pre-add", cache
42: .contains(-testVal));
43: cache.add(testVal);
44: cache.add(-testVal);
45: assertTrue("should contain after add", cache.contains(testVal));
46: assertTrue("should contain after add", cache.contains(-testVal));
47: }
48:
49: public void testContains() {
50: long testVal1 = 123456L;
51: long testVal2 = 9090909090L;
52: long testVal3 = 76543210234567L;
53: long testVal4 = 1L;
54: ArrayLongFPCache cache = new ArrayLongFPCache();
55: cache.add(testVal1);
56: cache.add(testVal2);
57: cache.add(testVal3);
58: cache.add(testVal4);
59: assertTrue("should contain after add", cache.contains(testVal1));
60: assertTrue("should contain after add", cache.contains(testVal2));
61: assertTrue("should contain after add", cache.contains(testVal3));
62: assertTrue("should contain after add", cache.contains(testVal4));
63: }
64:
65: public void testReplacement() {
66: ArrayLongFPCache cache = new ArrayLongFPCache();
67: for (long i = 0; i <= ArrayLongFPCache.DEFAULT_SMEAR; i++) {
68: cache.add(i * cache.cacheLength() + 1);
69: }
70: assertFalse("contains value after overwrite", cache
71: .contains(1L));
72: assertTrue("value not retained", cache.contains(cache
73: .cacheLength() + 1));
74:
75: }
76:
77: public void testRemove() {
78: long testVal = 4516500024601L;
79: ArrayLongFPCache cache = new ArrayLongFPCache();
80: cache.add(testVal);
81: cache.add(-testVal);
82: assertTrue("should contain after add", cache.contains(testVal));
83: assertTrue("should contain after add", cache.contains(-testVal));
84: cache.remove(testVal);
85: cache.remove(-testVal);
86: assertFalse("contains test value after remove", cache
87: .contains(testVal));
88: assertFalse("contains test value after remove", cache
89: .contains(-testVal));
90: }
91:
92: }
|