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 thetoArray()
method andassertArrayEquals
.
@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());
}