github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/testutil/deepequal_test.go (about) 1 package testutil 2 3 import "testing" 4 5 func TestDeepEqual(t *testing.T) { 6 type s struct { 7 a int 8 b string 9 } 10 11 cases := []struct { 12 a, b interface{} 13 want bool 14 }{ 15 {1, 1, true}, 16 {1, 2, false}, 17 {nil, nil, true}, 18 {nil, []byte{}, true}, 19 {nil, []byte{1}, false}, 20 {[]byte{1}, []byte{1}, true}, 21 {[]byte{1}, []byte{2}, false}, 22 {[]byte{1}, []byte{1, 2}, false}, 23 {[]byte{1}, []string{"1"}, false}, 24 {[3]byte{}, [4]byte{}, false}, 25 {[3]byte{1}, [3]byte{1, 0, 0}, true}, 26 {s{}, s{}, true}, 27 {s{a: 1}, s{}, false}, 28 {s{b: "foo"}, s{}, false}, 29 {"foo", "foo", true}, 30 {"foo", "bar", false}, 31 {"foo", nil, false}, 32 } 33 34 for i, c := range cases { 35 got := DeepEqual(c.a, c.b) 36 if got != c.want { 37 t.Errorf("case %d: got %v want %v", i, got, c.want) 38 } 39 } 40 }