-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_rollback_blackbox.cpp
65 lines (57 loc) · 1.56 KB
/
test_rollback_blackbox.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
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <ctime>
#include "rollback/blackbox/DoublyLinkedList.h"
using namespace std;
double rand01()
{
return (double) rand() / RAND_MAX;
}
void test_rollback_reorder ()
{
rollback::blackbox::DoublyLinkedList list = rollback::blackbox::DoublyLinkedList (4000, 65);
vector<size_t> versions = vector<size_t>();
size_t i = 0;
cout << i << ":";
list.a_print_at (i);
for (i = 0; i < 500; ++i) {
double r = rand01();
size_t index = (size_t) (rand01() * list.a_size());
if (r < 0.1 && list.a_size() > 0) {
list.a_remove (index);
cout << "remove(" << index << ")" << endl;
} else if (r < 0.1 + 0.2 && list.a_size() > 0) {
list.a_modify (index, i);
cout << "modify(" << i << ", " << index << ")" << endl;
} else {
list.a_insert (index, i);
cout << "insert(" << i << ", " << index << ")" << endl;
}
cout << i + 1 << ":";
list.a_print_at (i + 1);
versions.push_back (i);
}
versions.push_back (i);
random_shuffle (versions.begin(), versions.end());
for (vector<size_t>::iterator iter = versions.begin(); iter != versions.end(); ++iter) {
cout << *iter << ":";
list.a_print_at (*iter);
}
}
int main (int argc, char** argv)
{
// srand(3);
unsigned seed;
if (argc == 1) {
seed = (unsigned) time (NULL);
} else if (argc == 2) {
seed = atoi (argv[1]);
}
srand (seed);
test_rollback_reorder();
cout << "seed: " << seed << endl;
return 0;
}
// kate: indent-mode cstyle; indent-width 2; replace-tabs on;