package editortrees; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import java.util.ArrayList; public class EditTreeTest { static int points = 0; // Feel free to use these strings in your test cases, or not. static String s1 = "short string", s2 = "a moderately short string", s3 = "This string is not as short as the others", s4 = "This is a great, big, juicy, longer-than-the-others, string", s5 = "You can't always get the strings you want, " + "but if you try sometimes, you just might find you get the strings you need.", sNull = null, sEmpty = ""; /** The variables whose first two digits are your team number are available * for your team's test cases to use. If you want to intiialize them once and for all instead of in individual test cases, * put that code in setUpXY, where XY is your team number. * You may use other variables, of course, but they should be local to your methods. */ EditTree t110, t111, t112, t113, t114, t115, t116, t117, t118, t119; EditTree t120, t121, t122, t123, t124, t125, t126, t127, t128, t129; EditTree t130, t131, t132, t133, t134, t135, t136, t137, t138, t139; EditTree t140, t141, t142, t143, t144, t145, t146, t147, t148, t149; EditTree t150, t151, t152, t153, t154, t155, t156, t157, t158, t159; EditTree t160, t161, t162, t163, t164, t165, t166, t167, t168, t169; EditTree t210, t211, t212, t213, t214, t215, t216, t217, t218, t219; EditTree t220, t221, t222, t223, t224, t225, t226, t227, t228, t229; EditTree t230, t231, t232, t233, t234, t235, t236, t237, t238, t239; EditTree t240, t241, t242, t243, t244, t245, t246, t247, t248, t249; EditTree t250, t251, t252, t253, t254, t255, t256, t257, t258, t259; EditTree t260, t261, t262, t263, t264, t265, t266, t267, t268, t269; EditTree ti0, ti1, ti2, ti3, ti4, ti5, ti6, ti7, ti8, ti9; // Do not modify this method @Before public void setUp() throws Exception { try { setUpInstructors(); } catch (Exception e) { System.out.println("Error in setUpInstructors:"); e.printStackTrace(); } try { setUp11(); } catch (Exception e) { System.out.println("Error in setUp11:"); e.printStackTrace(); } try { setUp12(); } catch (Exception e) { System.out.println("Error in setUp12:"); e.printStackTrace(); } try { setUp13(); } catch (Exception e) { System.out.println("Error in setUp13:"); e.printStackTrace(); } try { setUp14(); } catch (Exception e) { System.out.println("Error in setUp14:"); e.printStackTrace(); } try { setUp15(); } catch (Exception e) { System.out.println("Error in setUp15:"); e.printStackTrace(); } try { setUp16(); } catch (Exception e) { System.out.println("Error in setUp16:"); e.printStackTrace(); } try { setUp21(); } catch (Exception e) { System.out.println("Error in setUp21:"); e.printStackTrace(); } try { setUp22(); } catch (Exception e) { System.out.println("Error in setUp22:"); e.printStackTrace(); } try { setUp23(); } catch (Exception e) { System.out.println("Error in setUp23:"); e.printStackTrace(); } try { setUp24(); } catch (Exception e) { System.out.println("Error in setUp24:"); e.printStackTrace(); } try { setUp25(); } catch (Exception e) { System.out.println("Error in setUp25:"); e.printStackTrace(); } try { setUp26(); } catch (Exception e) { System.out.println("Error in setUp26:"); e.printStackTrace(); } } public void setUpInstructors() throws Exception { } public void setUp11() throws Exception { } public void setUp12() throws Exception { } public void setUp13() throws Exception { t131 = new EditTree(s1); t132 = new EditTree(s2); t133 = new EditTree(s3); t134 = new EditTree(s4); t135 = new EditTree(s5); t136 = new EditTree(s1); t137 = new EditTree(s2); t138 = new EditTree(s3); t139 = new EditTree(s4); t130 = new EditTree(s5); } public void setUp14() throws Exception { } public void setUp15() throws Exception { // Setup a few test trees. Used by get(), toString(), and other // non-destructive tests. this.t150 = new EditTree(); this.t151 = new EditTree(s1); this.t152 = new EditTree(s2); this.t153 = new EditTree(s3); this.t154 = new EditTree(s4); this.t155 = new EditTree(s5); // Used by add() test this.t156 = new EditTree(s5); // t157 and t158 are used by split and concatenate. // t159 is used by the split test and the delete test this.t159 = new EditTree(s1); } public void setUp16() throws Exception { t160 = new EditTree(s1); t161 = new EditTree(s2); t162 = new EditTree(s3); t163 = new EditTree(s4); t164 = new EditTree(s5); } public void setUp21() throws Exception { t210 = new EditTree(s1); t211 = new EditTree(s2); t212 = new EditTree(s3); t213 = new EditTree(s4); t214 = new EditTree(s5); } public void setUp22() throws Exception { // Null Tree t220 = new EditTree(); // Just root, has character a. Tests the one character constructor t221 = new EditTree('a'); // Should set up a, then b to the rights. Tests the string constructor. t222 = new EditTree("ab"); // Both sides. Should be "abc" in order. Tests the string constructor t223 = new EditTree("abc"); // Set up tree for s1. Tests the string constructor t224 = new EditTree(s1); // Set up tree for s2. Tests the string constructor t225 = new EditTree(s2); // Set up tree for s3. Tests the string constructor t226 = new EditTree(s3); // Set up tree for s4. Tests the string constructor. t227 = new EditTree(s4); // Set up tree for "hlo". Will be used to test add(c,pos) t228 = new EditTree("hlo"); // Set up tree for "test tree". Set up tests String constructor. t229 = new EditTree("Test Tree"); /*Just display the trees to see if they constructed properly. Will be commented out at final commit time*/ // DisplayTree.display(t220); // // DisplayTree.display(t221); // // DisplayTree.display(t222); // // DisplayTree.display(t223); // // DisplayTree.display(t224); // // DisplayTree.display(t225); // // DisplayTree.display(t226); // // DisplayTree.display(t227); // // DisplayTree.display(t228); // // DisplayTree.display(t229); } public void setUp23() throws Exception { //CWA: New version submitted by the team on 1/29 t230 = new EditTree(); t231 = new EditTree('a'); t232 = new EditTree('b'); t233 = new EditTree('d'); t234 = new EditTree('f'); t232.add('c', 0); t233.add('e', 1); t234.add('g', 0); t234.add('h'); EditTree t235, t236, t237, t238, t239; // CWA: Tests that depend on the following trees may fail, because // the tests are re[presentation dependent, and also because ranks and balance codes are not set] // All such tests will be removed. // t232.getRoot().left = new Node('c'); // // t233.getRoot().right = new Node('e'); // // t234.getRoot().left = new Node('g'); // t234.getRoot().right = new Node('h'); // // Removed by CWA. These local variables are // never used. //EditTree t235, t236, t237, t238, t239; } public void setUp24() throws Exception { this.t240 = new EditTree(); this.t241 = new EditTree("a"); this.t242 = new EditTree("this is sparta!"); this.t243 = new EditTree("!@#$%^&*"); this.t244 = new EditTree(s1); this.t245 = new EditTree(s2); this.t246 = new EditTree(s3); this.t247 = new EditTree(s4); this.t248 = new EditTree(s5); this.t249 = new EditTree("this is a " + "combined string."); } public void setUp25() throws Exception { t250 = new EditTree(); t251 = new EditTree(); t251.add('a',0); t252 = new EditTree(); t252.add('a',0); t252.add('b'); t252.add('c',0); t253 = new EditTree(); t253.add('a'); t253.add('p'); t253.add('e'); t253.add('r'); t253.add('s'); t253.add('o'); t253.add('n'); t254 = new EditTree(); t254.add('a'); t254.add('t'); reinitialize5(); reinitialize6(); t257 = new EditTree(); t257.add('I'); t257.add(' '); t257.add('s'); t257.add(' '); t257.add('t', 1); t257.add('3'); t257.add('m'); t257.add('a', 6); t257.add('i',3); t258 = new EditTree(); t258.add('I'); t258.add('3'); } // CWA note: This code should have been in setUp(). // setUp is run before EACH test. private void reinitialize5() { t255 = new EditTree(); t255.add('l'); t255.add('f'); } // CWA note: This code should have been in setUp(). private void reinitialize6() { t256 = new EditTree(); t256.add('t'); t256.add('i', 0); } public void setUp26() throws Exception { t260 = new EditTree(); t261 = new EditTree(s1); t262 = new EditTree(s2); t263 = new EditTree(s3); t264 = new EditTree(s4); t265 = new EditTree(); } // auxiliary method: public void assertInOrder(int a,int b,int c) { assertTrue(a<=b && b<=c); } //--------------------- TEAM 11 tests ---------------------- @Test(timeout = 1000) public void testEditTree3_11() { t110 = new EditTree(s1); t111 = new EditTree(s2); t112 = new EditTree(s3); t113 = new EditTree(s4); t114 = new EditTree(s5); assertEquals(s1, t110.toString()); assertEquals(s2, t111.toString()); assertEquals(s3, t112.toString()); assertEquals(s4, t113.toString()); assertEquals(s5, t114.toString()); points += 1; } // Removed by CWA. We have not defined what equals means for EditTrees. // @Test(timeout = 1000) // public void testEditTree4_11() { // t110 = new EditTree('a'); // t111 = new EditTree(t110); // assertEquals(t110, t111); // points += 1; // } @Test(timeout = 1000) public void testHeight1_11() { t110 = new EditTree(s1); t111 = new EditTree(s2); t112 = new EditTree(s3); t113 = new EditTree('a'); t114 = new EditTree(); // Modified by CWA, based on comments by class members. assertTrue(4 >= t110.height()); // CWA: For some reason, team 11 initialized other trees but did not use them. points += 1; } @Test(timeout = 1000) public void testadd1_11() { t110 = new EditTree(s1); assertEquals(s1, t110.toString()); t110.add('a'); assertEquals(s1 + 'a', t110.toString()); t110.add(' '); assertEquals(s1 + 'a' + ' ', t110.toString()); // removed by CWA assertTrue(t110.isHeightBalanced()); points += 1; } @Test(timeout = 1000) public void testadd2_11() { t110 = new EditTree(s1); assertEquals(s1, t110.toString()); t110.add('a', 5); assertEquals("shorta string", t110.toString()); t110.add(' ', 10); assertEquals("shorta str ing", t110.toString()); points += 1; } @Test(timeout = 1000) public void testConcatenate1_11() { t110 = new EditTree(); t111 = new EditTree(s1); t110.concatenate(t111); assertEquals(s1, t110.toString()); points += 1; } @Test(timeout = 1000) public void testConcatenate2_11() { t110 = new EditTree(); t111 = new EditTree(); t110.concatenate(t111); // CWA: WE may not assume that the root node is null. // Students may use another representation that has a header node. // assertEquals(null, t110.getRoot()); assertEquals("", t110.toString()); points += 1; } @Test(timeout = 1000) public void testConcatenate3_11() { t110 = new EditTree(s1); t111 = new EditTree(); t110.concatenate(t111); assertEquals(s1, t110.toString()); points += 1; } @Test(timeout = 1000) public void testConcatenate4_11() { t110 = new EditTree(s2); t111 = new EditTree(s3); t110.concatenate(t111); // Modified by CWA, based on comments by class members. assertEquals(s2 + s3, t110.toString()); points += 1; } @Test // expecting an illegal argument exception public void testConcatenate5_11() { try { t110 = new EditTree(s1); t110.concatenate(t110); fail("cannot concatenate with self"); } catch (IllegalArgumentException e) { points += 1; } } @Test(timeout = 1000) public void testSplit1_11() { t110 = new EditTree(s1); t111 = t110.split(0); assertEquals(s1, t111.toString()); assertEquals("", t110.toString()); points += 1; } @Test(timeout = 1000) public void testSplit2_11() { t110 = new EditTree(s1); t111 = t110.split(6); assertEquals("string", t111.toString()); assertEquals("short ", t110.toString()); points += 1; } @Test(timeout = 1000) public void testSplit3_11() { t110 = new EditTree(s1); t111 = t110.split(11); assertEquals("g", t111.toString()); assertEquals("short strin", t110.toString()); points += 1; } @Test(timeout = 1000) public void testSplit4_11() { t110 = new EditTree(s5); t111 = t110.split(43); assertEquals( "but if you try sometimes, you just might find you get the strings you need.", t111.toString()); assertEquals("You can't always get the strings you want, ", t110 .toString()); points += 1; } @Test // expecting an index out of bounds exception public void testSplit5_11() { try { t110 = new EditTree(s1); t110.split(-3); fail("negative index not allowed"); } catch(IndexOutOfBoundsException e) { points += 1; } } @Test // expecting an index out of bounds exception public void testSplit6_11() { try { t110 = new EditTree(s1); t110.split(13); fail("index 13 is too large"); } catch(IndexOutOfBoundsException e) { points += 1; } } // removed by CWA // @Test(timeout = 1000) // public void testFind1_11() { // t110 = new EditTree(s1); // assertEquals(-1, t110.find("")); // points += 1; // } @Test(timeout = 1000) public void testFind2_11() { t110 = new EditTree(s1); assertEquals(6, t110.find("string")); points += 1; } @Test(timeout = 1000) public void testFind3_11() { t110 = new EditTree(s1); assertEquals(0, t110.find("s")); points += 1; } @Test(timeout = 1000) public void testFind4_11() { t110 = new EditTree(s1); assertEquals(0, t110.find(s1)); points += 1; } @Test(timeout = 1000) public void testFind5_11() { t110 = new EditTree(s5); assertEquals(0, t110.find(s5)); points += 1; } @Test(timeout = 1000) public void testFind6_11() { t110 = new EditTree(s5); assertEquals(s5.length() - 1, t110.find(".")); points += 1; } @Test(timeout = 1000) public void testFind7_11() { t110 = new EditTree(s5); assertEquals(0, t110.find("You")); points += 1; } @Test(timeout = 1000) public void testFind8_11() { t110 = new EditTree(s5); assertEquals(33, t110.find("you")); points += 1; } @Test(timeout = 1000) public void testFind9_11() { t110 = new EditTree(s1); assertEquals(-1, t110.find("string", 7)); points += 1; } @Test(timeout = 1000) public void testFind10_11() { t110 = new EditTree(s1); assertEquals(6, t110.find("string", 6)); points += 1; } @Test(timeout = 1000) public void testFind11_11() { t110 = new EditTree(s5); assertEquals(50, t110.find("you", 45)); points += 1; } @Test(timeout = 1000) public void testFind12_11() { t110 = new EditTree(s1); assertEquals(0, t110.find(s1)); points += 1; } @Test(timeout = 1000) public void testFind13_11() { t110 = new EditTree(s2); assertEquals(-1, t110.find("csse", 0)); points += 1; } // HeightBalanced tests removesd by CWA. // Can't really test this independent of representation. // Removed by CWA. The tree you try to remove fomr has // only 3 elements. There is no element 3 to remove. // Also equals is nt a required method for EditTree // @Test(timeout = 1000) // public void testEditDelete1_11() { // t110 = new EditTree("abc"); // EditTree correctNewTree = new EditTree("ab"); // assertEquals(correctNewTree, t110.delete(3)); // points += 1; // } // Removed by CWA. Would throw IndexOutOfBoundsException. // The character at position 2 is "c", and there are only 4 // characters after it, so we cannot remove 6 characters. // @Test(timeout = 1000) // public void testEditDelete2_11() { // t110 = new EditTree("abcdefg"); // EditTree correctNewTree = new EditTree("ag"); // assertEquals(correctNewTree, t110.delete(2, 6)); // points += 1; // } @Test // expecting an index out of bounds exception public void testEditDelete3_11() { try { t110 = new EditTree("abcdefg"); // CWA: changed 40 to 6, to catch boundary condition. t110.delete(2, 6); fail("attempt to go past end of string"); } catch(IndexOutOfBoundsException e) { points += 1; } } @Test(timeout = 1000) public void testEditGet1_11() { t110 = new EditTree(s1); //CWA: Changed 'o' to 'r'. Indexing begins at 0. assertEquals('r', t110.get(3)); points += 1; } @Test(timeout = 1000) public void testEditGet2_11() { t110 = new EditTree(s3); // CWA: Original test had "String" as the answer assertEquals("tring is no", t110.get(6, 11)); points += 1; } @Test // expecting an index out of bounds exception public void testEditGet3_11() { try { t110 = new EditTree(s2); t110.get(30); fail("30 is longer than string"); } catch(IndexOutOfBoundsException e) { points += 1; } } //--------------------- TEAM 12 tests ---------------------- @Test(timeout = 1000) public void testaddnull_12() { this.t112 = new EditTree(sNull); assertEquals("", t112.toString()); points += 1; } @Test(timeout = 1000) public void testaddempty_12() { t112 = new EditTree(sEmpty); assertEquals("", t112.toString()); points += 1; } @Test(timeout = 1000) public void testOneChar_12() { t112 = new EditTree(); t112.add('a'); assertEquals("a", t112.toString()); points += 1; } @Test(timeout = 1000) public void testThreeChar_12() { t112 = new EditTree("abc"); assertEquals("abc", t112.toString()); points += 1; } @Test // (timeout=1000) public void testTenChar_12() { t112 = new EditTree("abcdefghij"); // DisplayTree.display(t112); // System.out.print(t112.getRoot().left.parent.element); // while(t112 != null) // System.out.print(""); assertEquals("abcdefghij", t112.toString()); points += 1; } @Test(timeout = 1000) public void TestGetpos0_12() { t112 = new EditTree("abc"); assertEquals('a', t112.get(0)); points += 1; } @Test(timeout = 1000) public void TestGetpos1_12() { t112 = new EditTree("abc"); assertEquals('b', t112.get(1)); points += 1; } @Test(timeout = 1000) public void TestGetpos2_12() { t112 = new EditTree("abc"); assertEquals('c', t112.get(2)); points += 1; } @Test(timeout = 1000) public void TestTreesS1_12() { this.t112 = new EditTree(s1); assertEquals('g', t112.get(t112.size() - 1)); assertEquals("short string", t112.toString()); // CWA: Team 12 originally said height must be 4. Can also be 3. // in fact is SHOULD be free if constructor is written well. assertTrue(4 >= t112.height()); points += 1; } @Test(timeout = 1000) public void TestTreesAddspecificPosition_12() { this.t112 = new EditTree(s1); t112.add('X', 5); assertEquals('g', t112.get(t112.size() - 1)); assertEquals("shortX string", t112.toString()); // DisplayTree.display(t112); // while(t112 != null) // System.out.print(""); // CWA: Team 12 originally said height must be 5. // It cannot be 5! Must be 4 or 3 // in fact is SHOULD be free if constructor is written well. assertTrue(4 >= t112.height()); points += 1; } @Test(timeout = 1000) public void TestTreesAddspecificPositionBig_12() { this.t112 = new EditTree(s4); t112.add('X', 20); assertEquals('g', t112.get(t112.size() - 1)); assertEquals("This is a great, bigX, juicy, longer-than-the-others, string", t112.toString()); // DisplayTree.display(t112); // while(t112 != null) // System.out.print(""); points += 1; } @Test(timeout = 1000) public void TestTreesBIG_12() { this.t112 = new EditTree(s5); assertEquals('.', t112.get(t112.size() - 1)); assertEquals(s5, t112.toString()); points += 1; } @Test(timeout = 1000) public void TestDeleteSmall_12() { this.t112 = new EditTree(s1); assertEquals('s', t112.delete(0)); assertEquals(11, t112.size()); assertEquals('g', t112.delete(10)); assertEquals(10, t112.size()); assertEquals('s', t112.delete(5)); assertEquals(9, t112.size()); assertEquals('i', t112.delete(7)); assertEquals(8, t112.size()); assertEquals("hort trn", t112.toString()); points += 1; } @Test(timeout = 1000) public void TestDeleteMedium_12() { this.t112 = new EditTree(s3); assertEquals('T', t112.delete(0)); assertEquals(40, t112.size()); assertEquals('h', t112.delete(31)); assertEquals(39, t112.size()); assertEquals('s', t112.delete(38)); assertEquals(38, t112.size()); try { t112.delete(40); fail("can't delete from index 40"); } catch (IndexOutOfBoundsException e) { // allow it to continue } assertEquals("his string is not as short as te other", t112.toString()); points += 1; } @Test(timeout = 1000) public void TestDeleteExtendSmall_12() { this.t112 = new EditTree(s1); assertEquals("s", t112.delete(0, 1).toString()); assertEquals(11, t112.size()); assertEquals("t s", t112.delete(3, 3).toString()); assertEquals(8, t112.size()); assertEquals("hortring", t112.toString()); try { t112.delete(11, 12); fail("illegal delete positions"); } catch (IndexOutOfBoundsException e) { points += 1; } } @Test(timeout = 1000) public void TestDeleteExtendLarge_12() { // CWA: Team 12 had s1 instead of s5 this.t112 = new EditTree(s5); // CWA: Originally the next line had the string that was left instead of the string that was deleted. assertEquals("You can't always get the strings you want, but if you try sometimes,", t112.delete(0, 68).toString()); assertEquals(50, t112.size()); try { t112.delete(-1, 2); // assertEquals(true, false); } catch (IndexOutOfBoundsException e) { assertEquals(true, true); } points += 1; } @Test(timeout = 1000) public void TestSplitMedium_12() { this.t112 = new EditTree(s3); assertEquals("s short as the others", t112.split(20).toString()); // CWA: Changed 21 to 20. assertEquals(20, t112.size()); try { t112.split(100); fail("illegal split position"); } catch (IndexOutOfBoundsException e) { points += 1; } } @Test(timeout = 1000) public void TestSplitLong_12() { this.t112 = new EditTree(s5); assertEquals( // CWA A student said that there was an extra character in the beginning. // I chose to simply remove it, thinking that if he is wrong, someone will tell me. "u try sometimes, you just might find you get the strings you need.", t112.split(52).toString()); // CWA: Changed 67 to 52. assertEquals(52, t112.size()); points += 1; } @Test(timeout = 1000) public void TestConcatSmall_12() { this.t112 = new EditTree(s1); EditTree treeToAdd = new EditTree(s2); t112.concatenate(treeToAdd); assertEquals(s1+s2,t112.toString()); assertEquals("",treeToAdd.toString()); assertEquals('s',t112.get(0)); assertEquals('g', t112.get(t112.size()-1)); assertEquals('a', t112.get(12)); points += 1; } @Test(timeout = 1000) public void TestConcatLarge_12() { this.t112 = new EditTree(s3); EditTree treeToAdd = new EditTree(s4); t112.concatenate(treeToAdd); assertEquals(s3+s4,t112.toString()); assertEquals("",treeToAdd.toString()); assertEquals('T',t112.get(0)); assertEquals('g', t112.get(t112.size()-1)); assertEquals('T', t112.get(41)); points += 1; } //--------------------- TEAM 13 tests ---------------------- @Test(timeout = 1000) public void testToString_13() { // test non-modified trees assertEquals(s1, t131.toString()); assertEquals(s2, t132.toString()); assertEquals(s3, t133.toString()); assertEquals(s4, t134.toString()); assertEquals(s5, t135.toString()); points +=1; } @Test(timeout = 1000) public void testConstructors_13() { // make sure string constructor works assertEquals(new EditTree(s1).toString(), s1); assertEquals(new EditTree(s2).toString(), s2); assertEquals(new EditTree(s3).toString(), s3); assertEquals(new EditTree(s4).toString(), s4); assertEquals(new EditTree(s5).toString(), s5); // test single-character constructor assertEquals(new EditTree('!').toString(), "!"); // test tree-copier constructor EditTree testTree = new EditTree(t135); assertEquals(testTree.toString(), t135.toString()); assertEquals(testTree.size(), t135.size()); assertEquals(testTree.height(), t135.height()); assertEquals(testTree.get(65), t135.get(65)); points +=1; } @Test(timeout = 1000) public void testSize3_i() { ti3 = new EditTree(s1); assertEquals(12, ti3.size()); points +=1; } @Test(timeout = 1000) public void testAdd_13() { // test add at index t131.add('z', 7); t132.add('h', 12); t133.add('6', 23); t134.add('8', 59); t134.add('9', 60); t135.add('j', 68); t135.add(' ', 68); assertEquals("short sztring", t131.toString()); assertEquals("a moderatelyh short string", t132.toString()); assertEquals("This string is not as s6hort as the others", t133.toString()); assertEquals( "This is a great, big, juicy, longer-than-the-others, string89", t134.toString()); assertEquals( "You can't always get the strings you want, but if you try sometimes, j you just might find you get the strings you need.", t135.toString()); // test add at end t131.add('w'); t132.add('o'); t133.add('r'); t134.add('k'); t135.add('!'); assertEquals("short sztringw", t131.toString()); assertEquals("a moderatelyh short stringo", t132.toString()); assertEquals("This string is not as s6hort as the othersr", t133.toString()); assertEquals( "This is a great, big, juicy, longer-than-the-others, string89k", t134.toString()); assertEquals( "You can't always get the strings you want, but if you try sometimes, j you just might find you get the strings you need.!", t135.toString()); points +=1; } @Test(timeout = 1000) public void testDelete_13() { // test deleting at index assertEquals('t', t131.delete(7)); assertEquals(' ', t132.delete(12)); assertEquals('T', t133.delete(0)); assertEquals(',', t134.delete(15)); assertEquals(',', t134.delete(19)); assertEquals(',', t134.delete(25)); assertEquals('.', t135.delete(117)); assertEquals("short sring", t131.toString()); assertEquals("a moderatelyshort string", t132.toString()); assertEquals("his string is not as short as the others", t133.toString()); assertEquals( "This is a great big juicy longer-than-the-others, string", t134.toString()); assertEquals( "You can't always get the strings you want, but if you try sometimes, you just might find you get the strings you need", t135.toString()); // CWA removed this section. No Equals method is requireed for EditTrees // test deleting from index to a certain length away within the string // assertEquals(new EditTree("short string"), t136.delete(0, 12)); // assertEquals(new EditTree("rate"), t137.delete(5, 4)); // assertEquals(new EditTree(""), t138.delete(4, 0)); // assertEquals(new EditTree(", longer-than-the-others,"), // t139.delete(27, 25)); // assertEquals(new EditTree("You"), t130.delete(0, 3)); // CWA removed the following test. It is incorrect, and had nothing to do wit deletion. // assertEquals("", t136.toString()); // assertEquals("a modely short string", t137.toString()); // assertEquals("This string is not as short as the others", // t138.toString()); // assertEquals("This is a great, big, juicy string", t139.toString()); // assertEquals( // " can't always get the strings you want, but if you try sometimes, you just might find you get the strings you need.", // t130.toString()); points +=1; } @Test(timeout = 1000) public void testConcatenate_13() { // a few tree concatenations t131.concatenate(t132); t133.concatenate(t134); t135.concatenate(t130); // check to see if "other" trees are made to be blank assertEquals("", t132.toString()); assertEquals("", t134.toString()); assertEquals("", t130.toString()); // make sure that trees are properly concatenated assertEquals("short stringa moderately short string", t131.toString()); assertEquals( "This string is not as short as the othersThis is a great, big, juicy, longer-than-the-others, string", t133.toString()); assertEquals( "You can't always get the strings you want, but if you try sometimes, you just might find you get the strings you need.You can't always get the strings you want, but if you try sometimes, you just might find you get the strings you need.", t135.toString()); // make sure concatenating a blank tree doesn't add anything t131.concatenate(t132); assertEquals("", t132.toString()); assertEquals("short stringa moderately short string", t131.toString()); points +=1; } // Remooved by CWA. I had already deleted so many parts of this test when someone // pointed out to me that the last two calls to split should throw IndexOutObfBoundsExceptions. @Test(timeout = 1000) public void testSplit_13() { // // make sure split function returns correct tree (assumes one-based // // indexing) // // CWA: EditTree has no required equals method. // // I commented out the assertEquals tests, and left in the calls to split. // // NOTE: I did not check to make sure that the strings in the assert tests later in this method // // are actually the correct answers. If you find that they are not, please let me know. // //// assertEquals(new EditTree("short string"), // t131.split(1); //// assertEquals(new EditTree("rately short string"), // t132.split(6); //// assertEquals(new EditTree("s"), // t133.split(41); //// assertEquals(new EditTree( //// "at, big, juicy, longer-than-the-others, string"), // t132.split(13); // // // make sure correct letters are left in tree after it is split // assertEquals("", t131.toString()); // assertEquals("a mode", t132.toString()); // assertEquals("This string is not as short as the other", // t133.toString()); // assertEquals("This is a gre", t132.toString()); // // points +=1; } // Removed by CWA. Makes naive assumptions about constructors. // Assumes that every team's constructors work the same as theirs. // @Test(timeout = 1000) // public void testHeight_13() { // // test heights of non-modified trees // assertEquals(3, t131.height()); // assertEquals(4, t132.height()); // assertEquals(5, t133.height()); // assertEquals(5, t134.height()); // assertEquals(6, t135.height()); // // points +=1; // System.out.println(" points = " + points); // // } @Test(timeout = 1000) public void testGet_13() { // tests simple get operations (assumes 1-based indexing) //CWA: indexing is zero-based. I reduced each number by 1. assertEquals('s', t131.get(6)); assertEquals('Y', t135.get(0)); assertEquals('g', t132.get(24)); points +=1; System.out.println(" points = " + points); } @Test(timeout = 1000) public void testFind_13() { // try to find strings that don't exist assertEquals(-1, t131.find("LALALALALALALALA")); assertEquals(-1, t132.find("ASDASDASDQAWHDAWDADAWDWADA")); assertEquals(-1, t133.find("This", 7)); // find strings that do in fact exist (assume 1-based indexing for // position) // CWA: Changed numbers for zero-based indexing. assertEquals(0, t131.find("short")); assertEquals(2,t132.find("moderately ")); assertEquals(4, t133.find(" ", 1)); points +=1; System.out.println(" points = " + points); } //--------------------- TEAM 14 tests ---------------------- @Test(timeout = 1000) public void testAddChar_14() { EditTree addTree = new EditTree(); addTree.add('j'); assertEquals("j", addTree.toString()); points++; } @Test(timeout = 1000) public void testAddShortString_14() { EditTree addTree = new EditTree(); for (int i = 0; i < s1.length(); i++) { addTree.add(s1.charAt(i)); } assertEquals(s1, addTree.toString()); points++; } @Test(timeout = 1000) public void testAddModShortString_14() { EditTree addTree = new EditTree(); for (int i = 0; i < s2.length(); i++) { addTree.add(s2.charAt(i)); } assertEquals(s2, addTree.toString()); points++; } @Test public void testAddPosOutofBoundsNullRoot_14() { try { EditTree addTree = new EditTree(); addTree.add('j', 1); fail("illegal add position"); } catch(IndexOutOfBoundsException e) { points++; } } @Test public void testAddPosOutofBoundsWithString_14() { try { EditTree addTree = new EditTree(); for (int i = 0; i < s1.length(); i++) { addTree.add(s1.charAt(i)); } addTree.add('j', 20); fail("illegal add position"); } catch (IndexOutOfBoundsException e) { points++; } } @Test(timeout = 1000) public void testAddChartoEnd_14() { EditTree addTree = new EditTree(); for (int i = 0; i < s1.length(); i++) { addTree.add(s1.charAt(i)); } addTree.add('s', 12); assertEquals(s1 + "s", addTree.toString()); points++; } @Test(timeout = 1000) public void testAddChartoBeginning_14() { EditTree addTree = new EditTree(); for (int i = 0; i < s1.length(); i++) { addTree.add(s1.charAt(i)); } addTree.add(' ', 0); assertEquals(" " + s1, addTree.toString()); points++; } @Test(timeout = 1000) public void testAddChartoMiddle_14() { EditTree addTree = new EditTree(); for (int i = 0; i < s1.length(); i++) { addTree.add(s1.charAt(i)); } // CWA: Changed 6 to 5; zero-based indexing addTree.add('.', 5); assertEquals("short. string", addTree.toString()); points++; } // String 1 @Test(timeout = 1000) public void testStringOneHeightSizeAddAndDelete_14() { t140 = new EditTree(s1); assertTrue(t140.height() <= 4); assertEquals(12, t140.size()); t140.add('z', 2); assertEquals(13, t140.size()); t140.delete(2); assertEquals(12, t140.size()); // CWA: Added point value increment points++; } // Null @Test(timeout = 1000) public void testNullTreeHeightSize_14() { t140 = new EditTree(); assertEquals(-1, t140.height()); assertEquals(0, t140.size()); points++; } // Add one character // CWA: These things (except rank tests) are tested by testAddChar, so this test is redundant. // @Test(timeout = 1000) // public void testAddToNull_14() { // t140 = new EditTree(); // t140.add('c'); // assertEquals(1, t140.size()); // assertEquals(0, t140.height()); // // // CWA: It is not reasonable to do this test because of different representation by different teams. // assertEquals(0, t140.getRoot().rank); // t140.add('h'); // assertEquals(1, t140.getRoot().rank); // points++; // } // Find a single character string @Test(timeout = 1000) public void testFindOneCharStringInOneCharTree_14() { t140 = new EditTree("a"); // CWA: Changed strange assertFalse test to one that is more straightforward. assertEquals(t140.find("a"), 0); points++; } // Deletes root, checks root rank again, checks if deleted node is in // the tree // CWA: Tests that examine contents of specific nodes may be useful for individual teams' // tests, but cannot be used for the whole class because they depend on a particular representation of the trees. // @Test(timeout = 1000) // public void testDeleteRankandGetRoot_14() { // t140 = new EditTree("a"); // t140.delete(0); // assertEquals(0, t140.getRoot().rank); // assertTrue(t140.find("c") == -1); // points++; // } // Deletes a node, checks for height @Test(timeout = 1000) public void testDeleteAndCheckHeight_14() { t140 = new EditTree(s1); t140.delete(0); // CWA: Changed <= to == assertTrue(t140.height() == 3); points++; } // Add to end of tree by looping, check height @Test(timeout = 1000) public void testAddAndCheckHeight_14() { t140 = new EditTree(); for (int i = 0; i < s1.length()-1; i++) { t140.add(s1.charAt(i)); } assertTrue(t140.height() == 3); points++; } // Find s1 @Test(timeout = 1000) public void testFindS1InS1Tree_14() { t140 = new EditTree(s1); // CWA: changed assertFalse to assertEquals for easier checking. assertEquals(0, t140.find(s1)); points++; } // Concatenate 2 null trees @Test(timeout = 1000) public void testConcatNullTrees_14() { t140 = new EditTree(); t141 = new EditTree(); t140.concatenate(t141); assertEquals(0, t140.size()); assertEquals(-1, t140.height()); points++; } // Concatenate a null tree with a tree containing 1 node (Also tests // find) @Test(timeout = 1000) public void testConcatNullAndSingleAndCheck_14() { t140 = new EditTree(); t141 = new EditTree('a'); t140.concatenate(t141); assertEquals(1, t140.size()); assertEquals(0, t140.height()); // CWA: Added the following line of code: assertEquals(0, t141.size()); assertEquals(-1, t141.height()); assertEquals(0, t140.find("a")); assertEquals(-1 , t141.find("a")); points++; } // Concatenate a null tree with a tree containing many nodes (Also tests // find) @Test(timeout = 1000) public void testConcatNullAndManyAndCheck_14() { t140 = new EditTree(); t141 = new EditTree(s1); t140.concatenate(t141); assertTrue(t140.height() <= 4); assertEquals(12, t140.size()); assertEquals(0, t141.size()); assertFalse(t140.find(s1) == -1); //CWA: changed t140 to t141 assertTrue(t141.find(s1) == -1); points++; } // Concatenate 2 trees containing many nodes @Test(timeout = 1000) public void testConcatMediumAndCheck_14() { t140 = new EditTree(s1); t141 = new EditTree(s2); t140.concatenate(t141); int newSize = s1.length() + s2.length(); assertEquals(newSize, t140.size()); // CWA: Changed <= to == assertTrue(t140.height() == 5); assertFalse(t140.find(s1) == -1); assertFalse(t140.find(s2) == -1); points++; } // Mega-concatenation @Test(timeout = 1000) public void testConcatBig_14() { t142 = new EditTree(s4); t143 = new EditTree(s5); //CWA: I think you meant to use 142, so I changed it t143.concatenate(t142); //assertTrue(t143.isHeightBalanced()); //CWA: added a real test: assertEquals(s5+s4, t143.toString()); assertEquals("", t142.toString()); // CWA: added height test assertTrue(t143.height() <= 9); points++; } // Split a larger tree @Test(timeout = 1000) public void testSplitLargeTree_14() { // CWA: added the +s2. This did not make sense without it. // added the +1 in the plit to make it more interesting. t140 = new EditTree(s1+s2); t141 = t140.split(s1.length()+1); assertEquals(t140.toString(), s1+s2.substring(0, 1)); assertEquals(t141.toString(), s2.substring(1)); points++; } // Split a small tree @Test(timeout = 1000) public void testSplitSmallTree_14() { t140 = new EditTree("abc"); t141 = t140.split(1); // I think you got the heights backwards. t140 is "a" and t141 is "bc". I reversed the values assertEquals(0, t140.height()); assertEquals(1, t141.height()); // CWA: Changed assertTrue to assertEquals, also changed the strings to the correct answers assertEquals("a",t140.toString()); assertEquals("bc", t141.toString()); points++; } // Split slippery @Test(timeout = 1000) public void testSplitSlippery_14() { t140 = new EditTree("SLIPPERY"); t141 = t140.split(0); // CWA: the S should be part of the "split-off" tree. // replaced assertTrue by assertEquals assertEquals("",t140.toString()); assertEquals("SLIPPERY",t141.toString()); assertTrue(t141.height() <= 4 && t141.height() >= 3); //assertTrue(t141.isHeightBalanced()); points++; } // find a string at a position @Test(timeout = 1000) public void testSplitSlipperyAndFindsSubstrings_14() { //CWA: added the first two lines below. t140 = new EditTree("SLIPPERY"); t141= t140.split(1); assertTrue(t141.find("LIP", 0) == 0); assertTrue(t141.find("S", 0) == -1); assertTrue(t141.find("P", 0) == 2); points++; } // getsTest @Test(timeout = 1000) public void testGets_14() { t145 = new EditTree(s1); assertEquals('s', t145.get(0)); t146 = new EditTree(s2); assertEquals('a', t146.get(0)); t147 = new EditTree(s3); assertEquals('T', t147.get(0)); points++; } //--------------------- TEAM 15 tests ---------------------- @Test // (timeout = 1000) public void testInOrderString_15() { // Test the toString() method for each of the test strings String[] strings = { s1, s2, s3, s4, s5 }; EditTree[] trees = { t151, t152, t153, t154, t155 }; for (int t = 0; t < strings.length; t++) { // CWA: reversed orrder so it will be expected, calculated instead of the other way around assertEquals(strings[t], trees[t].toString()); } points += 1; } @Test(timeout = 1000) public void testGet_15() { // Tries to get a non-existent element from the null-tree. try { t150.get(1); fail("You should've thrown an IndexOutOfBoundsException on a zero-sized tree!"); } catch (IndexOutOfBoundsException e) { // pass } // Tries to get an obviously bogus position from a tree try { t151.get(-1); fail("You should've thrown an IndexOutOfBoundsException on a bogus position!"); } catch (IndexOutOfBoundsException e) { // pass } // Tries to get an object outside of the tree try { t151.get(42); fail("You should've thrown an IndexOutOfBoundsException when the index exceeds the size of the tree!"); } catch (IndexOutOfBoundsException e) { // pass } // Test the get() method for each of the test strings //CWA: Removed first three trees, so it won't be overkill String[] strings = { s4, s5 }; EditTree[] trees = { t154, t155 }; for (int t = 0; t < strings.length; t++) { String theString = strings[t]; EditTree theTree = trees[t]; for (int i = 0; i < theString.length(); i++) { assertEquals(theString.charAt(i), theTree.get(i)); } } // You've made it this far without blowing up. You may have a point. points += 1; } @Test(timeout = 1000) public void testAdd_15() { // Add a character to the tree and check if it exists in the toString // output. String toAdd = "this is a test"; String currentState = s5; for (int i = 0; i < toAdd.length(); i++) { // Add it to the tree and the state t156.add(toAdd.charAt(i)); currentState += toAdd.charAt(i); assertEquals(currentState, t156.toString()); } // Test adding a specific point t151.add('f', 3); assertEquals('f', t151.get(3)); // Try some invalid insert indices try { t151.add('c', -1); fail("You should've thrown an IllegalArgumentException for a negative insertion index!"); } catch (IllegalArgumentException e) { points += 1; } catch (IndexOutOfBoundsException e) { points += 1; } } @Test(timeout = 2000) public void testGetString_15() { // Tests the get(pos, length) going from a pos to an arbitrary position // in the string // CWA: Changed s5 to s2. It was a bit of overkill before. for (int i = 0; i < s2.length() - 1; i++) { for (int j = i + 1; j < s2.length(); j++) { assertEquals(s2.substring(i, j), t152.get(i, j - i)); } } points += 1; } // CWA: Removed this, because I wanted to check for something more specific. // I added a test for an equivalent thing at the end of this file. // @Test(timeout = 2000) // public void testHeight_15() { // String[] strings = { s1, s2, s3, s4, s5 }; // EditTree[] trees = { t151, t152, t153, t154, t155 }; // // Check the height of each node // for (int t = 0; t < strings.length; t++) { // assertTrue(maxTreeHeight_15(strings[t].length()) >= trees[t] // .height()); // } // // // points += 1; // } // // /** // * Returns the maximum height of a balanced AVL tree given the number of // * nodes. // * // * @param nodes // * @return // */ // private int maxTreeHeight_15(int nodes) { // double log = Math.log(nodes) / Math.log(2); // return (int) Math.floor((1.44 * log) - 1.328); // } /** * Perform the concatenate and split tests in this order */ @Test(timeout = 2000) public void testConcatenate_15() { // takes a position and splits the string s1 into to substrings int pos = 7; // constructs two new trees this.t157 = new EditTree(s1.substring(0, pos)); this.t158 = new EditTree(s1.substring(pos, s1.length())); // concatenates the two trees this.t157.concatenate(this.t158); // assert that this new tree has the same in-order traversal as the // original string. assertEquals(s1, this.t157.toString()); // You've earned it! points += 1; } @Test(timeout = 2000) public void testSplit_15() { this.t159 = new EditTree(s1); // splits the tree t157 into its original components int pos = 6; this.t158 = this.t157.split(pos); // asserts that the second half of the split t151 is the same as t158 //CWA: added calls to toString() assertEquals(this.t158.toString(), this.t159.split(pos).toString()); // asserts that the first half of the split is the same as t158 assertEquals(this.t157.toString(), this.t159.toString()); points += 1; } @Test(timeout = 3000) public void testFind_15() { // Choose a fixed position within the s5 string int pos = 10; int length = 10; String substring = s5.substring(pos, pos + length); assertEquals(pos, t155.find(substring)); // Check a non-existent string assertEquals(-1, t155.find("asdf")); assertEquals(-1, t155.find("asdf", 12)); // Check for a string that exists before the position given. assertEquals(-1, t155.find("can't", 11)); // Alas! You've found another point! points += 1; } @Test(timeout = 3000) public void testDelete_15() { this.t159 = new EditTree(s3); String modified_s3 = removeCharacter_15(s3, 10); this.t159.delete(10); assertEquals(modified_s3, this.t159.toString()); } private String removeCharacter_15(String toModified, int position) { return toModified.substring(0, position) + toModified.substring(position + 1); } //--------------------- TEAM 16 tests ---------------------- @Test(timeout = 1000) public void testAdd_16() { t160.add('x', 0); t160.add('y', 2); assertEquals(t160.toString(), "xsyhort string"); t161.add('d'); t161.add('y'); assertEquals(t161.toString(), "a moderately short stringdy"); t162.add('W', 10); t162.add('E'); assertEquals(t162.toString(), "This strinWg is not as short as the othersE"); t163.add('1', 2); t163.add('1', 2); t163.add('0', 2); assertEquals(t163.toString(), "Th011is is a great, big, juicy, longer-than-the-others, string"); points += 1; } @Test(timeout = 1000) public void testString_16() { assertEquals(t160.toString(), s1); assertEquals(t161.toString(), s2); assertEquals(t162.toString(), s3); assertEquals(t163.toString(), s4); assertEquals(t164.toString(), s5); points += 1; } @Test(timeout = 1000) public void testGet_16() { assertEquals(t160.get(0), s1.charAt(0)); assertEquals(t161.get(4), s2.charAt(4)); assertEquals(t162.get(15), s3.charAt(15)); assertEquals(t163.get(30), s4.charAt(30)); assertEquals(t164.get(s5.length() - 1), s5.charAt(s5.length() - 1)); points += 1; } @Test(timeout = 1000) public void testSlippery_16() { EditTree slippery = new EditTree(); slippery.add('s'); slippery.add('l'); slippery.add('1'); slippery.add('p'); slippery.add('p'); slippery.add('3', 3); slippery.add('r', 2); slippery.add('y'); assertEquals(slippery.toString(), "slr13ppy"); assertEquals(slippery.height(), 3); points += 1; } @Test(timeout = 1000) public void testDeleteSam_16() { assertEquals(t160.delete(2), 'o'); // CWA: added toString() call. assertEquals("shrt string", t160.toString()); t160.delete(4); t160.delete(4); t160.delete(4); t160.delete(4); t160.delete(4); // CWA: You left out the toString() call. // CWA: Answer was incorrect. I think I fixed it. // CWA You had the expected answer and the test in the wrong order. // Expected value should come first. assertEquals("shrtng", t160.toString()); // CWA added points increment points++; } @Test(timeout = 1000) public void testSplitSam_16() { assertEquals( // CWA: added toString calls and put arguments in correct order. Also, (because a student // said I was off by one, I added a space at the beginning of the first answer. " get the strings you want, but if you try sometimes, you just might find you get the strings you need.", t164.split(16).toString()); assertEquals(" string", t160.split(5).toString() ); } // CWA: caoncatenating a tree with itself is not allowed. // The following would have been legal: // t160.concatenate(new EditTree(t160)); // @Test(timeout = 1000) // public void testConcatenateSam_16() { // t160.concatenate(t160); // assertEquals(t160.toString(), "short stringshort string"); // } @Test(timeout = 1000) public void testDeleteSubStringSam_16() { t161.delete(2, 11); // CWA: Put arguments in correct order and added toString(). assertEquals("a short string", t161.toString()); // CWA added points increment points++; } @Test(timeout = 1000) public void testSingleRotationsDale_16() { EditTree test = new EditTree("SLIpPERY"); // CWA: You assume a rotation, How do you know how they contsruct the initial tree? // single left test.add('x'); // single right test.add('D', 4); test.add('g', 4); assertEquals(test.toString(), "SLIpgDPERYx"); // CWA added points increment points++; } @Test(timeout=1000) public void testDoubleRotationsDale_16(){ EditTree test = new EditTree("SIpE"); test.add('D',2); test.add('g',2); test.add('t',2); test.add('H', 2); // CWA: Expected value and test were reversed. // I fixed that in both asseertEquals cases below. assertEquals("SIHtgDpE", test.toString() ); EditTree test2 = new EditTree("SIpE"); test2.add('D',1); test2.add('g',1); test2.add('t',1); // CWA: answer in the following assert was wrong assertEquals("StgDIpE", test2.toString()); // CWA added points increment points++; } //--------------------- TEAM 21 tests ---------------------- @Test(timeout = 2000) // Tests constructing a EditTree from an EditTree public void testConstructor4_21() { assertEquals(t210.toString(), new EditTree(t210).toString()); assertEquals(t211.toString(), new EditTree(t211).toString()); assertEquals(t212.toString(), new EditTree(t212).toString()); assertEquals(t213.toString(), new EditTree(t213).toString()); assertEquals(t214.toString(), new EditTree(t214).toString()); //CWA added getRoot; and changed .equals to == assertFalse(t210.getRoot() == new EditTree(t210).getRoot()); assertFalse(t211.getRoot() == new EditTree(t211).getRoot()); assertFalse(t212.getRoot() == new EditTree(t212).getRoot()); assertFalse(t213.getRoot() == new EditTree(t213).getRoot()); assertFalse(t214.getRoot() == new EditTree(t214).getRoot()); points += 1; } @Test(timeout = 2000) public void testToString_21() { assertEquals(s1, t210.toString()); assertEquals(s2, t211.toString()); assertEquals(s3, t212.toString()); assertEquals(s4, t213.toString()); assertEquals(s5, t214.toString()); points += 1; } @Test(timeout = 2000) // Tests the add method for adding a character at the end of a string. (The // add method with only one parameter) public void testAdd_21() { t215 = new EditTree("short strin"); t215.add('g'); assertEquals(s1, t215.toString()); t216 = new EditTree("a moderately short strin"); t216.add('g'); assertEquals(s2, t216.toString()); t217 = new EditTree("This string is not as short as the other"); t217.add('s'); assertEquals(s3, t217.toString()); t218 = new EditTree( "This is a great, big, juicy, longer-than-the-others, strin"); t218.add('g'); assertEquals(s4, t218.toString()); t219 = new EditTree( "You can't always get the strings you want, " + "but if you try sometimes, you just might find you get the strings you need"); t219.add('.'); assertEquals(s5, t219.toString()); // CWA added points increment points++; // Tests repetitive addition t211 = new EditTree(""); for (int i = 0; i < s3.length(); i++) t211.add(s3.charAt(i)); assertEquals(s3, t211.toString()); points += 1; } @Test(timeout = 2000) // Tests the add method for inserting characters at places besides the end. // (The add method with two parameters) public void testAdd2_21() { t215 = new EditTree("shortstring"); // CWA: changed 4 to 5 t215.add(' ', 5); assertEquals(s1, t215.toString()); t216 = new EditTree("hort string"); // CWA: Changed -1 to 0 in several places below t216.add('s', 0); assertEquals(s1, t216.toString()); t217 = new EditTree(" moderately short string"); t217.add('a', 0); assertEquals(s2, t217.toString()); t218 = new EditTree("a" + "moderately short string"); //CWA: changed 0 to 1 t218.add(' ', 1); assertEquals(s2, t218.toString()); t219 = new EditTree(""); // Tests repetitive adding. for (int i = s3.length() - 1; i >= 0; i--) t219.add(s3.charAt(i), 0); assertEquals(s3, t219.toString()); points += 1; } @Test(timeout = 2000) // Tests that the add method throws a correct error if out of bounds public void testAddException_21() throws Exception { try { t210.add('x', 25); fail("Add method did not throw IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException exception) { points += 1; } } @Test(timeout = 2000) // Tests the delete method that removes a single character from the tree public void testDelete_21() { t210.delete(5); assertEquals("shortstring", t210.toString()); t211.delete(1); assertEquals("amoderately short string", t211.toString()); t212.delete(0); assertEquals("his string is not as short as the others", t212 .toString()); // Tests repetitive deletion while (t210.size() > 0) { t210.delete(0); } assertEquals("", t210.toString()); points += 1; } // removed by CWA. Team 21 was confused about second arguemnt of delete, // which is supposed to be the length of the deleted string // @Test(timeout = 2000) // // Tests the delete method that removes a substring from the tree // public void testDelete2_21() { // t210.delete(5, t210.size() - 1); // assertEquals("short", t210.toString()); // t210.delete(0, t210.size()); // assertEquals("", t210.toString()); // t211.delete(0, 13); // assertEquals(s1, t211.toString()); // t211.delete(1, t211.size()); // assertEquals("a", t211.toString()); // // points += 1; // } @Test(timeout = 2000) // Tests that the delete method throws a correct error if out of bounds public void testDeleteException_21() throws Exception { try { t210.delete(25); fail("Delete method did not throw IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException exception) { points += 1; } } @Test(timeout = 2000) // Tests that the second delete method throws the proper error public void testDeleteException2_21() throws Exception { try { t210.delete(2, 25); fail("Delete method did not throw IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException exception) { points += 1; } } @Test(timeout = 2000) // Tests the concatenate method that appends a string-tree. public void testConcatenate_21() { t215 = new EditTree("string"); t216 = new EditTree("short "); t216.concatenate(t215); assertEquals(s1, t216.toString()); assertEquals(0, t215.size()); t217 = new EditTree("st"); t218 = new EditTree("short "); t219 = new EditTree("ring"); t217.concatenate(t219); assertEquals("string", t217.toString()); t218.concatenate(t217); assertEquals(s1, t218.toString()); assertEquals(0, t217.size()); assertEquals(0, t219.size()); points += 1; } @Test(timeout = 2000) // Tests that the concatenate method throws the correct exception public void testConcatenateException_21() throws Exception { try { t210.concatenate(t210); fail("Concatenate method did not throw IllegalArgumentException."); } catch (IllegalArgumentException exception) { points += 1; } } @Test(timeout = 2000) public void testFind_21() { // Tests the find method that finds the first instance of a substring assertEquals(s1.indexOf(" st"), t210.find(" st")); assertEquals(s1.indexOf("short"), t210.find("short")); assertEquals(s1.indexOf("hi"), t210.find("hi")); assertEquals(s2.indexOf("a"), t211.find("a")); assertEquals(s2.indexOf("er"), t211.find("er")); assertEquals(s2.indexOf("ello"), t211.find("ello")); assertEquals(s3.indexOf(" is "), t212.find(" is ")); assertEquals(s3.indexOf("hello"), t212.find("hello")); points += 1; } @Test(timeout = 2000) public void testFind2_21() { // Tests the find method that finds the first instance of a substring // after a given starting position assertEquals(s1.indexOf(" st", 4), t210.find(" st", 4)); assertEquals(s1.indexOf("hort", 0), t210.find("hort", 0)); assertEquals(s1.indexOf("hi", 2), t210.find("hi", 2)); assertEquals(s2.indexOf("moderately", 0), t211.find("moderately", 0)); assertEquals(s2.indexOf("short", 7), t211.find("short", 7)); assertEquals(s2.indexOf("moderately", 5), t211.find("moderately", 5)); assertEquals(s2.indexOf("foo", 0), t211.find("foo", 0)); points += 1; } // CWA: Replaced it by a new version from the same team. @Test(timeout = 2000) // Tests the split method that cuts the tree into two subtrees at a given // index. public void testSplit_21() { t215 = t210.split(5); assertEquals("short", t210.toString()); assertEquals(" string", t215.toString()); t211 = t210.split(0); assertEquals("", t210.toString()); assertEquals("short", t211.toString()); try { t212 = t211.split(6); fail("Should have thrown IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) {} points += 1; } @Test(timeout = 2000) // Tests the split method throws the proper exception public void testSplitException_21() { try { t210.split(-1); fail("Split method did not throw IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException exception) { points += 1; } } @Test(timeout = 2000) // Tests the split method throws the proper exception public void testSplitException2_21() { try { t210.split(25); fail("Split method did not throw IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException exception) { points += 1; } } // CWA: removed. Get does not return a node. // @Test(timeout = 2000) // // Tests that the get method actually returns the Node at a given position // public void testGet_21() { // // i goes from 0 to the length of the shortest string // for (int i = 0; i < Math.min(s1.length(), Math.min(s2.length(), Math // .min(s3.length(), Math.min(s4.length(), s5.length())))); i++) { // // assertEquals(s1.charAt(i), t210.get(i).element); // assertEquals(s2.charAt(i), t211.get(i).element); // assertEquals(s3.charAt(i), t212.get(i).element); // assertEquals(s4.charAt(i), t213.get(i).element); // assertEquals(s5.charAt(i), t214.get(i).element); // } // points += 1; // } @Test(timeout = 2000) // Tests that the get method throws an exception when index is out of bounds public void testGetException_21() { try { t210.get(25); fail("Get method did not throw IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException exception) { points += 1; } } @Test(timeout = 2000) // Tests that the get method throws an exception when length is out of // bounds public void testGetException2_21() { try { t210.get(2, 25); fail("Get method did not throw IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException exception) { points += 1; } } //--------------------- TEAM 22 tests ---------------------- /*Tests sizes on all the trees.*/ @Test(timeout = 1000) public void testSize_22() { assertEquals(0, t220.size()); assertEquals(1, t221.size()); assertEquals(2, t222.size()); assertEquals(3, t223.size()); assertEquals(s1.length(), t224.size()); assertEquals(s2.length(), t225.size()); assertEquals(s3.length(), t226.size()); assertEquals(s4.length(), t227.size()); assertEquals(3, t228.size()); assertEquals(9, t229.size()); points += 1; } /* * Tests add position on "hlo" by adding the e and the l to make the tree * "hello". Should demonstrate a push right and a add right, which are the * two ways we add at a position */ @Test(timeout = 1000) public void testAddPosition_22() { t228.add('e', 1); t228.add('l', 3); assertEquals("hello", t228.toString()); points += 1; } /*Tests delete by restoring t228 ("hlo") to its initial state. Tests delete on other trees as well.*/ //TODO: Work on this one @Test(timeout = 1000) public void testAddDelete_22(){ t228.add('e', 1); t228.add('l', 3); t228.delete(3); t228.delete(1); assertEquals("hlo", t228.toString()); points += 1; } //Tests that a deletion on a null tree throws an exception @Test public void testNullDelete_22(){ try { t220.delete(1); fail("cannot delete from empty tree"); } catch(IndexOutOfBoundsException e) { points += 1; } } //Tests that out of bounds deletes yell at you properly @Test public void testOutOfBoundsDelete_22(){ // CWA: Removed the +1 from the next statement try { t227.delete(s4.length()); fail("delete position past end of tree"); } catch(IndexOutOfBoundsException e) { points += 1; } } //Tests duplicate by duplicating th posen calling .equals() on the root node of each @Test public void testDuplicateConstructor_22(){ //Test tree with stuff in it EditTree duplicate = new EditTree(t227); assertTrue(duplicate.toString().equals(t227.toString())); //Test null tree EditTree duplicate2 = new EditTree(t220); assertTrue(duplicate2.toString().equals(t220.toString())); points += 1; } @Test(timeout = 1000) public void testDelete_22(){ assertEquals('a',t221.delete(0)); assertEquals("",t221.toString()); assertEquals('b',t222.delete(1)); assertEquals("a",t222.toString()); assertEquals('c',t223.delete(2)); assertEquals("ab",t223.toString()); assertEquals('r',t224.delete(8)); assertEquals("short sting",t224.toString()); assertEquals('d',t225.delete(4)); assertEquals("a moerately short string",t225.toString()); assertEquals('o',t226.delete(16)); assertEquals("This string is nt as short as the others",t226.toString()); assertEquals(',',t227.delete(15)); assertEquals("This is a great big, juicy, longer-than-the-others, string",t227.toString()); points += 1; } @Test(timeout = 1000) public void testGet_22(){ assertEquals('a',t221.get(0)); assertEquals('b',t222.get(1)); assertEquals('b',t223.get(1)); assertEquals('o',t224.get(2)); assertEquals('e',t225.get(9)); assertEquals(' ',t226.get(21)); assertEquals('g',t227.get(19)); points += 1; } @Test(timeout = 1000) public void testGet2_22(){ assertEquals("ab",t222.get(0,2)); assertEquals("bc",t223.get(1,2)); assertEquals("ort",t224.get(2,3)); // CWA: It appears that you assumed that the modification from a previous est case would still be there. assertEquals("ate",t225.get(7,3)); assertEquals(" short as the", t226.get(21,13)); assertEquals("",t227.get(19,0)); points += 1; } //Check actual lengths on this one. @Test(timeout = 1000) public void testLengthDelete_22(){ assertEquals("strin", t224.delete(7, 5)); points++; } // removed by CWA. Lots of other tests test toString() // @Test(timeout = 1000) // public void testToString_22(){ // assertEquals("", t220.toString()); // assertEquals("a", t221.toString()); // assertEquals("ab", t222.toString()); // assertEquals("abc", t223.toString()); // assertEquals(s1, t224.toString()); // assertEquals(s2, t225.toString()); // assertEquals(s3, t226.toString()); // assertEquals(s4, t227.toString()); // assertEquals("hlo", t228.toString()); // assertEquals(s5, new EditTree(s5)); // points++; // } @Test (timeout = 1000) public void testConcatenate_22(){ t220.concatenate(t221); assertEquals("a",t220.toString()); t224.concatenate(t225); assertEquals(s1+s2,t224.toString()); t224.concatenate(t226); assertEquals(s1+s2+s3, t224.toString()); t224.concatenate(t227); assertEquals(s1+s2+s3+s4,t224.toString()); points++; } @Test (timeout = 1000) public void testSplit_22(){ assertEquals(s1.substring(5),t224.split(5).toString()); assertEquals(s2.substring(10),t225.split(10).toString()); assertEquals(s3.substring(15),t226.split(15).toString()); assertEquals(s4.substring(20),t227.split(20).toString()); assertEquals(s5.substring(30),new EditTree(s5).split(30).toString()); points++; } @Test(timeout = 3000) public void testFind_22(){ assertEquals(-1,t220.find("Secrets of Life")); assertEquals(0,t221.find("a")); assertEquals(1,t222.find("b")); assertEquals(s1.indexOf("string"),t224.find("string")); assertEquals(s2.indexOf("moderate"),t225.find("moderate")); assertEquals(s2.indexOf("moderate",10),t225.find("moderate",10)); assertEquals(s3.indexOf("short"),t226.find("short")); assertEquals(s4.indexOf("is"),t227.find("is")); assertEquals(s4.indexOf("is",4),t227.find("is",4)); points++; } //--------------------- TEAM 23 tests ---------------------- @Test(timeout = 1000) public void testAdd1_23() { this.t230.add('a'); assertEquals("a", this.t230.toString()); this.t230.add('b'); assertEquals("ab", this.t230.toString()); this.t230.add('c'); assertEquals("abc", this.t230.toString()); assertEquals(3, this.t230.size()); EditTreeTest.points++; } @Test(timeout = 1000) public void testAdd2_23() { this.t230.add('a', 0); assertEquals("a", this.t230.toString()); this.t230.add('b', 0); assertEquals("ba", this.t230.toString()); this.t230.add('c', 2); assertEquals("bac", this.t230.toString()); this.t230.add('d', 2); assertEquals("badc", this.t230.toString()); this.t230.add('e', 1); assertEquals("beadc", this.t230.toString()); assertEquals(5, this.t230.size()); EditTreeTest.points++; } // removed by CWA. See note in setUp_23(). // @Test(timeout = 1000) // public void testDelete1_23() { // try { // this.t230.delete(-1); // fail("Failed to throw IndexOutOfBoundsException"); // } catch (IndexOutOfBoundsException exception) { // // Do nothing. // } // try { // this.t230.delete(1); // fail("Failed to throw IndexOutOfBoundsException"); // } catch (IndexOutOfBoundsException exception) { // // Do nothing. // } // // Tested IndexOutOfBounds // // this.t231.delete(0); // assertEquals("", this.t231.toString()); // this.t232.delete(0); // assertEquals("c", this.t232.toString()); // this.t234.delete(2); // assertEquals("gf", this.t234.toString()); // assertEquals(2, this.t234.size()); // // this.t234.delete(0); // assertEquals("f", this.t234.toString()); // assertEquals(1, this.t234.size()); // // EditTreeTest.points++; // } // removed by CWA. See note in setUp_23(). @Test(timeout = 1000) public void testConcatenate_23() { EditTree t1 = new EditTree(); this.t230.concatenate(t1); assertEquals("", this.t230.toString()); // Tested null-null concatenation this.t230.concatenate(this.t231); // CWA: t231 gets emptied by this assertEquals("a", this.t230.toString()); // Tested null-filled concatenation this.t231.concatenate(t1); // CWA: Changed "a" to "" assertEquals("", this.t231.toString()); // Tested filled-null concatenation EditTree t2 = new EditTree('z'); this.t230.concatenate(t2); assertEquals("az", this.t230.toString()); EditTree t3 = new EditTree('a'); t3.add('b', 0); t3.add('c'); t3.add('d', 0); t3.add('e', 2); t3.add('f', 4); t3.add('g'); EditTree t4 = new EditTree('h'); t4.add('i', 0); t4.add('j'); t4.add('k', 0); t4.add('l', 2); t4.add('m', 4); t4.add('n'); t3.concatenate(t4); assertEquals("dbeafcgkilhmjn", t3.toString()); assertEquals(14, t3.size()); assertTrue(t3.height() <= 4 ); // Tested a larger tree. Made sure more information was accounted for. // Write a test that checks balancing if there is time. EditTreeTest.points++; } // removed by CWA. Assumes a particular internal representation of the tree. // And also builds a tree without setting the rank and balance fields of the nodes. // @Test(timeout = 1000) // public void testSplit_23() { @Test(timeout = 1000) public void testHeight_23() { EditTree t1 = new EditTree('a'); t1.add('c'); t1.add('d'); assertEquals(1, t1.height()); EditTree t2 = new EditTree('r'); assertEquals(0, t2.height()); assertEquals(-1, this.t230.height()); EditTreeTest.points++; } @Test(timeout = 1000) public void testSize_23() { EditTree t1 = new EditTree('a'); t1.add('c'); t1.add('d'); assertEquals(3, t1.size()); EditTree t2 = new EditTree('r'); assertEquals(1, t2.size()); assertEquals(0, this.t230.size()); EditTreeTest.points++; } @Test(timeout = 1000) public void testToString_23() { EditTree t1 = new EditTree("abc"); assertEquals("abc", t1.toString()); // from the string constructor for editTree assertEquals("", this.t230.toString()); // null tree EditTree t2 = new EditTree('a'); assertEquals("a", t2.toString()); // one character tree EditTreeTest.points++; } @Test(timeout = 1000) public void testConstructor1_23() { EditTree t1 = new EditTree(""); assertEquals("", t1.toString()); EditTree t2 = new EditTree("a"); assertEquals("a", t2.toString()); EditTree t3 = new EditTree("abc"); assertEquals("abc", t3.toString()); EditTreeTest.points++; } @Test(timeout = 1000) public void testConstructor2_23() { EditTree t1 = new EditTree(); assertEquals("", t1.toString()); EditTreeTest.points++; } @Test(timeout = 1000) public void testConstructor3_23() { EditTree t1 = new EditTree('a'); t1.add('c'); t1.add('d'); EditTree t2 = new EditTree(t1); assertEquals(t1.toString(), t2.toString()); EditTreeTest.points++; } @Test(timeout = 1000) public void testSingleLeft_23() { EditTree t1 = new EditTree('a'); t1.add('b'); t1.add('c'); assertEquals("abc", t1.toString()); assertEquals(1, t1.height()); // Single rotate left about root t1.add('d'); t1.add('e'); assertEquals("abcde", t1.toString()); assertEquals(2, t1.height()); // Second rotate about a non-root node EditTreeTest.points++; } @Test(timeout = 1000) public void testSingleRight_23() { EditTree t1 = new EditTree('a'); t1.add('b', 0); t1.add('c', 0); assertEquals("cba", t1.toString()); assertEquals(1, t1.height()); // Single rotate right about root t1.add('d', 0); t1.add('e', 0); assertEquals("edcba", t1.toString()); assertEquals(2, t1.height()); // Second rotate about a non-root node EditTreeTest.points++; } @Test(timeout = 1000) public void testDoubleLeft_23() { EditTree t1 = new EditTree('a'); t1.add('b', 1); t1.add('c', 1); assertEquals("acb", t1.toString()); assertEquals(1, t1.height()); // double rotate left about root t1.add('d', 3); t1.add('e', 3); assertEquals("acbed", t1.toString()); assertEquals(2, t1.height()); // Second rotate about a non-root node EditTreeTest.points++; } @Test(timeout = 1000) public void testDoubleRight_23() { EditTree t1 = new EditTree('a'); t1.add('b', 0); t1.add('c', 1); assertEquals("bca", t1.toString()); assertEquals(1, t1.height()); // double rotate right about root t1.add('d', 0); t1.add('e', 1); assertEquals("debca", t1.toString()); assertEquals(2, t1.height()); // Second rotate about a non-root node EditTreeTest.points++; } //--------------------- TEAM 24 tests ---------------------- @Test(timeout = 1000) public void testAdd_24() { t240.add('a'); assertEquals(1, t240.size()); assertEquals('a', t240.get(0)); t240.add('b'); assertEquals('b', t240.get(1)); assertEquals(2, t240.size()); t240.add('c'); //assertEquals(true, t240.isHeightBalanced()); points++; System.out.println(" points = " + points); } @Test(timeout = 1000) public void testAdd2_24() { t248.add('$'); assertEquals('$', t248.get(s5.length())); // assertTrue(t248.isHeightBalanced()); points += 1; System.out.println(" points = " + points); } @Test(timeout = 1000) public void testAddPos_24() { t242.add('&', 3); assertEquals('&', t242.get(3)); //assertTrue(t242.isHeightBalanced()); points++; System.out.println(" points = " + points); } @Test(timeout = 1000) public void testAddPos2_24() { t244.add('w', 0); //assertTrue(t244.isHeightBalanced()); assertEquals('w', t244.get(0)); points += 1; System.out.println(" points = " + points); } @Test(timeout = 1000) public void testAddPos3_24() { t248.add('q', s5.length() - 1); //assertTrue(t248.isHeightBalanced()); assertEquals('q', t248.get(s5.length()-1)); points += 1; System.out.println(" points = " + points); } @Test(timeout = 1000) public void testToString_24() { assertEquals("", t240.toString()); assertEquals("a", t241.toString()); assertEquals("this is sparta!", t242.toString()); assertEquals("!@#$%^&*", t243.toString()); assertEquals(s1, t244.toString()); assertEquals(s2, t245.toString()); assertEquals(s3, t246.toString()); assertEquals(s4, t247.toString()); assertEquals(s5, t248.toString()); assertEquals("this is a combined string.", t249.toString()); points++; System.out.println(" points = " + points); } @Test(timeout = 1000) public void testGetException_24() { try { assertEquals("", t240.get(10)); fail(); } catch (IndexOutOfBoundsException e) { assertTrue(true); points += 1; System.out.println(" points = " + points); } } @Test(timeout = 1000) public void testGet_24() { assertEquals('a', t241.get(0)); assertEquals('p', t242.get(9)); assertEquals('$', t243.get(3)); assertEquals('h', t244.get(1)); assertEquals('y', t245.get(11)); assertEquals(' ', t246.get(14)); assertEquals(',', t247.get(15)); assertEquals('\'', t248.get(7)); assertEquals('c', t249.get(10)); points += 1; System.out.println(" points = " + points); } @Test(timeout = 1000) public void testDeleteException_24() { try { t240.delete(0); fail(); } catch (IndexOutOfBoundsException e) { assertTrue(true); points += 1; System.out.println(" points = " + points); } } // removed by CWA. The size of a tree can never be -1. // @Test(timeout = 1000) // public void testDelete_24() { // // t241.delete(0); // assertEquals(-1, t241.size()); // points += 1; // System.out.println(" points = " + points); // } @Test(timeout = 1000) public void testDelete2_24() { t242.delete(0); //assertTrue(t242.isHeightBalanced()); assertEquals(14, t242.size()); t242.delete(t242.size() - 1); assertEquals('a', t242.get(t242.size() - 1)); //assertTrue(t242.isHeightBalanced()); t242.delete(7); assertFalse('s' == t242.get(7)); assertEquals('p', t242.get(7)); //assertTrue(t242.isHeightBalanced()); points += 1; System.out.println(" points = " + points); } @Test(timeout = 1000) public void testConcatenate_24() { int size1, size2; size1 = t242.size(); size2 = t243.size(); t242.concatenate(t243); assertEquals(size1 + size2, t242.size()); //assertTrue(t242.isHeightBalanced()); assertEquals('t', t242.get(0)); assertEquals('*', t242.get(t242.size() - 1)); points += 1; System.out.println(" points = " + points); } @Test(timeout = 1000) public void testConcatenate2_24() { int size1, size2; size1 = t248.size(); size2 = t247.size(); t248.concatenate(t247); assertEquals(size1 + size2, t248.size()); //assertTrue(t248.isHeightBalanced()); assertEquals('Y', t248.get(0)); assertEquals('g', t248.get(t248.size() - 1)); points += 1; System.out.println(" points = " + points); } @Test(timeout = 1000) public void testConcatenateException_24() { try { t244.concatenate(t244); fail(); } catch (IllegalArgumentException e) { assertTrue(true); points += 1; System.out.println(" points = " + points); } } @Test(timeout = 1000) public void testSplitExceptions_24() { try { t240.split(0); fail(); } catch (IndexOutOfBoundsException e) { assertTrue(true); } try { t240.split(1); fail(); } catch (IndexOutOfBoundsException e) { assertTrue(true); points += 1; } System.out.println(" points = " + points); } @Test(timeout = 1000) public void testSplit_24() { EditTree newTree = t242.split(4); //assertTrue(t242.isHeightBalanced()); //assertTrue(newTree.isHeightBalanced()); assertEquals(4, t242.size()); assertEquals('s', t242.get(3)); assertEquals(11, newTree.size()); assertEquals(' ', newTree.get(0)); points += 1; System.out.println(" points = " + points); } @Test(timeout = 1000) public void testDeleteRangeException_24() { try { t240.delete(0, 5); fail(); } catch (IndexOutOfBoundsException e) { assertTrue(true); } try { t241.delete(0, 2); fail(); } catch (IndexOutOfBoundsException e) { assertTrue(true); points += 1; } System.out.println(" points = " + points); } @Test(timeout = 1000) public void testDeleteRange_24() { t241.delete(0, 1); assertEquals(0, t241.size()); t245.delete(2, 4); //CWA: Replaced 't' by 'r' assertEquals('r', t245.get(2)); //assertTrue(t245.isHeightBalanced()); points += 1; System.out.println(" points = " + points); } @Test(timeout = 1000) public void testDeleteRange2_24() { t248.delete(0, t248.size()); assertEquals(0, t248.size()); points += 1; System.out.println(" points = " + points); } //--------------------- TEAM 25 tests ---------------------- @Test(timeout=1000) public void testSize0_25(){ assertEquals(0, t250.size()); points += 1; } @Test(timeout=1000) public void testSize1_25(){ assertEquals(1, t251.size()); points += 1; } @Test(timeout=1000) public void testSize2_25(){ assertEquals(3, t252.size()); points += 1; } // ERG: Removed tests that access nodes - implementation dependant // @Test(timeout=1000) // public void testSingleLeft_25(){ // t255.add('t'); // assertEquals(t255.getRoot().element, 'f'); // reinitialize5(); // points += 1; // } // // @Test(timeout=1000) // public void testSingleRight_25(){ // t256.add('r', 0); // assertEquals(t255.getRoot().element, 'i'); // reinitialize6(); // points += 1; // } // // @Test(timeout=1000) // public void testDoubleLeft_25(){ // t255.add('f', 1); // assertEquals(t255.getRoot().element, 'f'); // points += 1; // } // // @Test(timeout=1000) // public void testDoubleRight_25(){ // t256.add('g', 1); // assertEquals(t255.getRoot().element, 'g'); // points += 1; // } @Test(timeout=1000) public void testToString2_25(){ assertEquals("cab", t252.toString()); points += 1; } @Test(timeout=1000) public void testToString3_25(){ assertEquals("aperson", t253.toString()); points += 1; } @Test(timeout=1000) public void testDelete1_25(){ assertInOrder(2,t253.height(),3); assertEquals(7, t253.size()); assertEquals('a', t253.delete(0)); assertEquals(2, t253.height()); assertEquals(6, t253.size()); points += 1; } @Test(timeout=1000) public void testToString4_25(){ // ERG: Trees are reinitialized between tests t253.delete(0); assertEquals("person", t253.toString()); points += 1; } @Test(timeout=1000) public void testDelete2_25(){ // ERG: again, trees are reinitialized between tests t253.delete(0); assertEquals('e', t253.delete(1)); assertEquals('s', t253.delete(2)); t253.add('e'); assertEquals("prone",t253.toString()); points += 1; } // ERG: if you were asked to implement it, you could have used the .clone() method // // @Test(timeout=1000) // public void testNoChange_25(){ // // I don't know for sure if this is a way to compare a tree to its past // // self, but if not then I don't know how to test this case. Also the // // equals method needs to be implemented first. // assertEquals(t254, addDel(t254)); // points += 1; // } // // private EditTree addDel(EditTree t) { // // Used only in testNoChange_25() // t.add('s', 0); // t.delete(0); // return t; // } // // @Test(timeout=1000) // public void testChange_25(){ // assertFalse(t254.equals(delAdd(t254))); // points += 1; // } // // private EditTree delAdd(EditTree t) { // // Used only in testChange_25() // t.delete(0); // t.add('c', 0); // return t; // } // // ERG: too many changes to repeat them here // @Test(timeout=1000) // public void testStringConstructorAndConcatenate1_25(){ // t254.concatenate(new EditTree("ball")); // assertEquals("football",t254.toString()); // assertTrue(t254.isHeightBalanced()); // points += 1; // } // //ERG: the exception occurs if you pass the same tree as in t254.concatenate(t254); // @Test(timeout=1000,expected=IllegalArgumentException.class) // public void testConcatenateException1_25(){ // t254.concatenate(new EditTree("football")); // points += 1; // } // // @Test(timeout=1000,expected=IndexOutOfBoundsException.class) // public void testSplitException1_25(){ // t254.split(8); // points += 1; // } // // @Test(timeout=1000) // public void testSplit1_25(){ // EditTree temp = t254.split(4); // assertEquals("foot",t254.toString()); // assertEquals("ball",temp.toString()); // assertTrue(t254.isHeightBalanced()); // assertTrue(temp.isHeightBalanced()); // points += 1; // } // // @Test(timeout=1000) // public void testGet1_25(){ // assertEquals('3', t257.get(6)); // points += 1; // } // // @Test(timeout=1000) // public void testGet2_25(){ // assertEquals('a', t252.get(0)); // points += 1; // } //--------------------- TEAM 26 tests ---------------------- @Test(timeout = 1000) public void testSize_26(){ assertEquals(0,t260.size()); assertEquals(12,t261.size()); assertEquals(25,t262.size()); } @Test(timeout = 1000) public void testHeight_26(){ assertEquals(-1,t260.height()); // ERG: could be not as well balanced, allowing for height 4 assertInOrder(3,t261.height(),4); assertEquals(4,t262.height()); } @Test(timeout = 1000) public void testString_26() { assertEquals("", t260.toString()); assertEquals("short string", t261.toString()); assertEquals("a moderately short string", t262.toString()); } @Test(timeout = 1000) public void testSizeAfterConcat_26() { assertEquals(0, t265.size()); t265.concatenate(t261); // ERG: concatenate should clear the other tree assertEquals(t261.size(),0); assertEquals(t265.size(),12); } @Test(timeout = 1000) public void testHeightAfterConcat_26() { t265.concatenate(t261); t265.concatenate(t262); // ERG: could also be height 6 assertInOrder(5,t265.height(),6); } @Test(timeout = 1000) public void testGet_26() { System.out.println(t263.get(39) + ", " + t263.toString()); assertEquals('o', t261.get(2)); assertEquals('a', t262.get(0)); assertEquals('s', t263.get(40)); } @Test(timeout = 1000) public void testInsert_26() { t261.add('x'); t262.add('x', 0); assertEquals("short stringx", t261.toString()); assertEquals("xa moderately short string", t262.toString()); } @Test(timeout = 1000) public void testDeleteOne_26() { t261.delete(0); assertEquals(11, t261.size()); for (int i = 0; i < 4; i++) t261.delete(0); assertEquals(7, t261.size()); // ERG height could never be 1, but it could be 2 or 3 assertInOrder(2,t261.height(),3); } @Test(timeout = 1000) public void testDeleteMany_26() { t261.delete(0, 5); assertEquals(7, t261.size()); // ERG see deleteone assertInOrder(2,t261.height(),3); } //--------------------- EMILY's tests ---------------------- public void testEmptyConstruct_i(){ ti0=new EditTree(""); assertEquals(0,ti0.size()); assertEquals(-1,ti0.height()); points+=1; } public void testAdd_i(){ ti1=new EditTree(""); try{ ti1.add('a',1); fail(); }catch(IndexOutOfBoundsException e){ assertEquals(0,ti1.size()); assertEquals(-1,ti1.height()); points+=1; } ti1.add('a'); assertEquals(1,ti1.size()); assertEquals(0,ti1.height()); points+=1; } public void testDelete_i(){ ti2=new EditTree("01234567890123456789"); ti2.delete(5); assertEquals("0123467890123456789",ti2.toString()); points+=1; } public void testSplit_i(){ ti3=new EditTree('a'); ti4=ti3.split(1); assertEquals(1,ti3.size()); assertEquals(0,ti4.size()); ti5=ti3.split(0); assertEquals(0,ti3.size()); assertEquals(1,ti5.size()); points+=1; } public void testConcatenate_i(){ ti6=new EditTree(); ti6.concatenate(new EditTree()); assertEquals(0,ti6.size()); ti6.concatenate(new EditTree('a')); assertEquals(1,ti6.size()); ti6.concatenate(new EditTree()); assertEquals(1,ti6.size()); points+=1; } //--------------------- ANDREW's tests ---------------------- @Test(timeout=1000) public void TestStringConstructor_is(){ //ta siegle ti7 = new EditTree("Andrew"); ti7.add('L'); assertEquals("L",ti7.get(6, 1)); points += 1; } @Test(timeout=1000) public void TestMultipleRemoves_is(){ ti7 = new EditTree("thedecadekeepsisolatinglife"); ti7.delete(25,1); ti7.delete(19,4); ti7.delete(16,2); ti7.delete(11,3); ti7.delete(7,2); ti7.delete(3,2); assertEquals("thecakeisalie",ti7.get(0,13)); points += 1; } @Test(timeout=1000) public void TestSplit_is(){ ti7 = new EditTree("csse230032essc"); ti8 = ti7.split(7); assertEquals("csse230",ti7.get(0,ti7.size())); assertEquals("032essc",ti8.get(0,ti8.size())); points += 1; } @Test(timeout=1000) public void TestConcatinateAndSplit_is(){ String str = "Lorem Ipsum"; ti7 = new EditTree(str); for (int i = 0; i < str.length();i++){ ti8 = ti7.split(i); ti7.concatenate(ti8); assertEquals("Lorem Ipsum",ti7.get(0,ti7.size())); } points += 1; } @Test(timeout=1000) public void TestComplex_is(){ ti7 = new EditTree("2"); ti8 = new EditTree("+"); ti8.add('2', 0); ti8.concatenate(ti7); ti8.concatenate(new EditTree("=")); assertEquals("2+2=4",ti8.get(0,ti8.size()) + new Integer(ti8.size()).toString()); points += 1; } @Test(timeout=1000) public void TestMaxHeightwAdd_is(){ ti7 = new EditTree("Andrew"); ti7.add('e',0); ti7.add('l',0); ti7.add('g',0); ti7.add('e',0); ti7.add('i',0); assertTrue(ti7.height() <= 3); ti7 = new EditTree ("Andrew"); ti7.add('S'); ti7.add('i'); ti7.add('e'); ti7.add('g'); ti7.add('l'); ti7.add('e'); assertTrue(ti7.height() <= 4); points += 1; } @Test(timeout=1000) public void TestMaxHeightwConcat_is(){ ti7 = new EditTree("Rose-"); ti7.concatenate(new EditTree("Hulman")); assertTrue(ti7.height() <= 4); points += 1; } //--------------------- Claude's tests ---------------------- // I gave extra points to some of them. @Test(timeout=1000) public void TestHeightAfterDelete_i(){ ti0 = new EditTree("February 2"); ti0.add('8',8); ti0.add('7', 10); ti0.add('6', 3); ti0.add('5', 12); ti0.add('4', 14); ti0.delete(4); ti0.delete(4); ti0.delete(4); ti0.delete(4); assertTrue(ti0.height() <= 3); assertEquals(11, ti0.size()); points += 4; } @Test(timeout=1000) public void TestHeightAfterEndAdds_i(){ ti1 = new EditTree(); for (char c='a'; c<='o'; c++ ) ti1.add(c); assertEquals(3,ti1.height()); points += 3; } @Test(timeout=1000) public void checkHeights_i () { assertTrue((new EditTree(s1).height() <= 4)); assertTrue((new EditTree(s2).height() <= 5)); assertTrue((new EditTree(s3).height() <= 5)); assertTrue((new EditTree(s2+s4).height() <= 7)); assertTrue((new EditTree(s5).height() <= 8)); points +=3; } @Test(timeout=1000) public void checkHeightsAfterMultiplrConcat_i () { ti1 = new EditTree(s1); ti1.concatenate(new EditTree(s2)); ti1.concatenate(new EditTree(s2)); ti1.concatenate(new EditTree(s2)); assertEquals(s1+s2+s2+s2, ti1.toString()); assertTrue(ti1.height() <= 7); //Only 87 nodes, height cannot be 8. points +=5; ti2 = ti1.split(s1.length() + s2.length() + 1); assertEquals((s2+s2).substring(1), ti2.toString()); points += 5; } @Test public void theBigTestWithSpecificRotations_i() { EditTree t = new EditTree(); t.add('m'); t.add('y'); t.add('r', 1); // double left at m, height = 1, mry assertEquals(1, t.height()); assertEquals("mry", t.toString()); points += 1; t.add('s',2); t.add('P', 0); t.add('K', 0); // single right at m, height = 2, KPmrsy assertEquals(2, t.height()); assertEquals("KPmrsy", t.toString()); points += 1; t.add('b', 2); t.add('o', 4); t.add('Z', 2); // double left at P, height = 3 KPZbmorsy assertEquals(3, t.height()); assertEquals("KPZbmorsy", t.toString()); points += 1; t.add('V', 2); // single right at r, height = 3; KPVZbmorsy, b is now the root assertEquals(3, t.height()); assertEquals("KPVZbmorsy", t.toString()); points += 1; t.add('W', 3); // double right at X, height = 3 KPVWZbmorsy assertEquals(3, t.height()); assertEquals("KPVWZbmorsy", t.toString()); points += 1; t.add('Y', 4); // single left at P, height = 3 KPVWYZbmorsy assertEquals(3, t.height()); assertEquals("KPVWYZbmorsy", t.toString()); points += 1; t.add('X', 4); // single right at Z, height = 3 KPVWXYZbmorsy assertEquals(3, t.height()); assertEquals("KPVWXYZbmorsy", t.toString()); points += 1; t.add('U', 2); // single right at W, height = 4 KPUVWXYZbmorsy assertEquals(4, t.height()); assertEquals("KPUVWXYZbmorsy", t.toString()); points += 1; t.add('C', 0); t.add('B', 0); //single right at K, height = 4 BCKPUVWXYZbmorsy assertEquals(4, t.height()); assertEquals("BCKPUVWXYZbmorsy", t.toString()); points += 1; t.add('M', 3); //single right at W, height = 4 BCKMPUVWXYZbmorsy assertEquals(4, t.height()); assertEquals("BCKMPUVWXYZbmorsy", t.toString()); points += 1; t.add('a', 11); // double right at b, height = 4 BCKMPUVWXYZabmorsy, W is now root assertEquals(4, t.height()); assertEquals("BCKMPUVWXYZabmorsy", t.toString()); points += 1; t.delete(12); // deletes b, height = 4 BCKMPUVWXYZamorsy assertEquals(4, t.height()); assertEquals("BCKMPUVWXYZamorsy", t.toString()); points += 3; t.delete(7); // deletes W, height = 4 BCKMPUVXYZamorsy assertEquals(4, t.height()); assertEquals("BCKMPUVXYZamorsy", t.toString()); points += 3; } @Test public void printSummary_i() { System.out.print("\n =============== "); System.out.print("Total points: "); System.out.print(points); System.out.println(" ==============="); } }