-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
159 lines (120 loc) · 3.87 KB
/
main.cpp
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
#include <iostream>
#ifndef ARC
#include "ARC.cpp"
#endif // !ARC
using namespace arc;
/*
Test cases list:
1. (4.3) Test cache miss - L1 size should go upto PAGE_SIZE and remain constant.
2. (4.1) Test cache miss when T1 = PAGE_SIZE
3. (4.2) Test cache miss when L1 < PAGE_SIZE
4. (1) Test frequent hit - T2 should go upto PAGE_SIZE and T1 should simultaneously go down
5. (2) requested page in B1 - This should ultimately adjust p to increase the T1 capacity ( recency)
6. (3) requested page in B2 - This should ultimately adjust p to increase the T2 capacity ( frequency)
*/
int main()
{
ARC<int , int> *a = new ARC<int,int>();
for (int i = 1; i < 10000; i++)
a->load_master_data(i, i * 1000);
cout << " ARU Cache implementation: PAGE_SIZE is defined to be 5 - Select test case from below " << endl;
while (1)
{
cout << " 1. (4.3) Test cache miss - L1 size should go upto PAGE_SIZE and remain constant. " << endl;
cout << " 2. (4.1) Test cache miss when L1 = PAGE_SIZE & T1 < c implies that there is a key in B1" << endl;
cout << " 3. (4.2) Test cache miss when L1 < PAGE_SIZE " << endl;
cout << " 4. (1) Test frequent hit - T2 should go upto PAGE_SIZE and T1 should simultaneously go down " << endl;
cout << " 5. (2) requested page in B1 - This should ultimately increase p to increase the T1 capacity ( recency) " << endl;
cout << " 6. (3) requested page in B2 - This should ultimately decrease p to increase the T2 capacity ( frequency) " << endl;
cout << " 7. Custom Inputs : Press 99 to print " << endl;
int id = 0;
int value = 0;
cin >> id;
switch (id)
{
case 1:
cout << "Input keys : 1,2,3,4,5 " << endl;
cout << "Expected op : T1 should contain 5 to 1 " << endl;
for (int i = 1; i <= 5; i++)
a->fetch(i, value);
a->print();
a->clear();
break;
case 2:
cout << "Input keys : 1,2,3,4,5, 1,2,3,4, 6, " << endl;
cout << "Expected op : T1 should contain 6, B1 should contain 5, and T2 should contain 4 to 1" << endl;
for (int i = 1; i <= 5; i++)
a->fetch(i, value);
for (int i = 1; i <= 4; i++)
a->fetch(i, value);
a->fetch(6, value);
a->print();
a->clear();
break;
case 3:
cout << "Input keys : 1,2,3,4,5, 1,2,3,4,5, 6 " << endl;
cout << "Expected op : T1 should contain 6 , T2 should contain 5 to 2 , and B2 should contain 1" << endl;
for (int i = 1; i <= 5; i++)
a->fetch(i, value);
for (int i = 1; i <= 6; i++)
a->fetch(i, value);
a->print();
a->clear();
break;
case 4:
cout << "Input keys : 1,2,3,4,5, 1,2,3,4,5 " << endl;
cout << "Expected op : T2 should contain 5 to 1 , T1 should be empty" << endl;
for (int i = 1; i <= 5; i++)
a->fetch(i, value);
for (int i = 1; i <= 5; i++)
a->fetch(i, value);
a->print();
a->clear();
break;
case 5:
cout << "Input keys : 1,2,3,4,5, 1,2,3,4, 6,5 " << endl;
cout << "Expected op : 5 thats in B1 moves to T2 BUT P value increases from 0 to 1 => T1 capacity increased" << endl;
for (int i = 1; i <= 5; i++)
a->fetch(i, value);
for (int i = 1; i <= 4; i++)
a->fetch(i, value);
a->fetch(6, value);
a->print();
a->fetch(5, value);
a->print();
a->clear();
break;
case 6:
cout << "Input keys : 1,2,3,4,5, 1,2,3,4, 6,5 ,1" << endl;
cout << "Expected op : 1 thats in B2 moves to T2 BUT P value goes from 1 to 0 => T2 capacity increased" << endl;
for (int i = 1; i <= 5; i++)
a->fetch(i, value);
for (int i = 1; i <= 4; i++)
a->fetch(i, value);
a->fetch(6, value);
a->fetch(5, value);
a->print();
a->fetch(1, value);
a->print();
a->clear();
break;
case 7:
while (1)
{
int key, value;
cin >> key;
if (key == 99)
a->print();
else
a->fetch(key, value);
a->print();
cout << endl << endl;
}
default:
cout << " Select 1-7 as below" << endl;
break;
}
}
delete a;
return 1;
}