-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcounter_test.go
45 lines (40 loc) · 986 Bytes
/
gcounter_test.go
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
package dubba
import "testing"
func TestGcounterValue(t *testing.T) {
gCounter := NewGCounter()
gCounter.Increment()
currentValue := gCounter.Value()
if currentValue != 1 {
t.Errorf("Invalid value for g counter")
}
}
func TestGCounterIncrement(t *testing.T) {
gCounter := NewGCounter()
gCounter.Increment()
gCounter.IncrementNode("x", 4)
gCounter.IncrementNode("a", 3)
gCounter.IncrementNode("4", 1)
if gCounter.Value() != 9 {
t.Errorf("Invalid valid for G-Counter")
}
}
func TestGCounterMerge(t *testing.T) {
a, b := NewGCounter(), NewGCounter()
a.Increment()
b.IncrementNode("1", 9)
a.IncrementNode("2", 91)
ret := a.Merge(*b)
if ret.Value() != 100 {
t.Errorf("Invalid value for G-Counter. Merge failed")
}
}
func TestGCounterEqual(t *testing.T) {
a, b := NewGCounter(), NewGCounter()
a.Increment()
b.IncrementNode("1", 2)
a.IncrementNode("1", 1)
ret := a.IsEqualTo(*b)
if ret != true {
t.Errorf("Invalid value for G-Counter. Merge failed")
}
}