This repository was archived by the owner on Mar 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestChooseAlgorithm.java
More file actions
111 lines (108 loc) · 2.69 KB
/
TestChooseAlgorithm.java
File metadata and controls
111 lines (108 loc) · 2.69 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
import java.util.ArrayList;
public class TestChooseAlgorithm
{
private static ArrayList<String> testChooseSortAlgo()
{
String n = "";
ArrayList<String> arrOfProblems = new ArrayList<String>();
//setup
ExpParams e = new ExpParams();
e.setSortType(sortType.SELECTION);
Sort s = null;
//experiment step 1
s = chooseAlgorithm.chooseSortAlgo(s, e);
//testing case 1
if(!(s instanceof SelectionSort))
{
n = "ChooseSortAlgorithm when sort type is Selection Sort";
arrOfProblems.add(n);
}
//experiment step 2
e.setSortType(sortType.INSERTION);
s = chooseAlgorithm.chooseSortAlgo(s, e);
//testing case 2
if(!(s instanceof InsertionSort))
{
n = "ChooseSortAlgorithm when sort type is Insertion Sort";
arrOfProblems.add(n);
}
//experiment step 3
e.setSortType(sortType.SHELL);
s = chooseAlgorithm.chooseSortAlgo(s, e);
//testing case 3
if(!(s instanceof ShellSort))
{
n = "ChooseSortAlgorithm when sort type is Shell Sort";
arrOfProblems.add(n);
}
//experiment step 4
e.setSortType(sortType.MERGE);
s = chooseAlgorithm.chooseSortAlgo(s, e);
//testing case 4
if(!(s instanceof MergeSort))
{
n = "ChooseSortAlgorithm when sort type is Merge Sort";
arrOfProblems.add(n);
}
//experiment step 5
e.setSortType(sortType.QUICK);
s = chooseAlgorithm.chooseSortAlgo(s, e);
//testing case 5
if(!(s instanceof QuickSort))
{
n = "ChooseSortAlgorithm when sort type is QuickSort";
arrOfProblems.add(n);
}
//experiment step 6
e.setSortType(sortType.MERGEHYBRID);
s = chooseAlgorithm.chooseSortAlgo(s, e);
//testing case 6
if(!(s instanceof MergeSortHybrid))
{
n = "ChooseSortAlgorithm when sort type is Merge Sort Hybrid";
arrOfProblems.add(n);
}
//experiment step 7
e.setSortType(sortType.QUICKHYBRID);
s = chooseAlgorithm.chooseSortAlgo(s, e);
//testing case 7
if(!(s instanceof QuickSortHybrid))
{
n = "ChooseSortAlgorithm when sort type is QuickSort Hybrid";
arrOfProblems.add(n);
}
return arrOfProblems;
}
/*
* Runs all of the unit tests in this class
*/
public static void TestChooseSortingAlgorithm()
{
ArrayList<String> whatTests = new ArrayList<String>();
String Testname = "Choose Sorting Algorithm";
ArrayList<String> g = testChooseSortAlgo();
if(!g.isEmpty())
{
for(int i=0; i<g.size(); i++)
{
if(!g.get(i).equals(""))
{
whatTests.add(g.get(i));
}
}
}
boolean isCorrect = testIfFalse(whatTests);
FileIOUnitTestMenu.displayUnitTestResults(isCorrect, Testname, whatTests);
}
private static boolean testIfFalse(ArrayList<String> whatTests)
{
for(int i=0; i<whatTests.size(); i++)
{
if(!whatTests.get(i).equals(""))
{
return false;
}
}
return true;
}
}