Question: 1. /** * Inserts a string into a sorted list of strings, maintaining the sorted property of the list. * * @param s the string
1. /** * Inserts a string into a sorted list of strings, maintaining the sorted property of the list. * * @param s the string to insert * @param l a non-null, sorted list of strings */ public static void insertInOrder(String s, List
Here are the tests:
@Test public void testInsertInOrderEmpty() { List
@Test public void testInsertInOrderFirst() { List
@Test public void testInsertInOrderMiddle() { List
2./** * Splits a string into words, using whitespace to delimit the words. * * See the assignment writeup for the magic argument to split(). * * @param string a non-null string * @return an array representing the words in the string. */ public static String[] splitIntoWords(String string) {}
Here are the tests:
@Test public void testSplitThree() { assertArrayEquals(new String[] {"Larry", "Moe", "Curly"}, StringExercises.splitIntoWords("Larry Moe Curly ")); }
@Test public void testSplitOne() { assertArrayEquals(new String[] {"banana"}, StringExercises.splitIntoWords("banana")); }
3./** * Rotates the list right n places. * * Rotating a list right means moving the last item to the front of the list: * * 1, 2, 3, 4, 5 when rotated right once becomes 5, 1, 2, 3, 4 * * A list is rotated right two places as follows: * * 4, 5, 1, 2, 3 * * and so on. * * @param n the distance to rotate the list right */ public void rotateRight(int n) {}
Here are the test:
@Test public void testRotateRightEmpty() { empty.rotateRight(1); assertEquals(Arrays.asList(), empty); } @Test public void testRotateRightOne() { one.rotateRight(1); assertEquals(Arrays.asList(1), one); one.rotateRight(2); assertEquals(Arrays.asList(1), one); }
@Test public void testRotateRightOneTwo() { oneTwo.rotateRight(1); assertEquals(Arrays.asList(2,1), oneTwo); oneTwo.rotateRight(1); assertEquals(Arrays.asList(1,2), oneTwo); oneTwo.rotateRight(2); assertEquals(Arrays.asList(1,2), oneTwo); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
