import static org.junit.Assert.*; import org.junit.Test; import java.util.ArrayList; /** * Tester for lab02 */ /** * @author rachelcardell-oliver * */ public class lab02Test { double delta = 0.00001; //error tolerance for doubles /** * Test method for normal case of {@link lab02#sum(double[])}. */ @Test public void testSumNormal() { double testarr[] = {0.5, 1.5, 0.3, -1.0, 43.0, 1.0}; assertEquals(45.3,lab02.sum(testarr),delta); } /** * Test method for boundary case of {@link lab02#sum(double[])}. * Question: or should this throw an exception */ @Test public void testSumEmpty() { double testarr[] = {}; assertEquals(0.0,lab02.sum(testarr),delta); } /** * Test method for exceptional case of {@link lab02#sum(double[])}. * when all values are negative */ @Test public void testSumNeg() { double testarr[] = {-1,-2,-3}; assertEquals(-6.0,lab02.sum(testarr),delta); } /** * Test method for {@link lab02#average(double[])}. */ @Test public void testAverageNormal() { double testarr[] = {0.5, 1.5, -1.0, 43.0, 1.0}; assertEquals(9.0,lab02.average(testarr),delta); } /** * Test method for {@link lab02#mode(double[])}. */ @Test public void testModeNormal() { double testarr[] = {3,4,6,4,7,8,9,4,4}; assertEquals(4.0,lab02.mode(testarr),delta); } /** * Test method for {@link lab02#mode(double[])}. */ @Test public void testModeTies() { double testarr[] = {5,3,4,6,4,5,7,8,9,5,4}; assertTrue((4.0 == lab02.mode(testarr)) || (5.0 == lab02.mode(testarr))); } /** * Test method for {@link lab02#stddev(double[])}. */ @Test public void testStddev() { double testarr[] = {3,4,6,4,7,8,9,4,4}; assertEquals(4.0247,lab02.stddev(testarr),delta); } /** * Test method for {@link lab02#startsWith( String [ ] arr, char ch )}. * ArrayList startsWith( String [ ] arr, char ch ) */ @Test public void testStartsWithNormal() { String[] wordlist = {"once","upon","a","time","there","lived","a","toad"}; ArrayList resarr = lab02.startsWith(wordlist,'t'); assertTrue(resarr.get(0).equals("time")); assertTrue(resarr.get(1).equals("there")); assertTrue(resarr.get(2).equals("toad")); } /** * Test method for {@link lab02#startsWith( String [ ] arr, char ch )}. * ArrayList startsWith( String [ ] arr, char ch ) */ @Test public void testStartsWithNone() { String[] wordlist = {"once","upon","a","time","there","lived","a","friendly","toad"}; ArrayList resarr = lab02.startsWith(wordlist,'s'); assertEquals(0,resarr.size()); } }