File: project2.go

package info (click to toggle)
golang-github-google-go-cmp 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 616 kB
  • sloc: makefile: 2
file content (74 lines) | stat: -rw-r--r-- 1,893 bytes parent folder | download | duplicates (6)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2017, The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package teststructs

import (
	"time"

	pb "github.com/google/go-cmp/cmp/internal/testprotos"
)

// This is an sanitized example of equality from a real use-case.
// The original equality function was as follows:
/*
func equalBatch(b1, b2 *GermBatch) bool {
	for _, b := range []*GermBatch{b1, b2} {
		for _, l := range b.DirtyGerms {
			sort.Slice(l, func(i, j int) bool { return l[i].String() < l[j].String() })
		}
		for _, l := range b.CleanGerms {
			sort.Slice(l, func(i, j int) bool { return l[i].String() < l[j].String() })
		}
	}
	if !pb.DeepEqual(b1.DirtyGerms, b2.DirtyGerms) ||
		!pb.DeepEqual(b1.CleanGerms, b2.CleanGerms) ||
		!pb.DeepEqual(b1.GermMap, b2.GermMap) {
		return false
	}
	if len(b1.DishMap) != len(b2.DishMap) {
		return false
	}
	for id := range b1.DishMap {
		kpb1, err1 := b1.DishMap[id].Proto()
		kpb2, err2 := b2.DishMap[id].Proto()
		if !pb.Equal(kpb1, kpb2) || !reflect.DeepEqual(err1, err2) {
			return false
		}
	}
	return b1.HasPreviousResult == b2.HasPreviousResult &&
		b1.DirtyID == b2.DirtyID &&
		b1.CleanID == b2.CleanID &&
		b1.GermStrain == b2.GermStrain &&
		b1.TotalDirtyGerms == b2.TotalDirtyGerms &&
		b1.InfectedAt.Equal(b2.InfectedAt)
}
*/

type GermBatch struct {
	DirtyGerms, CleanGerms map[int32][]*pb.Germ
	GermMap                map[int32]*pb.Germ
	DishMap                map[int32]*Dish
	HasPreviousResult      bool
	DirtyID, CleanID       int32
	GermStrain             int32
	TotalDirtyGerms        int
	InfectedAt             time.Time
}

type Dish struct {
	pb  *pb.Dish
	err error
}

func CreateDish(m *pb.Dish, err error) *Dish {
	return &Dish{pb: m, err: err}
}

func (d *Dish) Proto() (*pb.Dish, error) {
	if d.err != nil {
		return nil, d.err
	}
	return d.pb, nil
}