-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread_test.cpp
69 lines (56 loc) · 1.7 KB
/
thread_test.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
#include <bits/stdc++.h>
using namespace std;
#include "cache.h"
void testCache(Cache<int , string> *cache){
cache->insert(1, "one");
cache->insert(2, "two");
cache->insert(3, "three");
cache->insert(2, "two updated");
cout<<cache->get(1).first<<endl;
cache->insert(4, "six");
cout<<cache->get(3).first<<endl; // not found in case of LRU
cache->insert(5, "five");
cache->insert(5, "five");
cache->insert(4, "four");
cout<<cache->get(1).first<<endl;
cout<<cache->get(2).first<<endl;
cout<<cache->get(3).first<<endl;
cout<<cache->get(4).first<<endl;
cout<<cache->get(5).first<<endl;
}
void testThread(Cache<int , string> *cache){
cache->insert(1, "one 1");
cache->insert(2, "two 1");
cache->insert(3, "three 1");
cache->insert(4, "four 1");
cout<<cache->get(1).first<<endl;
cout<<cache->get(2).first<<endl;
// cout<<cache->get(3).first<<endl;
// cout<<cache->get(4).first<<endl;
// cout<<cache->get(5).first<<endl;
}
void testThread2(Cache<int , string> *cache){
cache->insert(1, "one 2");
cache->insert(2, "two 2");
cout<<cache->get(1).first<<endl;
cout<<cache->get(2).first<<endl;
// cout<<cache->get(3).first<<endl;
// cout<<cache->get(4).first<<endl;
// cout<<cache->get(5).first<<endl;
}
int main(){
cout<< "TEST: LRU" << endl;
auto *s = new StorageMap<int, string>(3);
auto *e = new LRU<int>();
auto *cache1 = new Cache<int, string>(s, e);
testCache(cache1);
thread t1(testThread,cache1);
thread t2(testThread,cache1);
thread t3(testThread2,cache1);
thread t4(testThread2,cache1);
t1.join();
t2.join();
t3.join();
t4.join();
delete s, e, cache1;
}