1
2
3
4 package castvalue
5
6 import (
7 fmt "fmt"
8 _ "github.com/gogo/protobuf/gogoproto"
9 github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb"
10 github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto"
11 proto "github.com/gogo/protobuf/proto"
12 go_parser "go/parser"
13 math "math"
14 math_rand "math/rand"
15 testing "testing"
16 time "time"
17 )
18
19
20 var _ = proto.Marshal
21 var _ = fmt.Errorf
22 var _ = math.Inf
23
24 func TestCastawayProto(t *testing.T) {
25 seed := time.Now().UnixNano()
26 popr := math_rand.New(math_rand.NewSource(seed))
27 p := NewPopulatedCastaway(popr, false)
28 dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
29 if err != nil {
30 t.Fatalf("seed = %d, err = %v", seed, err)
31 }
32 msg := &Castaway{}
33 if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
34 t.Fatalf("seed = %d, err = %v", seed, err)
35 }
36 littlefuzz := make([]byte, len(dAtA))
37 copy(littlefuzz, dAtA)
38 for i := range dAtA {
39 dAtA[i] = byte(popr.Intn(256))
40 }
41 if err := p.VerboseEqual(msg); err != nil {
42 t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
43 }
44 if !p.Equal(msg) {
45 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
46 }
47 if len(littlefuzz) > 0 {
48 fuzzamount := 100
49 for i := 0; i < fuzzamount; i++ {
50 littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
51 littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
52 }
53
54 _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
55 }
56 }
57
58 func BenchmarkCastawayProtoMarshal(b *testing.B) {
59 popr := math_rand.New(math_rand.NewSource(616))
60 total := 0
61 pops := make([]*Castaway, 10000)
62 for i := 0; i < 10000; i++ {
63 pops[i] = NewPopulatedCastaway(popr, false)
64 }
65 b.ResetTimer()
66 for i := 0; i < b.N; i++ {
67 dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
68 if err != nil {
69 panic(err)
70 }
71 total += len(dAtA)
72 }
73 b.SetBytes(int64(total / b.N))
74 }
75
76 func BenchmarkCastawayProtoUnmarshal(b *testing.B) {
77 popr := math_rand.New(math_rand.NewSource(616))
78 total := 0
79 datas := make([][]byte, 10000)
80 for i := 0; i < 10000; i++ {
81 dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedCastaway(popr, false))
82 if err != nil {
83 panic(err)
84 }
85 datas[i] = dAtA
86 }
87 msg := &Castaway{}
88 b.ResetTimer()
89 for i := 0; i < b.N; i++ {
90 total += len(datas[i%10000])
91 if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
92 panic(err)
93 }
94 }
95 b.SetBytes(int64(total / b.N))
96 }
97
98 func TestWilsonProto(t *testing.T) {
99 seed := time.Now().UnixNano()
100 popr := math_rand.New(math_rand.NewSource(seed))
101 p := NewPopulatedWilson(popr, false)
102 dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
103 if err != nil {
104 t.Fatalf("seed = %d, err = %v", seed, err)
105 }
106 msg := &Wilson{}
107 if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
108 t.Fatalf("seed = %d, err = %v", seed, err)
109 }
110 littlefuzz := make([]byte, len(dAtA))
111 copy(littlefuzz, dAtA)
112 for i := range dAtA {
113 dAtA[i] = byte(popr.Intn(256))
114 }
115 if err := p.VerboseEqual(msg); err != nil {
116 t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
117 }
118 if !p.Equal(msg) {
119 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
120 }
121 if len(littlefuzz) > 0 {
122 fuzzamount := 100
123 for i := 0; i < fuzzamount; i++ {
124 littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256))
125 littlefuzz = append(littlefuzz, byte(popr.Intn(256)))
126 }
127
128 _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg)
129 }
130 }
131
132 func BenchmarkWilsonProtoMarshal(b *testing.B) {
133 popr := math_rand.New(math_rand.NewSource(616))
134 total := 0
135 pops := make([]*Wilson, 10000)
136 for i := 0; i < 10000; i++ {
137 pops[i] = NewPopulatedWilson(popr, false)
138 }
139 b.ResetTimer()
140 for i := 0; i < b.N; i++ {
141 dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
142 if err != nil {
143 panic(err)
144 }
145 total += len(dAtA)
146 }
147 b.SetBytes(int64(total / b.N))
148 }
149
150 func BenchmarkWilsonProtoUnmarshal(b *testing.B) {
151 popr := math_rand.New(math_rand.NewSource(616))
152 total := 0
153 datas := make([][]byte, 10000)
154 for i := 0; i < 10000; i++ {
155 dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedWilson(popr, false))
156 if err != nil {
157 panic(err)
158 }
159 datas[i] = dAtA
160 }
161 msg := &Wilson{}
162 b.ResetTimer()
163 for i := 0; i < b.N; i++ {
164 total += len(datas[i%10000])
165 if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
166 panic(err)
167 }
168 }
169 b.SetBytes(int64(total / b.N))
170 }
171
172 func TestCastawayJSON(t *testing.T) {
173 seed := time.Now().UnixNano()
174 popr := math_rand.New(math_rand.NewSource(seed))
175 p := NewPopulatedCastaway(popr, true)
176 marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
177 jsondata, err := marshaler.MarshalToString(p)
178 if err != nil {
179 t.Fatalf("seed = %d, err = %v", seed, err)
180 }
181 msg := &Castaway{}
182 err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
183 if err != nil {
184 t.Fatalf("seed = %d, err = %v", seed, err)
185 }
186 if err := p.VerboseEqual(msg); err != nil {
187 t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
188 }
189 if !p.Equal(msg) {
190 t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
191 }
192 }
193 func TestWilsonJSON(t *testing.T) {
194 seed := time.Now().UnixNano()
195 popr := math_rand.New(math_rand.NewSource(seed))
196 p := NewPopulatedWilson(popr, true)
197 marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
198 jsondata, err := marshaler.MarshalToString(p)
199 if err != nil {
200 t.Fatalf("seed = %d, err = %v", seed, err)
201 }
202 msg := &Wilson{}
203 err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
204 if err != nil {
205 t.Fatalf("seed = %d, err = %v", seed, err)
206 }
207 if err := p.VerboseEqual(msg); err != nil {
208 t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
209 }
210 if !p.Equal(msg) {
211 t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
212 }
213 }
214 func TestCastawayProtoText(t *testing.T) {
215 seed := time.Now().UnixNano()
216 popr := math_rand.New(math_rand.NewSource(seed))
217 p := NewPopulatedCastaway(popr, true)
218 dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
219 msg := &Castaway{}
220 if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
221 t.Fatalf("seed = %d, err = %v", seed, err)
222 }
223 if err := p.VerboseEqual(msg); err != nil {
224 t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
225 }
226 if !p.Equal(msg) {
227 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
228 }
229 }
230
231 func TestCastawayProtoCompactText(t *testing.T) {
232 seed := time.Now().UnixNano()
233 popr := math_rand.New(math_rand.NewSource(seed))
234 p := NewPopulatedCastaway(popr, true)
235 dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
236 msg := &Castaway{}
237 if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
238 t.Fatalf("seed = %d, err = %v", seed, err)
239 }
240 if err := p.VerboseEqual(msg); err != nil {
241 t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
242 }
243 if !p.Equal(msg) {
244 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
245 }
246 }
247
248 func TestWilsonProtoText(t *testing.T) {
249 seed := time.Now().UnixNano()
250 popr := math_rand.New(math_rand.NewSource(seed))
251 p := NewPopulatedWilson(popr, true)
252 dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
253 msg := &Wilson{}
254 if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
255 t.Fatalf("seed = %d, err = %v", seed, err)
256 }
257 if err := p.VerboseEqual(msg); err != nil {
258 t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
259 }
260 if !p.Equal(msg) {
261 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
262 }
263 }
264
265 func TestWilsonProtoCompactText(t *testing.T) {
266 seed := time.Now().UnixNano()
267 popr := math_rand.New(math_rand.NewSource(seed))
268 p := NewPopulatedWilson(popr, true)
269 dAtA := github_com_gogo_protobuf_proto.CompactTextString(p)
270 msg := &Wilson{}
271 if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
272 t.Fatalf("seed = %d, err = %v", seed, err)
273 }
274 if err := p.VerboseEqual(msg); err != nil {
275 t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
276 }
277 if !p.Equal(msg) {
278 t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
279 }
280 }
281
282 func TestCastvalueDescription(t *testing.T) {
283 CastvalueDescription()
284 }
285 func TestCastawayVerboseEqual(t *testing.T) {
286 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
287 p := NewPopulatedCastaway(popr, false)
288 dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
289 if err != nil {
290 panic(err)
291 }
292 msg := &Castaway{}
293 if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
294 panic(err)
295 }
296 if err := p.VerboseEqual(msg); err != nil {
297 t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
298 }
299 }
300 func TestWilsonVerboseEqual(t *testing.T) {
301 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
302 p := NewPopulatedWilson(popr, false)
303 dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
304 if err != nil {
305 panic(err)
306 }
307 msg := &Wilson{}
308 if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
309 panic(err)
310 }
311 if err := p.VerboseEqual(msg); err != nil {
312 t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
313 }
314 }
315 func TestCastawayFace(t *testing.T) {
316 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
317 p := NewPopulatedCastaway(popr, true)
318 msg := p.TestProto()
319 if !p.Equal(msg) {
320 t.Fatalf("%#v !Face Equal %#v", msg, p)
321 }
322 }
323 func TestWilsonFace(t *testing.T) {
324 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
325 p := NewPopulatedWilson(popr, true)
326 msg := p.TestProto()
327 if !p.Equal(msg) {
328 t.Fatalf("%#v !Face Equal %#v", msg, p)
329 }
330 }
331 func TestCastawayGoString(t *testing.T) {
332 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
333 p := NewPopulatedCastaway(popr, false)
334 s1 := p.GoString()
335 s2 := fmt.Sprintf("%#v", p)
336 if s1 != s2 {
337 t.Fatalf("GoString want %v got %v", s1, s2)
338 }
339 _, err := go_parser.ParseExpr(s1)
340 if err != nil {
341 t.Fatal(err)
342 }
343 }
344 func TestWilsonGoString(t *testing.T) {
345 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
346 p := NewPopulatedWilson(popr, false)
347 s1 := p.GoString()
348 s2 := fmt.Sprintf("%#v", p)
349 if s1 != s2 {
350 t.Fatalf("GoString want %v got %v", s1, s2)
351 }
352 _, err := go_parser.ParseExpr(s1)
353 if err != nil {
354 t.Fatal(err)
355 }
356 }
357 func TestCastawaySize(t *testing.T) {
358 seed := time.Now().UnixNano()
359 popr := math_rand.New(math_rand.NewSource(seed))
360 p := NewPopulatedCastaway(popr, true)
361 size2 := github_com_gogo_protobuf_proto.Size(p)
362 dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
363 if err != nil {
364 t.Fatalf("seed = %d, err = %v", seed, err)
365 }
366 size := p.Size()
367 if len(dAtA) != size {
368 t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
369 }
370 if size2 != size {
371 t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
372 }
373 size3 := github_com_gogo_protobuf_proto.Size(p)
374 if size3 != size {
375 t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
376 }
377 }
378
379 func BenchmarkCastawaySize(b *testing.B) {
380 popr := math_rand.New(math_rand.NewSource(616))
381 total := 0
382 pops := make([]*Castaway, 1000)
383 for i := 0; i < 1000; i++ {
384 pops[i] = NewPopulatedCastaway(popr, false)
385 }
386 b.ResetTimer()
387 for i := 0; i < b.N; i++ {
388 total += pops[i%1000].Size()
389 }
390 b.SetBytes(int64(total / b.N))
391 }
392
393 func TestWilsonSize(t *testing.T) {
394 seed := time.Now().UnixNano()
395 popr := math_rand.New(math_rand.NewSource(seed))
396 p := NewPopulatedWilson(popr, true)
397 size2 := github_com_gogo_protobuf_proto.Size(p)
398 dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
399 if err != nil {
400 t.Fatalf("seed = %d, err = %v", seed, err)
401 }
402 size := p.Size()
403 if len(dAtA) != size {
404 t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))
405 }
406 if size2 != size {
407 t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2)
408 }
409 size3 := github_com_gogo_protobuf_proto.Size(p)
410 if size3 != size {
411 t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3)
412 }
413 }
414
415 func BenchmarkWilsonSize(b *testing.B) {
416 popr := math_rand.New(math_rand.NewSource(616))
417 total := 0
418 pops := make([]*Wilson, 1000)
419 for i := 0; i < 1000; i++ {
420 pops[i] = NewPopulatedWilson(popr, false)
421 }
422 b.ResetTimer()
423 for i := 0; i < b.N; i++ {
424 total += pops[i%1000].Size()
425 }
426 b.SetBytes(int64(total / b.N))
427 }
428
429 func TestCastawayStringer(t *testing.T) {
430 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
431 p := NewPopulatedCastaway(popr, false)
432 s1 := p.String()
433 s2 := fmt.Sprintf("%v", p)
434 if s1 != s2 {
435 t.Fatalf("String want %v got %v", s1, s2)
436 }
437 }
438 func TestWilsonStringer(t *testing.T) {
439 popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
440 p := NewPopulatedWilson(popr, false)
441 s1 := p.String()
442 s2 := fmt.Sprintf("%v", p)
443 if s1 != s2 {
444 t.Fatalf("String want %v got %v", s1, s2)
445 }
446 }
447
448
449
View as plain text