Question: Please help me write a class that will pass the following JUnit test class: import static org.junit.Assert.*; import org.junit.Test; public class TestMySorter { /** *

Please help me write a class that will pass the following JUnit test class:

import static org.junit.Assert.*;

import org.junit.Test;

public class TestMySorter

{

/**

* Test Bubble Sort on a small, randomly ordered array

*/

@Test

public void testBubbleSmall()

{

int[] x = { 5, 3, 8, 1 };

MySorter s = new MySorter();

s.bubbleSort(x);

for (int i = 0; i < x.length - 1; i++)

{

assertTrue("Out of order at " + i, x[i] < x[i + 1]);

}

}

/**

* Test maxPosition for an element in the

* middle of the unsorted position

*/

@Test

public void testMaxPositionMiddle()

{

int[] x = {1, 5, 3, 7, 8, 9};

MySorter s = new MySorter();

assertEquals(1, s.maxPosition(x, 2));

}

/**

* Test maxPosition for an element in the middle

* of the unsorted portion

*/

@Test

public void testMaxPositionFirst()

{

int[] x = {5, 1, 3, 2, 8, 9};

MySorter s = new MySorter();

assertEquals(0, s.maxPosition(x, 3));

}

/**

* Test maxPosition for an element in the middle

* of the unsorted portion

*/

@Test

public void testMaxPositionLast()

{

int[] x = {1, 5, 3, 7, 8, 9};

MySorter s = new MySorter();

assertEquals(3, s.maxPosition(x, 3));

}

/**

* maxPosition must work correctly even when there is only

* one element in the portion of the array it is looking at

*/

@Test

public void testMaxPositionOneElement()

{

int[] x = {1, 5, 3, 7, 8, 9};

MySorter s = new MySorter();

assertEquals(0, s.maxPosition(x, 0));

}

/**

* Make sure that we can find the biggest thing

* even if it's negative

*/

@Test

public void testMaxPositionNegative()

{

int[] x = {-7, -6, -8,-3, -1};

MySorter s = new MySorter();

assertEquals(1, s.maxPosition(x, 2));

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!