forked from rgbdemo/nestk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-transactions.cpp
63 lines (51 loc) · 1.33 KB
/
test-transactions.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
#include <ntk/utils/stl.h>
#include <iostream>
#include <map>
typedef std::map<int,int> map_int_int;
using namespace ntk;
bool test1()
{
std::map<int, int> orig;
orig[5] = 12;
orig[8] = 15;
orig[12] = 8;
std::map<int,int> modified = orig;
{
AssociativeContainerTransaction<map_int_int> transaction(modified);
transaction.changeElement(5) = 15;
transaction.removeElement(8);
}
if (modified.size() != 2) return false;
if (modified[5] != 15) return false;
return true;
}
bool test2()
{
std::map<int, int> orig;
orig[5] = 12;
orig[8] = 15;
orig[12] = 8;
foreach_const_it(it, orig, map_int_int)
std::cout << "[" << it->first << "] => [" << it->second << "]" << std::endl;
std::map<int,int> modified = orig;
{
AssociativeContainerTransaction<map_int_int> transaction(modified);
transaction.changeElement(5) = 15;
transaction.changeElement(8) = 12;
transaction.removeElement(12);
transaction.abortTransaction();
}
foreach_const_it(it, modified, map_int_int)
std::cout << "[" << it->first << "] => [" << it->second << "]" << std::endl;
if (modified.size() != 3) return false;
if (modified[5] != 12) return false;
if (modified[8] != 15) return false;
return true;
}
int main()
{
bool ok = true;
ok &= test1();
ok &= test2();
return ok != true;
}