APL2.1 - Controle Machine & DEV 2.3
This commit is contained in:
BIN
DEV 2.3/Largest/Largest.class
Normal file
BIN
DEV 2.3/Largest/Largest.class
Normal file
Binary file not shown.
19
DEV 2.3/Largest/Largest.java
Normal file
19
DEV 2.3/Largest/Largest.java
Normal file
@@ -0,0 +1,19 @@
|
||||
import java.util.Objects;
|
||||
|
||||
public class Largest {
|
||||
|
||||
/**
|
||||
* Return the largest element in a list.
|
||||
*
|
||||
* @param list A list of integers
|
||||
* @return The largest number in the given list
|
||||
*/
|
||||
public static int largest(int[] list) {
|
||||
Objects.requireNonNull(list);
|
||||
int index, max=Integer.MIN_VALUE;
|
||||
for (index = 0; index < list.length; index++) {
|
||||
max = list[index] > max ? list[index] : max;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
BIN
DEV 2.3/Largest/TestLargest.class
Normal file
BIN
DEV 2.3/Largest/TestLargest.class
Normal file
Binary file not shown.
36
DEV 2.3/Largest/TestLargest.java
Normal file
36
DEV 2.3/Largest/TestLargest.java
Normal file
@@ -0,0 +1,36 @@
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestLargest {
|
||||
|
||||
@Test
|
||||
public void testSimple() {
|
||||
assertEquals(9, Largest.largest(new int[] {9,8,7}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoundary() {
|
||||
assertEquals(Integer.MAX_VALUE, Largest.largest(new int[] {1, 28825, Integer.MAX_VALUE}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInverse() {
|
||||
assert(3 != Largest.largest(new int[] {1, 3, 7}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCrosscheck() {
|
||||
int[] a = new int[] {3, 1, 7};
|
||||
Arrays.sort(a);
|
||||
assert(Largest.largest(new int[] {3, 1, 7}) == a[a.length-1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testError() {
|
||||
Largest.largest(new int[] {});
|
||||
Largest.largest(null);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user