...
1# Deep Variable Equality for Humans
2
3[](https://goreportcard.com/report/github.com/go-test/deep)
4[](https://coveralls.io/github/go-test/deep?branch=master)
5[](https://pkg.go.dev/github.com/go-test/deep)
6
7This package provides a single function: `deep.Equal`. It's like [reflect.DeepEqual](http://golang.org/pkg/reflect/#DeepEqual) but much friendlier to humans (or any sentient being) for two reason:
8
9* `deep.Equal` returns a list of differences
10* `deep.Equal` does not compare unexported fields (by default)
11
12`reflect.DeepEqual` is good (like all things Golang!), but it's a game of [Hunt the Wumpus](https://en.wikipedia.org/wiki/Hunt_the_Wumpus). For large maps, slices, and structs, finding the difference is difficult.
13
14`deep.Equal` doesn't play games with you, it lists the differences:
15
16```go
17package main_test
18
19import (
20 "testing"
21 "github.com/go-test/deep"
22)
23
24type T struct {
25 Name string
26 Numbers []float64
27}
28
29func TestDeepEqual(t *testing.T) {
30 // Can you spot the difference?
31 t1 := T{
32 Name: "Isabella",
33 Numbers: []float64{1.13459, 2.29343, 3.010100010},
34 }
35 t2 := T{
36 Name: "Isabella",
37 Numbers: []float64{1.13459, 2.29843, 3.010100010},
38 }
39
40 if diff := deep.Equal(t1, t2); diff != nil {
41 t.Error(diff)
42 }
43}
44```
45
46
47```
48$ go test
49--- FAIL: TestDeepEqual (0.00s)
50 main_test.go:25: [Numbers.slice[1]: 2.29343 != 2.29843]
51```
52
53The difference is in `Numbers.slice[1]`: the two values aren't equal using Go `==`.
View as plain text