Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created November 29, 2021 19:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordanorelli/e67e20ec307b8d54bd396761255a26ba to your computer and use it in GitHub Desktop.
Save jordanorelli/e67e20ec307b8d54bd396761255a26ba to your computer and use it in GitHub Desktop.
package merge
import (
"testing"
)
func TestMergeTables(t *testing.T) {
alice := Table[string, *additive]{
"vanilla": add(3),
"chocolate": add(5),
"strawberry": add(2),
}
bob := Table[string, *additive]{
"vanilla": add(2),
"chocolate": add(3),
"pistacchio": add(5),
}
votes := make(Table[string, *additive])
if err := votes.Merge(alice); err != nil {
t.Fatalf("tables failed to merge: %v", err)
}
if err := votes.Merge(bob); err != nil {
t.Fatalf("tables failed to merge: %v", err)
}
check := func(k string, n int) {
if have := votes[k].total; have != n {
t.Fatalf("expected %d votes for %s but saw %v instead", n, k, have)
}
}
check("vanilla", 5)
check("chocolate", 8)
check("strawberry", 2)
check("pistacchio", 5)
bob["pistacchio"].Merge(add(100))
bob["pistacchio"] = add(1)
check("pistacchio", 5)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment