func TestFigure3D(t *testing.T) { var a clock.Clock var b clock.Clock var c clock.Clock b.Update(11, 1) if g, e := clock.Sync(&b, &a), clock.Copy; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } a.ResolveTheirs(&b) if g, e := clock.Sync(&b, &c), clock.Copy; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } c.ResolveTheirs(&b) a.Update(10, 3) b.Update(11, 3) if g, e := clock.Sync(&a, &b), clock.Conflict; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } // resolve conflict in favor of something new b.ResolveNew(&a) if g, e := clock.Sync(&a, &b), clock.Nothing; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } if g, e := clock.Sync(&c, &b), clock.Nothing; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } a.Update(10, 6) if g, e := clock.Sync(&a, &b), clock.Conflict; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } a.ValidateFile(&clock.Clock{ /* dummy parent */ }) b.ValidateFile(&clock.Clock{ /* dummy parent */ }) c.ValidateFile(&clock.Clock{ /* dummy parent */ }) }
func TestFigure2C(t *testing.T) { var b clock.Clock a := clock.Create(10, 1) if g, e := clock.Sync(a, &b), clock.Copy; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } b.ResolveTheirs(a) a.Update(10, 3) b.Update(11, 3) if g, e := clock.Sync(&b, a), clock.Conflict; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } if g, e := a.String(), `{sync{10:3} mod{10:3} create{10:1}}`; g != e { t.Errorf("bad state A: %v != %v", g, e) } if g, e := b.String(), `{sync{10:1 11:3} mod{11:3} create{10:1}}`; g != e { t.Errorf("bad state B: %v != %v", g, e) } a.ValidateFile(&clock.Clock{ /* dummy parent */ }) b.ValidateFile(&clock.Clock{ /* dummy parent */ }) }