How would I go about setting this JUnit test to actually sort correctly?
I tried a bunch of different ways of setting up the test but it still isn't working. For example, trying to remove the main parameters to add later doesn't work. I've tried tweaking parts to make it work but it just fails.
void test() {
int [] input = new int[]{6,1,7,3,8,2,5,4};
input.sort(input);
assertEquals("1:2:3:4:5:6:7:8:",(input));
}
// Things I have tried
//int[] result = new Computers().printArray(input);
//input.sort(input);
//assertEquals("1:2:3:4:5:6:7:8:",(input));
//input.sort(input);
//assertEquals(expected,numbers);
//int [] input = new int[]{6,1,7,3,8,2,5,4};
//Computers sort = new Computers();
//assertEquals("1:2:3:4:5:6:7:8:",(input));
//int[] numbers = {6,1,7,3,8,2,5,4};
//int[] expected = {1,2,3,4,5,6,7,8};
}
Here is my sort in Computers class
public void sort(int arr[])
{
int n = arr.length;
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
{
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
static void printArray(int arr[]) {
int n = arr.length;
for (int i = 0; i < n; ++i)
System.out.print(arr[i] + " ");
System.out.println();
}
Cannot invoke sort(int[]) on the array type int[] Cannot make a static reference to the non-static method sort(int[]) from the type Computers
So I don't know how exactly I should set up this sort to work properly.