12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package sortutil
- import "testing"
- type dinnerDay struct {
- day string
- vc *VectorClock
- }
- const (
- actorAlice = "Alice"
- actorBen = "Ben"
- actorCathy = "Cathy"
- actorDave = "Dave"
- )
- func TestDinnerAgreement(t *testing.T) {
-
-
- dd := &dinnerDay{"Wednesday", NewVectorClock()}
- dd.vc.Act(actorAlice)
- dd2 := &dinnerDay{dd.day, CloneVectorClock(dd.vc)}
-
- dd.day = "Tuesday"
- dd.vc.Act(actorBen)
-
- dd.vc.Act(actorDave)
-
- if !dd.vc.IsDescendent(dd2.vc) {
- t.Error("dd should be a descendent of dd2")
- return
- } else if dd2.vc.IsDescendent(dd.vc) {
- t.Error("dd2 should not be a descendent of dd")
- return
- }
-
- dd2.day = "Thursday"
- dd2.vc.Act(actorCathy)
-
- if !dd.vc.IsConflicting(dd2.vc) {
- t.Error("Vector clocks should be conflicting")
- return
- }
-
- dd3 := &dinnerDay{dd2.day, NewDescendant(dd.vc, dd2.vc)}
- dd3.vc.Act(actorDave)
-
- if !dd3.vc.IsDescendent(dd.vc) || dd3.vc.IsConflicting(dd.vc) {
- t.Error("dd3 should be a descendent of dd")
- return
- } else if !dd3.vc.IsDescendent(dd2.vc) || dd3.vc.IsConflicting(dd2.vc) {
- t.Error("dd3 should be a descendent of dd2")
- return
- }
- if out := dd3.vc.String(); out != `
- Alice:1
- Ben:1
- Cathy:1
- Dave:2
- `[1:] {
- t.Error("Unexpected output:", out)
- return
- }
- }
|