Commit 1a1c5941 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e2dbfff6
...@@ -429,13 +429,13 @@ func TestIntSets(t *testing.T) { ...@@ -429,13 +429,13 @@ func TestIntSets(t *testing.T) {
// kvdiff returns differens in between kv1 and kv2. // kvdiff returns differens in between kv1 and kv2.
var DEL = "ø" var DEL = "ø" // DEL means key deletion
type kvdelta1 struct { //type kvdelta1 struct {
k Key // k Key
v string // DEL means delete // v string // DEL means delete
} //}
func kvdiff(kv1, kv2 map[Key]string) []kvdelta1 { func kvdiff(kv1, kv2 map[Key]string) map[Key]string {
delta := []kvdelta1{} delta := map[Key]string{}
keys := SetKey{} keys := SetKey{}
for k := range kv1 { keys.Add(k) } for k := range kv1 { keys.Add(k) }
for k := range kv2 { keys.Add(k) } for k := range kv2 { keys.Add(k) }
...@@ -451,9 +451,20 @@ func kvdiff(kv1, kv2 map[Key]string) []kvdelta1 { ...@@ -451,9 +451,20 @@ func kvdiff(kv1, kv2 map[Key]string) []kvdelta1 {
v2, ok := kv2[k] v2, ok := kv2[k]
if !ok { v2 = DEL } if !ok { v2 = DEL }
if v1 != v2 { if v1 != v2 {
delta = append(delta, kvdelta1{k,v2}) delta[k] = v2
} }
} }
return delta return delta
} }
func TestKVDiff(t *testing.T) {
kv1 := map[Key]string{1:"a", 3:"c", 4:"d"}
kv2 := map[Key]string{1:"b", 4:"d", 5:"e"}
got := kvdiff(kv1, kv2)
want := map[Key]string{1:"b", 3:DEL, 5:"e"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("error:\ngot: %v\nwant: %v", got, want)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment