package editortrees; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; 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."; /** * 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 { } public void setUp14() throws Exception { } public void setUp15() throws Exception { } 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 { } 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) 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(), "Th110is 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 testHeight_16() { assertEquals(t160.height(), 3); assertEquals(t161.height(), 4); assertEquals(t162.height(), 5); assertEquals(t163.height(), 5); assertEquals(t164.height(), 6); 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'); assertEquals(t160, "shrt string"); t160.delete(4); t160.delete(4); t160.delete(4); t160.delete(4); t160.delete(4); assertEquals(t160, "shring"); } @Test(timeout = 1000) public void testSplitSam_16() { assertEquals( t164.split(16), "get the strings you want, but if you try sometimes, you just might find you get the strings you need."); assertEquals(t160.split(5), " string"); } @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); assertEquals(t161, "a short string"); } @Test(timeout = 1000) public void testSingleRotationsDale_16() { EditTree test = new EditTree("SLIpPERY"); // single left test.add('x'); // single right test.add('D', 4); test.add('g', 4); assertEquals(test.toString(), "SLIpgDPERYx"); } @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); assertEquals(test.toString(), "SIHtgDpE"); EditTree test2 = new EditTree("SIpE"); test2.add('D',1); test2.add('g',1); test2.add('t',1); assertEquals(test2.toString(), "SDgtIpE"); } }