github.com/cayleygraph/cayley@v0.7.7/graph/transaction_test.go (about)

     1  package graph
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/cayleygraph/quad"
     7  )
     8  
     9  func TestTransaction(t *testing.T) {
    10  	var tx *Transaction
    11  
    12  	// simples adds / removes
    13  	tx = NewTransaction()
    14  
    15  	tx.AddQuad(quad.Make("E", "follows", "F", nil))
    16  	tx.AddQuad(quad.Make("F", "follows", "G", nil))
    17  	tx.RemoveQuad(quad.Make("A", "follows", "Z", nil))
    18  	if len(tx.Deltas) != 3 {
    19  		t.Errorf("Expected 3 Deltas, have %d delta(s)", len(tx.Deltas))
    20  	}
    21  
    22  	// add, remove -> nothing
    23  	tx = NewTransaction()
    24  	tx.AddQuad(quad.Make("E", "follows", "G", nil))
    25  	tx.RemoveQuad(quad.Make("E", "follows", "G", nil))
    26  	if len(tx.Deltas) != 0 {
    27  		t.Errorf("Expected [add, remove]->[], have %d Deltas", len(tx.Deltas))
    28  	}
    29  
    30  	// remove, add -> nothing
    31  	tx = NewTransaction()
    32  	tx.RemoveQuad(quad.Make("E", "follows", "G", nil))
    33  	tx.AddQuad(quad.Make("E", "follows", "G", nil))
    34  	if len(tx.Deltas) != 0 {
    35  		t.Errorf("Expected [add, remove]->[], have %d delta(s)", len(tx.Deltas))
    36  	}
    37  
    38  	// add x2 -> add x1
    39  	tx = NewTransaction()
    40  	tx.AddQuad(quad.Make("E", "follows", "G", nil))
    41  	tx.AddQuad(quad.Make("E", "follows", "G", nil))
    42  	if len(tx.Deltas) != 1 {
    43  		t.Errorf("Expected [add, add]->[add], have %d delta(s)", len(tx.Deltas))
    44  	}
    45  
    46  	// remove x2 -> remove x1
    47  	tx = NewTransaction()
    48  	tx.RemoveQuad(quad.Make("E", "follows", "G", nil))
    49  	tx.RemoveQuad(quad.Make("E", "follows", "G", nil))
    50  	if len(tx.Deltas) != 1 {
    51  		t.Errorf("Expected [remove, remove]->[remove], have %d delta(s)", len(tx.Deltas))
    52  	}
    53  
    54  	// add, remove x2 -> remove x1
    55  	tx = NewTransaction()
    56  	tx.AddQuad(quad.Make("E", "follows", "G", nil))
    57  	tx.RemoveQuad(quad.Make("E", "follows", "G", nil))
    58  	tx.RemoveQuad(quad.Make("E", "follows", "G", nil))
    59  	if len(tx.Deltas) != 1 {
    60  		t.Errorf("Expected [add, remove, remove]->[remove], have %d delta(s)", len(tx.Deltas))
    61  	}
    62  }