KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > util > fingerprint > ArrayLongFPCacheTest


1 /* ArrayLongFPCacheTest
2 *
3 * $Id: ArrayLongFPCacheTest.java,v 1.1 2005/10/06 05:01:49 gojomo Exp $
4 *
5 * Created on Oct 5, 2005
6 *
7 * Copyright (C) 2005 Internet Archive.
8 *
9 * 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.contains(testVal));
40         assertFalse("contains test value pre-add",cache.contains(-testVal));
41         cache.add(testVal);
42         cache.add(-testVal);
43         assertTrue("should contain after add",cache.contains(testVal));
44         assertTrue("should contain after add",cache.contains(-testVal));
45     }
46
47     public void testContains() {
48         long testVal1 = 123456L;
49         long testVal2 = 9090909090L;
50         long testVal3 = 76543210234567L;
51         long testVal4 = 1L;
52         ArrayLongFPCache cache = new ArrayLongFPCache();
53         cache.add(testVal1);
54         cache.add(testVal2);
55         cache.add(testVal3);
56         cache.add(testVal4);
57         assertTrue("should contain after add",cache.contains(testVal1));
58         assertTrue("should contain after add",cache.contains(testVal2));
59         assertTrue("should contain after add",cache.contains(testVal3));
60         assertTrue("should contain after add",cache.contains(testVal4));
61     }
62
63     public void testReplacement() {
64         ArrayLongFPCache cache = new ArrayLongFPCache();
65         for(long i=0; i<=ArrayLongFPCache.DEFAULT_SMEAR; i++) {
66             cache.add(i*cache.cacheLength()+1);
67         }
68         assertFalse("contains value after overwrite",cache.contains(1L));
69         assertTrue("value not retained",cache.contains(cache.cacheLength()+1));
70
71     }
72     
73     public void testRemove() {
74         long testVal = 4516500024601L;
75         ArrayLongFPCache cache = new ArrayLongFPCache();
76         cache.add(testVal);
77         cache.add(-testVal);
78         assertTrue("should contain after add",cache.contains(testVal));
79         assertTrue("should contain after add",cache.contains(-testVal));
80         cache.remove(testVal);
81         cache.remove(-testVal);
82         assertFalse("contains test value after remove",cache.contains(testVal));
83         assertFalse("contains test value after remove",cache.contains(-testVal));
84     }
85
86 }
87
Popular Tags