Skip to content

Commit

Permalink
add sorting to vector clock String encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
pfandzelter committed Jul 26, 2021
1 parent db949c8 commit af53d3f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions govec/vclock/vclock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/gob"
"fmt"
"log"
"sort"
)

// Condition constants define how to compare a vector clock against another,
Expand Down Expand Up @@ -121,6 +122,8 @@ func (vc VClock) ReturnVCString() string {
i++
}

sort.Strings(ids)

var buffer bytes.Buffer
buffer.WriteString("{")
for i := range ids {
Expand Down
20 changes: 20 additions & 0 deletions govec/vclock/vclock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,23 @@ func TestEncodeDecode(t *testing.T) {
t.Fatalf("decoded not the same as encoded enc = %s | dec = %s", nString, dString)
}
}

func TestVCString(t *testing.T) {
n := New()

n.Set("a", 1)
n.Set("b", 1)
n.Set("c", 1)
n.Set("d", 1)
n.Set("e", 1)
n.Set("f", 1)
n.Set("g", 1)
n.Set("h", 1)

expected := "{\"a\":1, \"b\":1, \"c\":1, \"d\":1, \"e\":1, \"f\":1, \"g\":1, \"h\":1}"
nString := n.ReturnVCString()

if nString != expected {
t.Fatalf("VC string %s not the same as expected %s", nString, expected )
}
}

0 comments on commit af53d3f

Please sign in to comment.