forked from CovenantSQL/CovenantSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createdb_gen_test.go
84 lines (76 loc) · 1.64 KB
/
createdb_gen_test.go
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
package types
// Code generated by github.com/CovenantSQL/HashStablePack DO NOT EDIT.
import (
"bytes"
"crypto/rand"
"encoding/binary"
"testing"
)
func TestMarshalHashCreateDatabase(t *testing.T) {
v := CreateDatabase{}
binary.Read(rand.Reader, binary.BigEndian, &v)
bts1, err := v.MarshalHash()
if err != nil {
t.Fatal(err)
}
bts2, err := v.MarshalHash()
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(bts1, bts2) {
t.Fatal("hash not stable")
}
}
func BenchmarkMarshalHashCreateDatabase(b *testing.B) {
v := CreateDatabase{}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
v.MarshalHash()
}
}
func BenchmarkAppendMsgCreateDatabase(b *testing.B) {
v := CreateDatabase{}
bts := make([]byte, 0, v.Msgsize())
bts, _ = v.MarshalHash()
b.SetBytes(int64(len(bts)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
bts, _ = v.MarshalHash()
}
}
func TestMarshalHashCreateDatabaseHeader(t *testing.T) {
v := CreateDatabaseHeader{}
binary.Read(rand.Reader, binary.BigEndian, &v)
bts1, err := v.MarshalHash()
if err != nil {
t.Fatal(err)
}
bts2, err := v.MarshalHash()
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(bts1, bts2) {
t.Fatal("hash not stable")
}
}
func BenchmarkMarshalHashCreateDatabaseHeader(b *testing.B) {
v := CreateDatabaseHeader{}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
v.MarshalHash()
}
}
func BenchmarkAppendMsgCreateDatabaseHeader(b *testing.B) {
v := CreateDatabaseHeader{}
bts := make([]byte, 0, v.Msgsize())
bts, _ = v.MarshalHash()
b.SetBytes(int64(len(bts)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
bts, _ = v.MarshalHash()
}
}