Question
Tester.java public class Tester { public static void main(String[] args) { int[] a = new int[] { 5, 4, 1, 9, 2, 6 }; Arrays.swapLargestAndSmallest(a);
Tester.java
public class Tester
{
public static void main(String[] args)
{
int[] a = new int[] { 5, 4, 1, 9, 2, 6 };
Arrays.swapLargestAndSmallest(a);
System.out.println(java.util.Arrays.toString(a));
System.out.println("Expected: [5, 4, 9, 1, 2, 6]");
a = new int[] {1, 4, 1, 9, 2, 6};
Arrays.swapLargestAndSmallest(a);
System.out.println(java.util.Arrays.toString(a));
System.out.println("Expected: [9, 4, 1, 1, 2, 6]");
a = new int[] {1, 4, 2, 9, 9, 6};
Arrays.swapLargestAndSmallest(a);
System.out.println(java.util.Arrays.toString(a));
System.out.println("Expected: [9, 4, 2, 1, 9, 6]");
a = new int[] {1};
Arrays.swapLargestAndSmallest(a);
System.out.println(java.util.Arrays.toString(a));
System.out.println("Expected: [1]");
}
}
Convert Tester.java into a JUnit testcase that uses asserts and multiple methods to test each scenario. Shell Junit testcase:
import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class testing { @BeforeAll static void setUpBeforeClass() throws Exception { } @AfterAll static void tearDownAfterClass() throws Exception { } @BeforeEach void setUp() throws Exception { } @AfterEach void tearDown() throws Exception { } @Test void test() { int a = Something.random(); assertEquals(0, a); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started