Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 80494 invoked from network); 13 Nov 2005 15:17:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 13 Nov 2005 15:17:16 -0000 Received: (qmail 43078 invoked by uid 500); 13 Nov 2005 15:17:13 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 43054 invoked by uid 500); 13 Nov 2005 15:17:13 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 43043 invoked by uid 500); 13 Nov 2005 15:17:13 -0000 Received: (qmail 43040 invoked by uid 99); 13 Nov 2005 15:17:13 -0000 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 13 Nov 2005 07:17:12 -0800 Received: (qmail 80460 invoked by uid 65534); 13 Nov 2005 15:16:52 -0000 Message-ID: <20051113151652.80459.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r333020 - /jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLRUMap.java Date: Sun, 13 Nov 2005 15:16:52 -0000 To: commons-cvs@jakarta.apache.org From: scolebourne@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: scolebourne Date: Sun Nov 13 07:16:47 2005 New Revision: 333020 URL: http://svn.apache.org/viewcvs?rev=333020&view=rev Log: Extra tests for the internals of LRUMap bug 32573 Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLRUMap.java Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLRUMap.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLRUMap.java?rev=333020&r1=333019&r2=333020&view=diff ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLRUMap.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLRUMap.java Sun Nov 13 07:16:47 2005 @@ -322,6 +322,137 @@ } } + //----------------------------------------------------------------------- + static class SingleHashCode { + private final String code; + SingleHashCode(String code) { + this.code = code; + } + public int hashCode() { + // always return the same hashcode + // that way, it will end up in the same bucket + return 12; + } + public String toString() { + return "SingleHashCode:" + code; + } + } + + public void testInternalState_Buckets() { + if (isPutAddSupported() == false || isPutChangeSupported() == false) return; + SingleHashCode one = new SingleHashCode("1"); + SingleHashCode two = new SingleHashCode("2"); + SingleHashCode three = new SingleHashCode("3"); + SingleHashCode four = new SingleHashCode("4"); + SingleHashCode five = new SingleHashCode("5"); + SingleHashCode six = new SingleHashCode("6"); + + LRUMap map = new LRUMap(3, 1.0f); + int hashIndex = map.hashIndex(map.hash(one), 4); + map.put(one, "A"); + map.put(two, "B"); + map.put(three, "C"); + + assertEquals(4, map.data.length); + assertEquals(3, map.size); + assertEquals(null, map.header.next); + assertEquals(one, map.header.after.key); // LRU + assertEquals(two, map.header.after.after.key); + assertEquals(three, map.header.after.after.after.key); // MRU + assertEquals(three, map.data[hashIndex].key); + assertEquals(two, map.data[hashIndex].next.key); + assertEquals(one, map.data[hashIndex].next.next.key); + + map.put(four, "D"); // reuses last in next list + + assertEquals(4, map.data.length); + assertEquals(3, map.size); + assertEquals(null, map.header.next); + assertEquals(two, map.header.after.key); // LRU + assertEquals(three, map.header.after.after.key); + assertEquals(four, map.header.after.after.after.key); // MRU + assertEquals(four, map.data[hashIndex].key); + assertEquals(three, map.data[hashIndex].next.key); + assertEquals(two, map.data[hashIndex].next.next.key); + + map.get(three); + + assertEquals(4, map.data.length); + assertEquals(3, map.size); + assertEquals(null, map.header.next); + assertEquals(two, map.header.after.key); // LRU + assertEquals(four, map.header.after.after.key); + assertEquals(three, map.header.after.after.after.key); // MRU + assertEquals(four, map.data[hashIndex].key); + assertEquals(three, map.data[hashIndex].next.key); + assertEquals(two, map.data[hashIndex].next.next.key); + + map.put(five, "E"); // reuses last in next list + + assertEquals(4, map.data.length); + assertEquals(3, map.size); + assertEquals(null, map.header.next); + assertEquals(four, map.header.after.key); // LRU + assertEquals(three, map.header.after.after.key); + assertEquals(five, map.header.after.after.after.key); // MRU + assertEquals(five, map.data[hashIndex].key); + assertEquals(four, map.data[hashIndex].next.key); + assertEquals(three, map.data[hashIndex].next.next.key); + + map.get(three); + map.get(five); + + assertEquals(4, map.data.length); + assertEquals(3, map.size); + assertEquals(null, map.header.next); + assertEquals(four, map.header.after.key); // LRU + assertEquals(three, map.header.after.after.key); + assertEquals(five, map.header.after.after.after.key); // MRU + assertEquals(five, map.data[hashIndex].key); + assertEquals(four, map.data[hashIndex].next.key); + assertEquals(three, map.data[hashIndex].next.next.key); + + map.put(six, "F"); // reuses middle in next list + + assertEquals(4, map.data.length); + assertEquals(3, map.size); + assertEquals(null, map.header.next); + assertEquals(three, map.header.after.key); // LRU + assertEquals(five, map.header.after.after.key); + assertEquals(six, map.header.after.after.after.key); // MRU + assertEquals(six, map.data[hashIndex].key); + assertEquals(five, map.data[hashIndex].next.key); + assertEquals(three, map.data[hashIndex].next.next.key); + } + + public void testInternalState_getEntry_int() { + if (isPutAddSupported() == false || isPutChangeSupported() == false) return; + SingleHashCode one = new SingleHashCode("1"); + SingleHashCode two = new SingleHashCode("2"); + SingleHashCode three = new SingleHashCode("3"); + SingleHashCode four = new SingleHashCode("4"); + SingleHashCode five = new SingleHashCode("5"); + SingleHashCode six = new SingleHashCode("6"); + + LRUMap map = new LRUMap(3, 1.0f); + int hashIndex = map.hashIndex(map.hash(one), 4); + map.put(one, "A"); + map.put(two, "B"); + map.put(three, "C"); + + assertEquals(one, map.getEntry(0).key); + assertEquals(two, map.getEntry(1).key); + assertEquals(three, map.getEntry(2).key); + try { + map.getEntry(-1); + fail(); + } catch (IndexOutOfBoundsException ex) {} + try { + map.getEntry(3); + fail(); + } catch (IndexOutOfBoundsException ex) {} + } + // public void testCreate() throws Exception { // resetEmpty(); // writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/LRUMap.emptyCollection.version3.obj"); --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org