import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.junit.Test; import java.util.Arrays; public class TestLargest { @Test public void testSimple() { assertEquals(9, Largest.largest(new int[] {9,8,7})); } @Test(expected = ArrayIndexOutOfBoundsException.class) public void testTableauVide() { Largest.largest(new int[] {}); } @Test public void testFonctionCorrecte() { int[] t1 = {5, 4, 8, 1, 4}; int[] t2 = {15, 4, 8, 49, 5, 89}; int[] t3 = {4, -5, 8, 9, 4}; int maxt1 = Largest.largest(t1); int maxt2 = Largest.largest(t2); int maxt3 = Largest.largest(t3); Arrays.sort(t1); Arrays.sort(t2); Arrays.sort(t3); assertEquals(t1[t1.length-1], maxt1); assertEquals(t2[t2.length-1], maxt2); assertEquals(t3[t3.length-1], maxt3); } @Test public void testTableauNegatif() { assertEquals(-4, Largest.largest(new int[] {-15, -5, -4, -58})); } @Test(expected = NullPointerException.class) public void testTableauNull() { int[] t = null; Largest.largest(t); } }