-
Notifications
You must be signed in to change notification settings - Fork 0
/
StatementCoverageData.java
125 lines (113 loc) · 3.04 KB
/
StatementCoverageData.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
package TestCompetition.JavaAgent;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.io.*;
import java.util.*;
public class StatementCoverageData {
static String key;
static int hashSize;
static final HashMap<String,Set<String>> h = new HashMap<>();
static final HashMap<String,Integer> hMap = new HashMap<>();
static ValueComparator bvc = new ValueComparator(hMap);
static TreeMap <String, Integer> sorted_map = new TreeMap <String, Integer> (bvc);
static List<String> testsTotal = new ArrayList<String>();
static List<String> testsAdditional = new ArrayList<String>();
public static void testExecuted(String className, String methodName)
{
key = className;
h.put(key,new HashSet<>());
}
public static void lineExecuted(String className)
{
String str = className;
if(h.containsKey(key))
h.get(key).add(str);
}
public static List<String> totalPriorIntoFile()
{
try
{
File file = new File("total_prior.txt");
if (file.exists())
file.delete();
else
file.createNewFile();
FileWriter writer = new FileWriter("total_prior.txt",true);
for (String key : h.keySet())
hMap.put(key, (h.get(key)).size());
sorted_map.putAll(hMap);
for (String key : sorted_map.keySet())
{
writer.write("" + key);
testsTotal.add(key);
writer.write(System.getProperty("line.separator"));
}
writer.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
return testsTotal;
}
public static void prioritize(String keyCurrent)
{
for (String temp : h.get(keyCurrent))
{
for (String key : hMap.keySet())
{
if(h.get(key).contains(temp))
hMap.put(key, hMap.get(key) - 1);
}
}
}
public static List<String> additionalPriorIntoFile()
{
try
{
File file = new File("additional_prior.txt");
if (file.exists())
file.delete();
else
file.createNewFile();
FileWriter writer = new FileWriter("additional_prior.txt",true);
String keyCurrent;
hashSize = hMap.size();
int i =1;
while(i<=hashSize)
{
keyCurrent = ""+sorted_map.keySet().toArray()[0];
writer.write(keyCurrent);
testsAdditional.add(keyCurrent);
writer.write(System.getProperty("line.separator"));
hMap.remove(keyCurrent);
prioritize(keyCurrent);
h.remove(keyCurrent);
sorted_map.clear();
sorted_map.putAll(hMap);
i++;
}
writer.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
return testsAdditional;
}
}
class ValueComparator implements Comparator<String>
{
HashMap<String, Integer> base;
public ValueComparator(HashMap<String, Integer> base)
{
this.base = base;
}
public int compare(String a, String b)
{
if (base.get(a) >= base.get(b))
return -1;
else
return 1;
}
}