From fd6775b3d9696df27a489b03ad0f6dde3beaaaa7 Mon Sep 17 00:00:00 2001 From: ray Date: Thu, 23 May 2002 23:29:38 +0000 Subject: [PATCH] Added tests to test the growing and shrinking the hashtable. git-svn-id: https://samskivert.googlecode.com/svn/trunk@756 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/util/HashIntMapTest.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/tests/src/java/com/samskivert/util/HashIntMapTest.java b/projects/samskivert/tests/src/java/com/samskivert/util/HashIntMapTest.java index 56349408..8627df36 100644 --- a/projects/samskivert/tests/src/java/com/samskivert/util/HashIntMapTest.java +++ b/projects/samskivert/tests/src/java/com/samskivert/util/HashIntMapTest.java @@ -1,5 +1,5 @@ // -// $Id: HashIntMapTest.java,v 1.3 2002/04/11 04:07:42 mdb Exp $ +// $Id: HashIntMapTest.java,v 1.4 2002/05/23 23:29:38 ray Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -89,6 +89,33 @@ public class HashIntMapTest extends TestCase e.printStackTrace(); fail("serialization failure"); } + + table.clear(); + // now try putting lots and lots of values in the table + // so that it grows a bunch + for (int ii=1; ii < 12345; ii += 3) { + table.put(ii, new Integer(ii)); + } + + // now check by removing most and seeing if everything's equal + for (int ii=1; ii < 12345; ii += 3) { + Integer val; + // let's keep the ones that are a multiple of 16 + if ((ii & 15) == 0) { + val = (Integer) table.get(ii); + } else { + val = (Integer) table.remove(ii); + } + assertTrue("get(" + ii + ") == " + val, val.intValue() == ii); + } + + // and then let's also remove the multiples of 16 + for (int ii=1; ii < 12345; ii += 3) { + if ((ii & 15) == 0) { + Integer val = (Integer) table.remove(ii); + assertTrue("get(" + ii + ") == " + val, val.intValue() == ii); + } + } } protected void populateTable (HashIntMap table)