blob: edd5cdf982367f35bc66193335be98d4a9ebd223 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package theweeklychallenge;
/*
Week 139:
https://theweeklychallenge.org/blog/perl-weekly-challenge-139
Task #1: JortSort
You are given a list of numbers.
Write a script to implement JortSort. It should return true/false depending if the given list of numbers are already sorted.
*/
import java.util.Arrays;
import junit.framework.TestCase;
import static junit.framework.Assert.*;
public class JortSort extends TestCase {
public static void main(String[] args) {
junit.textui.TestRunner.run(theweeklychallenge.JortSort.class);
}
public void testJortSort() {
assertEquals(jortSort(new int[] {1,2,3,4,5}), 1);
assertEquals(jortSort(new int[] {1,3,4,2,5}), 0);
}
public static int jortSort(int[] n) {
int[] s = n.clone();
Arrays.sort(s);
for(int i = 0; i < n.length; i++) {
if (n[i] != s[i]) {
return 0;
}
}
return 1;
}
}
|