-
-
Notifications
You must be signed in to change notification settings - Fork 424
/
Copy pathVersionHashMapTests.cs
94 lines (69 loc) · 2.79 KB
/
VersionHashMapTests.cs
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
using System.Linq;
using Xunit;
namespace LanguageExt.Tests;
public class VersionHashMapTests
{
[Fact]
public void Write_with_no_conflicts()
{
var data = VersionHashMap<string, int>.Empty;
data.Update(data["a"].Write("paul", 1));
data.Update(data["b"].Write("james", 1));
data.Update(data["b"].Write("james", 2));
data.Update(data["b"].Write("gavin", 3));
var str = data.AsIterable().OrderBy(p => p.Key).AsIterable().ToSeq().ToString();
Assert.True(str == "[(a, 1), (b, 3)]");
}
[Fact]
public void Write_with_conflicts_that_are_resolved_to_last_write_wins1()
{
var data = VersionHashMap<string, int>.Empty;
var client1 = data["a"].Write("paul", 10000, 1);
var client2 = data["a"].Write("james", 5000, 2);
var client3 = data["b"].Write("gavin", 500, 3);
data.Update(client1);
data.Update(client2);
data.Update(client3);
var str = data.AsIterable().OrderBy(p => p.Key).AsIterable().ToSeq().ToString();
Assert.True(str == "[(a, 1), (b, 3)]");
}
[Fact]
public void Write_with_conflicts_that_are_resolved_to_last_write_wins2()
{
var data = VersionHashMap<string, int>.Empty;
var client1 = data["a"].Write("paul", 10000, 1);
var client2 = data["a"].Write("james", 5000, 2);
var client3 = data["b"].Write("gavin", 500, 3);
data.Update(client2);
data.Update(client1);
data.Update(client3);
var str = data.AsIterable().OrderBy(p => p.Key).AsIterable().ToSeq().ToString();
Assert.True(str == "[(a, 1), (b, 3)]");
}
[Fact]
public void Write_with_conflicts_that_are_resolved_to_first_write_wins1()
{
var data = VersionHashMap<FirstWriteWins<int>, string, int>.Empty;
var client1 = data["a"].Write("paul", 10000, 1);
var client2 = data["a"].Write("james", 5000, 2);
var client3 = data["b"].Write("gavin", 500, 3);
data.Update(client1);
data.Update(client2);
data.Update(client3);
var str = data.AsIterable().OrderBy(p => p.Key).AsIterable().ToSeq().ToString();
Assert.True(str == "[(a, 2), (b, 3)]");
}
[Fact]
public void Write_with_conflicts_that_are_resolved_to_first_write_wins2()
{
var data = VersionHashMap<FirstWriteWins<int>, string, int>.Empty;
var client1 = data["a"].Write("paul", 10000, 1);
var client2 = data["a"].Write("james", 5000, 2);
var client3 = data["b"].Write("gavin", 500, 3);
data.Update(client2);
data.Update(client1);
data.Update(client3);
var str = data.AsIterable().OrderBy(p => p.Key).AsIterable().ToSeq().ToString();
Assert.True(str == "[(a, 2), (b, 3)]");
}
}