import junit.framework.TestCase; /* * Created on Aug 2, 2004 */ /** Test class for SegmentedList. * */ public class SegmentedListTest extends TestCase { /** Add some objects to a list and see if they can be gotten out. * */ public static void test() { final int TESTLIMIT = 10000; SegmentedList slist = new SegmentedList(); try { slist.get(0); assert false: "didn't get expected out of bounds exception"; } catch (IndexOutOfBoundsException e) { //should happen } slist.add("a"); assert slist.size() == 1; Object gotten = slist.get(0); assert gotten.equals("a"); slist.add("b"); assert slist.size() == 2; gotten = slist.get(1); assert gotten.equals("b"); for (int p = 2; p < TESTLIMIT; p++) { String newValue = "" + ('a' + p); slist.add(newValue); assert slist.size() == p + 1; gotten = slist.get(p); assert gotten.equals(newValue): newValue + " " + p; try { slist.get(p+1); assert false: "didn't get expected out of bounds exception " + p; } catch (IndexOutOfBoundsException e) { //should happen //System.out.println(e); //too much printing } try { slist.get(-p-1); assert false: "didn't get expected out of bounds exception"; } catch (IndexOutOfBoundsException e) { //should happen } } } }