package editortrees; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import editortrees.Node.Code; 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; private Node n1; // 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 { } public void setUp14() throws Exception { } public void setUp15() throws Exception { } public void setUp16() throws Exception { } public void setUp21() throws Exception { } public void setUp22() throws Exception { } public void setUp23() throws Exception { } public void setUp24() throws Exception { } public void setUp25() throws Exception { } public void setUp26() throws Exception { } // The name of each of your team's tests should end with an underscore // followed by your team number, // for example, testSize3_13 if you are on team 13. // Make sure that each of your tests has a timeout. // The timeout should be 1 or 2 seconds unless your // test involves VERY complicated operations. // Each of your tests should be worth one point. // A sample test to remind you of the format: @Test // (timeout=1000) // one second public void testSize3_i() { // i is for instructor ti3 = new EditTree(s1); assertEquals(12, ti3.size()); points += 1; // only incremented if test passes. } @Test(timeout = 1000) // one second public void testaddnull_12() { // i is for instructor this.t112 = new EditTree(sNull); assertEquals("", t112.toString()); points += 1; // only incremented if test passes. } @Test(timeout = 1000) // one second public void testaddempty_12() { // i is for instructor t112 = new EditTree(sEmpty); assertEquals("", t112.toString()); points += 1; // only incremented if test passes. } @Test(timeout = 1000) // one second public void testOneChar_12() { // i is for instructor t112 = new EditTree(); t112.add('a'); assertEquals("a", t112.toString()); points += 1; // only incremented if test passes. } @Test(timeout = 1000) // one second public void testThreeChar_12() { // i is for instructor t112 = new EditTree("abc"); assertEquals("abc", t112.toString()); points += 1; // only incremented if test passes. } @Test // (timeout=1000) // one second public void testTenChar_12() { // i is for instructor 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; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestGetpos0_12() { // i is for instructor t112 = new EditTree("abc"); assertEquals('a', t112.get(0)); points += 1; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestGetpos1_12() { // i is for instructor t112 = new EditTree("abc"); assertEquals('b', t112.get(1)); points += 1; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestGetpos2_12() { // i is for instructor t112 = new EditTree("abc"); assertEquals('c', t112.get(2)); points += 1; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestTreesS1_12() { // i is for instructor this.t112 = new EditTree(s1); assertEquals('g', t112.get(t112.size() - 1)); assertEquals("short string", t112.toString()); assertEquals(4, t112.height()); points += 1; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestTreesAddspecificPosition_12() { // i is for instructor 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(""); assertEquals(5, t112.height()); points += 1; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestTreesAddspecificPositionBig_12() { // i is for instructor 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; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestTreesBIG_12() { // i is for instructor this.t112 = new EditTree(s5); assertEquals('.', t112.get(t112.size() - 1)); assertEquals(s5, t112.toString()); points += 1; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestDeleteSmall_12() { // i is for instructor 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; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestDeleteMedium_12() { // i is for instructor 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); // assertEquals(true, false); } catch (IndexOutOfBoundsException e) { assertEquals(true, true); } try { t112.delete(-2); // assertEquals(true, false); } catch (IndexOutOfBoundsException e) { assertEquals(true, true); } assertEquals("his string is not as short as te other", t112.toString()); points += 1; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestDeleteExtendSmall_12() { // i is for instructor this.t112 = new EditTree(s1); assertEquals("s", t112.delete(0, 1).toString()); assertEquals(11, t112.size()); assertEquals("t s", t112.delete(3, 3)); assertEquals(8, t112.size()); assertEquals("hortring", t112.toString()); try { t112.delete(11, 12); // assertEquals(true, false); } catch (IndexOutOfBoundsException e) { assertEquals(true, true); } points += 1; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestDeleteExtendLarge_12() { // i is for instructor this.t112 = new EditTree(s1); assertEquals(" you just might find you get the strings you need.", 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; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestSplitMedium_12() { // i is for instructor this.t112 = new EditTree(s3); assertEquals("s short as the others", t112.split(20).toString()); assertEquals(21, t112.size()); try { t112.split(100); // assertEquals(true, false); } catch (IndexOutOfBoundsException e) { assertEquals(true, true); } points += 1; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestSplitLong_12() { // i is for instructor this.t112 = new EditTree(s5); assertEquals( "ou try sometimes, you just might find you get the strings you need.", t112.split(52).toString()); assertEquals(67, t112.size()); points += 1; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestConcatSmall_12() { // i is for instructor 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; // only incremented if test passes. } @Test(timeout = 1000) // one second public void TestConcatLarge_12() { // i is for instructor 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; // only incremented if test passes. } }