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 l) { }

Here are the tests:

@Test public void testInsertInOrderEmpty() { List l = new ArrayList();; ListExercises.insertInOrder("Josh", l); assertEquals(Arrays.asList("Josh"), l); }

@Test public void testInsertInOrderFirst() { List l = new ArrayList(); l.add("Marc"); ListExercises.insertInOrder("Josh", l); assertEquals(Arrays.asList("Josh", "Marc"), l); }

@Test public void testInsertInOrderMiddle() { List l = new ArrayList(); l.add("Josh"); l.add("Marc"); ListExercises.insertInOrder("Lisa", l); assertEquals(Arrays.asList("Josh", "Lisa", "Marc"), l); } @Test public void testInsertInOrderEnd() { List l = new ArrayList(); l.add("Josh"); l.add("Lisa"); ListExercises.insertInOrder("Marc", l); assertEquals(Arrays.asList("Jos" + "666666666666h", "Lisa", "Marc"), l); }

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!