-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSearchAndSortClientFile.java
More file actions
134 lines (121 loc) · 4.67 KB
/
SearchAndSortClientFile.java
File metadata and controls
134 lines (121 loc) · 4.67 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//IMPORTANT NOTE:
//YOU SHOULD NOT EDIT THIS CLIENT FILE AT ALL!!!
//JUST RUN IT... if some of your methods don’t work, it will tell you which ones don’t work
//if all your methods work, you get a smiley face!
import java.util.ArrayList;
public class SearchAndSortClientFile
{
public static void main(String[] args)
{
//preliminary assignments:
ArrayList<Integer> tempList = new ArrayList<Integer>();
for(int i = 0; i < 10; i++)
{
tempList.add(2 * i - 5);
}
int[] tempArray = new int[10];
for(int i = 0; i < 10; i++)
{
tempArray[i] = 3 * i - 12;
}
SearchAndSort orderedArrays = new SearchAndSort(tempArray, tempList);
SearchAndSort randomArrays = new SearchAndSort();
boolean error = false;
//test isSortedArray:
if(randomArrays.isSortedArray())
{
System.out.println("isSortedArray returns true incorrectly");
error = true;
}
if(!orderedArrays.isSortedArray())
{
System.out.println("isSortedArray returns false incorrectly");
error = true;
}
//test isSortedArrayList:
if(randomArrays.isSortedArrayList())
{
System.out.println("isSortedArrayList returns true incorrectly");
error = true;
}
if(!orderedArrays.isSortedArrayList())
{
System.out.println("isSortedArrayList returns false incorrectly");
error = true;
}
//test linearSearch
if(orderedArrays.linearSearchArray(-12) != 0 || orderedArrays.linearSearchArray(15) != 9 || orderedArrays.linearSearchArray(0) != 4)
{
System.out.println("linearSearchArray is not working correctly");
error = true;
}
if(orderedArrays.linearSearchArrayList(-5) != 0 || orderedArrays.linearSearchArrayList(13) != 9 || orderedArrays.linearSearchArrayList(7) != 6)
{
System.out.println("linearSearchArrayList is not working correctly");
error = true;
}
//test binarySearch
if(orderedArrays.binarySearchArray(-12) != 0 || orderedArrays.binarySearchArray(15) != 9 || orderedArrays.binarySearchArray(0) != 4)
{
System.out.println("binarySearchArray is not working correctly");
error = true;
}
if(orderedArrays.binarySearchArrayList(-5) != 0 || orderedArrays.binarySearchArrayList(13) != 9 || orderedArrays.binarySearchArrayList(7) != 6)
{
System.out.println("binarySearchArrayList is not working correctly");
error = true;
}
//test bubbleSort
randomArrays.resetArrays();
randomArrays.bubbleSortArray();
randomArrays.bubbleSortArrayList();
if(!randomArrays.isSortedArray())
{
System.out.println("bubbleSortArray not working correctly");
error = true;
}
if(!randomArrays.isSortedArrayList())
{
System.out.println("bubbleSortArrayList not working correctly");
error = true;
}
randomArrays.resetArrays();
//test selectionSort
randomArrays.selectionSortArray();
randomArrays.selectionSortArrayList();
if(!randomArrays.isSortedArray())
{
System.out.println("selectionSortArray not working correctly");
error = true;
}
if(!randomArrays.isSortedArrayList())
{
System.out.println("selectionSortArrayList not working correctly");
error = true;
}
randomArrays.resetArrays();
//test insertionSort
randomArrays.insertionSortArray();
randomArrays.insertionSortArrayList();
if(!randomArrays.isSortedArray())
{
System.out.println("insertionSortArray not working correctly");
error = true;
}
if(!randomArrays.isSortedArrayList())
{
System.out.println("insertionSortArrayList not working correctly");
error = true;
}
randomArrays.resetArrays();
if(!error)
{
System.out.println("\nCongraluations! All your methods appear to be working correctly\n");
System.out.println(" +\"\"\"\"\"\"\"+ ");
System.out.println(" [| o o |]");
System.out.println(" | ^ | ");
System.out.println(" | \\___/ | ");
System.out.println(" +-------+ ");
}
}
}