forked from ProgramRepair/SearchRepair
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalyzer.java
234 lines (173 loc) · 5.86 KB
/
Analyzer.java
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package Experiment;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import Library.Utility;
public class Analyzer {
public static final String MEDIAN = "median";
public static final String SMALLEST = "smallest";
public static final String SYLLABLES = "syllables";
public static final String DIGITS = "digits";
public static final String GRADE = "grade";
public static final String CHECKSUM = "checksum";
public static final String CORRECT = "correct";
public static final String FAILED = "failed";
private Map<String, Map<String, String>> table;
private String root;
private boolean wb;
private int repo;
//statistics
private int genprogfix;
private int aefix;
private int tspfix;
private int searchfix;
public Analyzer(String root, boolean wb, int repo) {
this.root = root;
this.wb = wb;
this.table = new HashMap<String, Map<String, String>>();
initTable();
resetStatics();
}
private void resetStatics() {
this.genprogfix = 0;
this.aefix = 0;
this.tspfix = 0;
this.searchfix = 0;
}
public void fetch(){
File rootDir = new File(root);
for(File dir : rootDir.listFiles()){
String name = dir.getName();
if(name.equals(Analyzer.MEDIAN) || name.equals(Analyzer.SMALLEST) || name.equals(Analyzer.DIGITS) || name.equals(Analyzer.CHECKSUM )|| name.equals(Analyzer.SYLLABLES) || name.equals(Analyzer.GRADE) ){
fetch(dir, name);
}
}
}
private void fetch(File dir, String name) {
for(File version : dir.listFiles()){
if(checkIsCorrect(version)){
initCorrectForAll(version);
continue;
}
initSearchFix(version, name);
initAE(version, name);
initTSP(version, name);
initGenprog(version, name);
}
}
private void initGenprog(File version, String name) {
String path;
if(wb) path = version.getAbsolutePath() + "/repair/tsp-wb";
else path = version.getAbsolutePath() + "/repair/tsp-bb";
String content = Utility.getStringFromFile(path).trim();
if(content.equals(Analyzer.CORRECT)){
this.table.get(name).put(version.getName(), Analyzer.CORRECT);
}
else{
this.table.get(name).put(version.getName(), Analyzer.FAILED);
}
}
private void initTSP(File version, String name) {
String path;
if(wb) path = version.getAbsolutePath() + "/repair/tsp-wb";
else path = version.getAbsolutePath() + "/repair/tsp-bb";
String content = Utility.getStringFromFile(path).trim();
if(content.equals(Analyzer.CORRECT)){
this.table.get(name).put(version.getName(), Analyzer.CORRECT);
}
else{
this.table.get(name).put(version.getName(), Analyzer.FAILED);
}
}
private void initAE(File version, String name) {
String path;
if(wb) path = version.getAbsolutePath() + "/repair/ae-wb";
else path = version.getAbsolutePath() + "/repair/ae-bb";
String content = Utility.getStringFromFile(path).trim();
if(content.equals(Analyzer.CORRECT)){
this.table.get(name).put(version.getName(), Analyzer.CORRECT);
}
else{
this.table.get(name).put(version.getName(), Analyzer.FAILED);
}
}
private void initCorrectForAll(File version) {
this.table.get(Analyzer.MEDIAN).put(version.getName(), Analyzer.CORRECT);
this.table.get(Analyzer.CHECKSUM).put(version.getName(), Analyzer.CORRECT);
this.table.get(Analyzer.SMALLEST).put(version.getName(), Analyzer.CORRECT);
this.table.get(Analyzer.SYLLABLES).put(version.getName(), Analyzer.CORRECT);
this.table.get(Analyzer.GRADE).put(version.getName(), Analyzer.CORRECT);
this.table.get(Analyzer.DIGITS).put(version.getName(), Analyzer.CORRECT);
}
private boolean checkIsCorrect(File version) {
String checkDir;
if(!wb){
checkDir = version.getAbsolutePath() + "/whitebox/negative";
}
else checkDir = version.getAbsolutePath() + "/blackbox/negative";
return !new File(checkDir).exists() || new File(checkDir).list().length == 0;
}
private void initSearchFix(File version, String name) {
// TODO Auto-generated method stub
this.table.get(name).put(version.getName(), Analyzer.FAILED);
}
private void initTable() {
table.put(Analyzer.MEDIAN, new HashMap<String, String>());
table.put(Analyzer.SMALLEST, new HashMap<String, String>());
table.put(Analyzer.DIGITS, new HashMap<String, String>());
table.put(Analyzer.GRADE, new HashMap<String, String>());
table.put(Analyzer.SYLLABLES, new HashMap<String, String>());
table.put(Analyzer.CHECKSUM, new HashMap<String, String>());
}
private boolean checkNeg(File subsubDir) {
String dirPath = subsubDir.getAbsolutePath();
//System.out.println(dirPath);
File dir1 = new File(dirPath + "/blackbox/negative");
File dir2 = new File(dirPath + "/whitebox/negative");
boolean hasNeg = false;
if(dir1.exists() && dir1.list().length != 0) hasNeg = true;
if(dir2.exists() && dir2.list().length != 0) hasNeg = true;
return hasNeg;
}
public int checkVersions(String root){
int count = 0;
File dir = new File(root);
for(File file : dir.listFiles()){
if(!file.getName().equals("tests") && file.isDirectory()){
count += getSubdir(file);
}
}
return count;
}
private int getSubdir(File file) {
int count = 0;
for(File temp : file.listFiles()){
if(temp.isDirectory()) count++;
}
return count;
}
public static void main(String[] args){
Analyzer ana = new Analyzer("./bughunt/median", true, 1);
ana.fetch();
ana.initStatics();
ana.printFormat();
// try {
// System.setOut(new PrintStream("log"));
// int count = ana.checkVersions("/users/yke/documents/coding/project/introclass-may-2015/median");
// System.out.println(count);
// } catch (FileNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
private void initStatics() {
this.resetStatics();
for(String s : this.table.get(Analyzer.MEDIAN))
}
private void printFormat() {
System.out.println();
}
}