13. Avoid Aardvark

Google Presentation with all of the ArrayList in-class problems

  • ArrayList 5, page 12
public static void avoidAardvarks (ArrayList<String> data)

Testing

  • Include the boilerplate.

      import org.junit.*;
      import org.junit.runner.*;
      import static org.junit.Assert.*;
    
  • See code at the end of the presentation (linked above) if you prefer not to just “add” to results.

  • Recall: @Before and @Test must appear before functions, not statements.

  • Testing ArrayList is simplest if you use the toArray() method and assertArrayEquals.

@Test
public void simple_1() {
    String[] correct = { "yes" };
    
    ArrayList<String> data = new ArrayList<>();
    data.add("not");
    data.add("yet");

    avoidAardvarks(data);
    
    assertArrayEquals(correct, data.toArray());
}
Last modified August 18, 2023: 2022-2023 End State (7352e87)