forked from cayleygraph/cayley
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction_test.go
62 lines (52 loc) · 1.74 KB
/
transaction_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package graph
import (
"testing"
"github.com/cayleygraph/quad"
)
func TestTransaction(t *testing.T) {
var tx *Transaction
// simples adds / removes
tx = NewTransaction()
tx.AddQuad(quad.Make("E", "follows", "F", nil))
tx.AddQuad(quad.Make("F", "follows", "G", nil))
tx.RemoveQuad(quad.Make("A", "follows", "Z", nil))
if len(tx.Deltas) != 3 {
t.Errorf("Expected 3 Deltas, have %d delta(s)", len(tx.Deltas))
}
// add, remove -> nothing
tx = NewTransaction()
tx.AddQuad(quad.Make("E", "follows", "G", nil))
tx.RemoveQuad(quad.Make("E", "follows", "G", nil))
if len(tx.Deltas) != 0 {
t.Errorf("Expected [add, remove]->[], have %d Deltas", len(tx.Deltas))
}
// remove, add -> nothing
tx = NewTransaction()
tx.RemoveQuad(quad.Make("E", "follows", "G", nil))
tx.AddQuad(quad.Make("E", "follows", "G", nil))
if len(tx.Deltas) != 0 {
t.Errorf("Expected [add, remove]->[], have %d delta(s)", len(tx.Deltas))
}
// add x2 -> add x1
tx = NewTransaction()
tx.AddQuad(quad.Make("E", "follows", "G", nil))
tx.AddQuad(quad.Make("E", "follows", "G", nil))
if len(tx.Deltas) != 1 {
t.Errorf("Expected [add, add]->[add], have %d delta(s)", len(tx.Deltas))
}
// remove x2 -> remove x1
tx = NewTransaction()
tx.RemoveQuad(quad.Make("E", "follows", "G", nil))
tx.RemoveQuad(quad.Make("E", "follows", "G", nil))
if len(tx.Deltas) != 1 {
t.Errorf("Expected [remove, remove]->[remove], have %d delta(s)", len(tx.Deltas))
}
// add, remove x2 -> remove x1
tx = NewTransaction()
tx.AddQuad(quad.Make("E", "follows", "G", nil))
tx.RemoveQuad(quad.Make("E", "follows", "G", nil))
tx.RemoveQuad(quad.Make("E", "follows", "G", nil))
if len(tx.Deltas) != 1 {
t.Errorf("Expected [add, remove, remove]->[remove], have %d delta(s)", len(tx.Deltas))
}
}