-
Notifications
You must be signed in to change notification settings - Fork 1
/
Test.java
123 lines (108 loc) · 4.17 KB
/
Test.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
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
/**
* This class tests the program.
*
*
*/
public class Test {
/**
* This main method tests everything
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String fName="Tests.txt";
FileWriter file = new FileWriter(fName);
BufferedWriter bw = new BufferedWriter(file);
// This will test reference set sizes 10-30
for (int i = 10; i <= 50; i += 5) {
int badO = 0;
int goodO = 0;
int greatO = 0;
int badLRU = 0;
int goodLRU = 0;
int greatLRU = 0;
int badRandom = 0;
int goodRandom = 0;
int greatRandom = 0;
// Create 100 different reference strings to test for each algorithm
// and each type of string
for (int j = 0; j < 100; j++) {
shortProgram bad = new shortProgram(false);
shortProgram good = new shortProgram(true);
shortProgram great = new shortProgram((byte) 100);
great.shuffle();
badO += Optimal.optimal(bad, i);
goodO += Optimal.optimal(good, i);
greatO += Optimal.optimal(great, i);
badLRU += LRU.lru(bad, i);
goodLRU += LRU.lru(good, i);
greatLRU += LRU.lru(great, i);
RandomAlgorithm rb = new RandomAlgorithm(bad, i);
RandomAlgorithm rg = new RandomAlgorithm(good, i);
RandomAlgorithm rgr = new RandomAlgorithm(great, i);
badRandom += rb.simulateDemandPagingRandomAlgorithm();
goodRandom += rg.simulateDemandPagingRandomAlgorithm();
greatRandom += rgr.simulateDemandPagingRandomAlgorithm();
}
// Get the averages of each algorithm and their respective programs
badO = badO/1000;
goodO = goodO/1000;
greatO = greatO/1000;
badLRU = badLRU/1000;
goodLRU = goodLRU/1000;
greatLRU = greatLRU/1000;
badRandom = badRandom/1000;
goodRandom = goodRandom/1000;
greatRandom = greatRandom/1000;
bw.write("Optimal, bad, set size " + i + ": " + badO);
bw.newLine();
bw.write("Optimal, good, set size " + i + ": " + goodO);
bw.newLine();
bw.write("Optimal, great, set size " + i + ": " + greatO);
bw.newLine();
bw.newLine();
bw.write("LRUA, bad, set size " + i + ": " + badLRU);
bw.newLine();
bw.write("LRUA, good, set size " + i + ": " + goodLRU);
bw.newLine();
bw.write("LRUA, great, set size " + i + ": " + greatLRU);
bw.newLine();
bw.newLine();
bw.write("Random, bad, set size " + i + ": " + badRandom);
bw.newLine();
bw.write("Random, good, set size " + i + ": " + goodRandom);
bw.newLine();
bw.write("Random, great, set size " + i + ": " + greatRandom);
bw.newLine();
bw.newLine();
bw.newLine();
}
bw.close();
System.out.println("Done!");
readFile(fName);
}
public static void readFile(String fName)
{
try {
List<String> data=new ArrayList<String>();
data = Files.readAllLines(new File(fName).toPath(), Charset.defaultCharset() );
for(int i=0;i<data.size();i++)
{
System.out.println(data.get(i));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}