-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortingTester.java
More file actions
104 lines (90 loc) · 2.38 KB
/
SortingTester.java
File metadata and controls
104 lines (90 loc) · 2.38 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import java.util.Arrays;
import java.util.Random;
public class SortingTester {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr1 = {-123,-109,-50,0,25,34,9888888},//sorted array
arr2 = {78,50,1,-8,-10000},//upsidown array
arr3 = {-123,-109,34,9888888,34,34,-50,-123,9888888,-123,-123,0,34,25,-123,9888888},//not sorted
arr4 = {2,2,2,2,2,2,0,0,0,0,9,9,9,9}//not sorted
;
int[] arr5= new int[100];
double score = 100;
int[] arrch=arr1.clone();
Arrays.sort(arrch);
try{
Ex2.sort(arr1);
if(!Arrays.equals(arr1, arrch)){
score-=10;
System.out.println("failed at test 1" );
}
}catch (Exception e) {
// TODO: handle exception
score-=10;
System.out.println("failed at test 1 with exception" );
}
try{
arrch=arr2.clone();
Arrays.sort(arrch);
Ex2.sort(arr2);
if(!Arrays.equals(arr2, arrch)){
score-=10;
System.out.println("failed at test 2" );
}
}catch (Exception e) {
// TODO: handle exception
score-=10;
System.out.println("failed at test 2 with exception" );
}
try{
arrch=arr3.clone();
Arrays.sort(arrch);
Ex2.sort(arr3);
if(!Arrays.equals(arr3, arrch)){
score-=10;
System.out.println("failed at test 3" );
}
}catch (Exception e) {
// TODO: handle exception
score-=10;
System.out.println("failed at test 3 with exception" );
}
try{
arrch=arr4.clone();
Arrays.sort(arrch);
Ex2.sort(arr4);
if(!Arrays.equals(arr4, arrch)){
score-=10;
System.out.println("failed at test 4" );
}
}catch (Exception e) {
// TODO: handle exception
score-=10;
System.out.println("failed at test 4 with exception" );
}
double t5=60;
int count=0, countEX=0;
for (int j = 0; j < 1000; j++) {
Random rng = new Random();
for(int i=0;i<arr5.length;i++){
arr5[i]=rng.nextInt(100)-50;
}
arrch=arr5.clone();
Arrays.sort(arrch);
try{
Ex2.sort(arr5);
if(!Arrays.equals(arr5, arrch)){
t5*=99.75/100;
count++;
}
}catch (Exception e) {
// TODO: handle exception
t5*=99.75/100;
countEX++;
}
}
if(count>0||countEX>0)System.out.println("failed at "+count+" and hav exeptions in: "+countEX+" random testes from 1000" );
score-=60-t5;
System.out.println("\n\nfinal grade: "+score);
}
}