/** * Test program for some basic functions of the unordered StringList class. * CSE 143 demonstration program. * @author Hal Perkins * @version 0.1, 3/30/06 */ public class TestStringList { /** * Complain loudly if condition is false * @param condition any boolean value - throw a runtime exception if this is false. */ public static void check(boolean condition) { if (!condition) { throw new RuntimeException("test failed"); } } /** * Create a StringList and try some of its operations. * This is not a comprehensive test, but gives some idea * how to create an object and use some of its methods. */ public static void main(String[] args) { StringList s1 = new StringList(); System.out.println(s1); check(s1.isEmpty()); check(s1.size() == 0); s1.add("foo"); System.out.println(s1); check(!s1.isEmpty()); check(s1.size() == 1); check(s1.get(0).equals("foo")); s1.add("bar"); s1.add("baz"); System.out.println(s1); check(s1.size() == 3); check(s1.get(0).equals("foo")); check(s1.get(2).equals("baz")); s1.set(1,"blah"); System.out.println(s1); check(s1.size() == 3); check(s1.get(0).equals("foo")); check(s1.get(1).equals("blah")); check(s1.get(2).equals("baz")); s1.add(1,"boo"); System.out.println(s1); check(s1.size() == 4); check(s1.get(0).equals("foo")); check(s1.get(1).equals("boo")); check(s1.get(2).equals("blah")); check(s1.get(3).equals("baz")); } }