-
Notifications
You must be signed in to change notification settings - Fork 4
/
stats_test.go
41 lines (34 loc) · 1006 Bytes
/
stats_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package deepdiff
import (
"context"
"encoding/json"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestCalcStats(t *testing.T) {
aJSON := []byte(`{"a": 100,"foo": [1,2,3],"bar": false,"baz": {"a": {"b": 4,"c": false,"d": "apples-and-oranges"},"e": null,"g": "apples-and-oranges"}}`)
bJSON := []byte(`{"a": 99,"foo": [1,2,3],"bar": false,"baz": {"a": {"b": 5,"c": false,"d": "apples-and-oranges"},"e": "thirty-thousand-something-dogecoin","f": {"a" : false, "b": true}}}`)
var a, b map[string]interface{}
if err := json.Unmarshal(aJSON, &a); err != nil {
t.Fatal(err)
}
if err := json.Unmarshal(bJSON, &b); err != nil {
t.Fatal(err)
}
expect := &Stats{
Left: 14,
Right: 16,
LeftWeight: 186,
RightWeight: 268,
Inserts: 4,
Updates: 0,
Deletes: 4,
}
got, err := New().Stat(context.Background(), a, b)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(expect, got); diff != "" {
t.Errorf("result mismatch. (-want +got):\n%s", diff)
}
}