aboutsummaryrefslogtreecommitdiff
path: root/cmp/internal/teststructs/project1.go
blob: 1999e38fd7a2ec8bf4e5d2264f2e5193f6479445 (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// 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.md 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 equalEagle(x, y Eagle) bool {
	if x.Name != y.Name &&
		!reflect.DeepEqual(x.Hounds, y.Hounds) &&
		x.Desc != y.Desc &&
		x.DescLong != y.DescLong &&
		x.Prong != y.Prong &&
		x.StateGoverner != y.StateGoverner &&
		x.PrankRating != y.PrankRating &&
		x.FunnyPrank != y.FunnyPrank &&
		!pb.Equal(x.Immutable.Proto(), y.Immutable.Proto()) {
		return false
	}

	if len(x.Dreamers) != len(y.Dreamers) {
		return false
	}
	for i := range x.Dreamers {
		if !equalDreamer(x.Dreamers[i], y.Dreamers[i]) {
			return false
		}
	}
	if len(x.Slaps) != len(y.Slaps) {
		return false
	}
	for i := range x.Slaps {
		if !equalSlap(x.Slaps[i], y.Slaps[i]) {
			return false
		}
	}
	return true
}
func equalDreamer(x, y Dreamer) bool {
	if x.Name != y.Name ||
		x.Desc != y.Desc ||
		x.DescLong != y.DescLong ||
		x.ContSlapsInterval != y.ContSlapsInterval ||
		x.Ornamental != y.Ornamental ||
		x.Amoeba != y.Amoeba ||
		x.Heroes != y.Heroes ||
		x.FloppyDisk != y.FloppyDisk ||
		x.MightiestDuck != y.MightiestDuck ||
		x.FunnyPrank != y.FunnyPrank ||
		!pb.Equal(x.Immutable.Proto(), y.Immutable.Proto()) {

		return false
	}
	if len(x.Animal) != len(y.Animal) {
		return false
	}
	for i := range x.Animal {
		vx := x.Animal[i]
		vy := y.Animal[i]
		if reflect.TypeOf(x.Animal) != reflect.TypeOf(y.Animal) {
			return false
		}
		switch vx.(type) {
		case Goat:
			if !equalGoat(vx.(Goat), vy.(Goat)) {
				return false
			}
		case Donkey:
			if !equalDonkey(vx.(Donkey), vy.(Donkey)) {
				return false
			}
		default:
			panic(fmt.Sprintf("unknown type: %T", vx))
		}
	}
	if len(x.PreSlaps) != len(y.PreSlaps) {
		return false
	}
	for i := range x.PreSlaps {
		if !equalSlap(x.PreSlaps[i], y.PreSlaps[i]) {
			return false
		}
	}
	if len(x.ContSlaps) != len(y.ContSlaps) {
		return false
	}
	for i := range x.ContSlaps {
		if !equalSlap(x.ContSlaps[i], y.ContSlaps[i]) {
			return false
		}
	}
	return true
}
func equalSlap(x, y Slap) bool {
	return x.Name == y.Name &&
		x.Desc == y.Desc &&
		x.DescLong == y.DescLong &&
		pb.Equal(x.Args, y.Args) &&
		x.Tense == y.Tense &&
		x.Interval == y.Interval &&
		x.Homeland == y.Homeland &&
		x.FunnyPrank == y.FunnyPrank &&
		pb.Equal(x.Immutable.Proto(), y.Immutable.Proto())
}
func equalGoat(x, y Goat) bool {
	if x.Target != y.Target ||
		x.FunnyPrank != y.FunnyPrank ||
		!pb.Equal(x.Immutable.Proto(), y.Immutable.Proto()) {
		return false
	}
	if len(x.Slaps) != len(y.Slaps) {
		return false
	}
	for i := range x.Slaps {
		if !equalSlap(x.Slaps[i], y.Slaps[i]) {
			return false
		}
	}
	return true
}
func equalDonkey(x, y Donkey) bool {
	return x.Pause == y.Pause &&
		x.Sleep == y.Sleep &&
		x.FunnyPrank == y.FunnyPrank &&
		pb.Equal(x.Immutable.Proto(), y.Immutable.Proto())
}
*/

type Eagle struct {
	Name          string
	Hounds        []string
	Desc          string
	DescLong      string
	Dreamers      []Dreamer
	Prong         int64
	Slaps         []Slap
	StateGoverner string
	PrankRating   string
	FunnyPrank    string
	Immutable     *EagleImmutable
}

type EagleImmutable struct {
	ID          string
	State       *pb.Eagle_States
	MissingCall *pb.Eagle_MissingCalls
	Birthday    time.Time
	Death       time.Time
	Started     time.Time
	LastUpdate  time.Time
	Creator     string
	empty       bool
}

type Dreamer struct {
	Name              string
	Desc              string
	DescLong          string
	PreSlaps          []Slap
	ContSlaps         []Slap
	ContSlapsInterval int32
	Animal            []interface{} // Could be either Goat or Donkey
	Ornamental        bool
	Amoeba            int64
	Heroes            int32
	FloppyDisk        int32
	MightiestDuck     bool
	FunnyPrank        string
	Immutable         *DreamerImmutable
}

type DreamerImmutable struct {
	ID          string
	State       *pb.Dreamer_States
	MissingCall *pb.Dreamer_MissingCalls
	Calls       int32
	Started     time.Time
	Stopped     time.Time
	LastUpdate  time.Time
	empty       bool
}

type Slap struct {
	Name       string
	Desc       string
	DescLong   string
	Args       pb.Message
	Tense      int32
	Interval   int32
	Homeland   uint32
	FunnyPrank string
	Immutable  *SlapImmutable
}

type SlapImmutable struct {
	ID          string
	Out         pb.Message
	MildSlap    bool
	PrettyPrint string
	State       *pb.Slap_States
	Started     time.Time
	Stopped     time.Time
	LastUpdate  time.Time
	LoveRadius  *LoveRadius
	empty       bool
}

type Goat struct {
	Target     string
	Slaps      []Slap
	FunnyPrank string
	Immutable  *GoatImmutable
}

type GoatImmutable struct {
	ID         string
	State      *pb.Goat_States
	Started    time.Time
	Stopped    time.Time
	LastUpdate time.Time
	empty      bool
}
type Donkey struct {
	Pause      bool
	Sleep      int32
	FunnyPrank string
	Immutable  *DonkeyImmutable
}

type DonkeyImmutable struct {
	ID         string
	State      *pb.Donkey_States
	Started    time.Time
	Stopped    time.Time
	LastUpdate time.Time
	empty      bool
}

type LoveRadius struct {
	Summer *SummerLove
	empty  bool
}

type SummerLove struct {
	Summary *SummerLoveSummary
	empty   bool
}

type SummerLoveSummary struct {
	Devices    []string
	ChangeType []pb.SummerType
	empty      bool
}

func (EagleImmutable) Proto() *pb.Eagle     { return nil }
func (DreamerImmutable) Proto() *pb.Dreamer { return nil }
func (SlapImmutable) Proto() *pb.Slap       { return nil }
func (GoatImmutable) Proto() *pb.Goat       { return nil }
func (DonkeyImmutable) Proto() *pb.Donkey   { return nil }