1 // Copyright 2017, The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE.md file.
10 pb "github.com/google/go-cmp/cmp/internal/testprotos"
13 // This is an sanitized example of equality from a real use-case.
14 // The original equality function was as follows:
16 func equalBatch(b1, b2 *GermBatch) bool {
17 for _, b := range []*GermBatch{b1, b2} {
18 for _, l := range b.DirtyGerms {
19 sort.Slice(l, func(i, j int) bool { return l[i].String() < l[j].String() })
21 for _, l := range b.CleanGerms {
22 sort.Slice(l, func(i, j int) bool { return l[i].String() < l[j].String() })
25 if !pb.DeepEqual(b1.DirtyGerms, b2.DirtyGerms) ||
26 !pb.DeepEqual(b1.CleanGerms, b2.CleanGerms) ||
27 !pb.DeepEqual(b1.GermMap, b2.GermMap) {
30 if len(b1.DishMap) != len(b2.DishMap) {
33 for id := range b1.DishMap {
34 kpb1, err1 := b1.DishMap[id].Proto()
35 kpb2, err2 := b2.DishMap[id].Proto()
36 if !pb.Equal(kpb1, kpb2) || !reflect.DeepEqual(err1, err2) {
40 return b1.HasPreviousResult == b2.HasPreviousResult &&
41 b1.DirtyID == b2.DirtyID &&
42 b1.CleanID == b2.CleanID &&
43 b1.GermStrain == b2.GermStrain &&
44 b1.TotalDirtyGerms == b2.TotalDirtyGerms &&
45 b1.InfectedAt.Equal(b2.InfectedAt)
49 type GermBatch struct {
50 DirtyGerms, CleanGerms map[int32][]*pb.Germ
51 GermMap map[int32]*pb.Germ
52 DishMap map[int32]*Dish
53 HasPreviousResult bool
54 DirtyID, CleanID int32
65 func CreateDish(m *pb.Dish, err error) *Dish {
66 return &Dish{pb: m, err: err}
69 func (d *Dish) Proto() (*pb.Dish, error) {