github.com/annchain/OG@v0.0.9/common/hash_gen_test.go (about)

     1  package common
     2  
     3  // Code generated by github.com/tinylib/msgp DO NOT EDIT.
     4  
     5  import (
     6  	"bytes"
     7  	"github.com/annchain/OG/arefactor/og/types"
     8  	"testing"
     9  
    10  	"github.com/tinylib/msgp/msgp"
    11  )
    12  
    13  func TestMarshalUnmarshalHash(t *testing.T) {
    14  	v := types.Hash{}
    15  	bts, err := v.MarshalMsg(nil)
    16  	if err != nil {
    17  		t.Fatal(err)
    18  	}
    19  	left, err := v.UnmarshalMsg(bts)
    20  	if err != nil {
    21  		t.Fatal(err)
    22  	}
    23  	if len(left) > 0 {
    24  		t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left)
    25  	}
    26  
    27  	left, err = msgp.Skip(bts)
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  	if len(left) > 0 {
    32  		t.Errorf("%d bytes left over after Skip(): %q", len(left), left)
    33  	}
    34  }
    35  
    36  func BenchmarkMarshalMsgHash(b *testing.B) {
    37  	v := types.Hash{}
    38  	b.ReportAllocs()
    39  	b.ResetTimer()
    40  	for i := 0; i < b.N; i++ {
    41  		v.MarshalMsg(nil)
    42  	}
    43  }
    44  
    45  func BenchmarkAppendMsgHash(b *testing.B) {
    46  	v := types.Hash{}
    47  	bts := make([]byte, 0, v.Msgsize())
    48  	bts, _ = v.MarshalMsg(bts[0:0])
    49  	b.SetBytes(int64(len(bts)))
    50  	b.ReportAllocs()
    51  	b.ResetTimer()
    52  	for i := 0; i < b.N; i++ {
    53  		bts, _ = v.MarshalMsg(bts[0:0])
    54  	}
    55  }
    56  
    57  func BenchmarkUnmarshalHash(b *testing.B) {
    58  	v := types.Hash{}
    59  	bts, _ := v.MarshalMsg(nil)
    60  	b.ReportAllocs()
    61  	b.SetBytes(int64(len(bts)))
    62  	b.ResetTimer()
    63  	for i := 0; i < b.N; i++ {
    64  		_, err := v.UnmarshalMsg(bts)
    65  		if err != nil {
    66  			b.Fatal(err)
    67  		}
    68  	}
    69  }
    70  
    71  func TestEncodeDecodeHash(t *testing.T) {
    72  	v := types.Hash{}
    73  	var buf bytes.Buffer
    74  	msgp.Encode(&buf, &v)
    75  
    76  	m := v.Msgsize()
    77  	if buf.Len() > m {
    78  		t.Logf("WARNING: Msgsize() for %v is inaccurate", v)
    79  	}
    80  
    81  	vn := types.Hash{}
    82  	err := msgp.Decode(&buf, &vn)
    83  	if err != nil {
    84  		t.Error(err)
    85  	}
    86  
    87  	buf.Reset()
    88  	msgp.Encode(&buf, &v)
    89  	err = msgp.NewReader(&buf).Skip()
    90  	if err != nil {
    91  		t.Error(err)
    92  	}
    93  }
    94  
    95  func BenchmarkEncodeHash(b *testing.B) {
    96  	v := types.Hash{}
    97  	var buf bytes.Buffer
    98  	msgp.Encode(&buf, &v)
    99  	b.SetBytes(int64(buf.Len()))
   100  	en := msgp.NewWriter(msgp.Nowhere)
   101  	b.ReportAllocs()
   102  	b.ResetTimer()
   103  	for i := 0; i < b.N; i++ {
   104  		v.EncodeMsg(en)
   105  	}
   106  	en.Flush()
   107  }
   108  
   109  func BenchmarkDecodeHash(b *testing.B) {
   110  	v := types.Hash{}
   111  	var buf bytes.Buffer
   112  	msgp.Encode(&buf, &v)
   113  	b.SetBytes(int64(buf.Len()))
   114  	rd := msgp.NewEndlessReader(buf.Bytes(), b)
   115  	dc := msgp.NewReader(rd)
   116  	b.ReportAllocs()
   117  	b.ResetTimer()
   118  	for i := 0; i < b.N; i++ {
   119  		err := v.DecodeMsg(dc)
   120  		if err != nil {
   121  			b.Fatal(err)
   122  		}
   123  	}
   124  }
   125  
   126  func TestMarshalUnmarshalHashBytes(t *testing.T) {
   127  	v := types.HashBytes{}
   128  	bts, err := v.MarshalMsg(nil)
   129  	if err != nil {
   130  		t.Fatal(err)
   131  	}
   132  	left, err := v.UnmarshalMsg(bts)
   133  	if err != nil {
   134  		t.Fatal(err)
   135  	}
   136  	if len(left) > 0 {
   137  		t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left)
   138  	}
   139  
   140  	left, err = msgp.Skip(bts)
   141  	if err != nil {
   142  		t.Fatal(err)
   143  	}
   144  	if len(left) > 0 {
   145  		t.Errorf("%d bytes left over after Skip(): %q", len(left), left)
   146  	}
   147  }
   148  
   149  func BenchmarkMarshalMsgHashBytes(b *testing.B) {
   150  	v := types.HashBytes{}
   151  	b.ReportAllocs()
   152  	b.ResetTimer()
   153  	for i := 0; i < b.N; i++ {
   154  		v.MarshalMsg(nil)
   155  	}
   156  }
   157  
   158  func BenchmarkAppendMsgHashBytes(b *testing.B) {
   159  	v := types.HashBytes{}
   160  	bts := make([]byte, 0, v.Msgsize())
   161  	bts, _ = v.MarshalMsg(bts[0:0])
   162  	b.SetBytes(int64(len(bts)))
   163  	b.ReportAllocs()
   164  	b.ResetTimer()
   165  	for i := 0; i < b.N; i++ {
   166  		bts, _ = v.MarshalMsg(bts[0:0])
   167  	}
   168  }
   169  
   170  func BenchmarkUnmarshalHashBytes(b *testing.B) {
   171  	v := types.HashBytes{}
   172  	bts, _ := v.MarshalMsg(nil)
   173  	b.ReportAllocs()
   174  	b.SetBytes(int64(len(bts)))
   175  	b.ResetTimer()
   176  	for i := 0; i < b.N; i++ {
   177  		_, err := v.UnmarshalMsg(bts)
   178  		if err != nil {
   179  			b.Fatal(err)
   180  		}
   181  	}
   182  }
   183  
   184  func TestEncodeDecodeHashBytes(t *testing.T) {
   185  	v := types.HashBytes{}
   186  	var buf bytes.Buffer
   187  	msgp.Encode(&buf, &v)
   188  
   189  	m := v.Msgsize()
   190  	if buf.Len() > m {
   191  		t.Logf("WARNING: Msgsize() for %v is inaccurate", v)
   192  	}
   193  
   194  	vn := types.HashBytes{}
   195  	err := msgp.Decode(&buf, &vn)
   196  	if err != nil {
   197  		t.Error(err)
   198  	}
   199  
   200  	buf.Reset()
   201  	msgp.Encode(&buf, &v)
   202  	err = msgp.NewReader(&buf).Skip()
   203  	if err != nil {
   204  		t.Error(err)
   205  	}
   206  }
   207  
   208  func BenchmarkEncodeHashBytes(b *testing.B) {
   209  	v := types.HashBytes{}
   210  	var buf bytes.Buffer
   211  	msgp.Encode(&buf, &v)
   212  	b.SetBytes(int64(buf.Len()))
   213  	en := msgp.NewWriter(msgp.Nowhere)
   214  	b.ReportAllocs()
   215  	b.ResetTimer()
   216  	for i := 0; i < b.N; i++ {
   217  		v.EncodeMsg(en)
   218  	}
   219  	en.Flush()
   220  }
   221  
   222  func BenchmarkDecodeHashBytes(b *testing.B) {
   223  	v := types.HashBytes{}
   224  	var buf bytes.Buffer
   225  	msgp.Encode(&buf, &v)
   226  	b.SetBytes(int64(buf.Len()))
   227  	rd := msgp.NewEndlessReader(buf.Bytes(), b)
   228  	dc := msgp.NewReader(rd)
   229  	b.ReportAllocs()
   230  	b.ResetTimer()
   231  	for i := 0; i < b.N; i++ {
   232  		err := v.DecodeMsg(dc)
   233  		if err != nil {
   234  			b.Fatal(err)
   235  		}
   236  	}
   237  }
   238  
   239  func TestMarshalUnmarshalHashes(t *testing.T) {
   240  	v := types.Hashes{}
   241  	bts, err := v.MarshalMsg(nil)
   242  	if err != nil {
   243  		t.Fatal(err)
   244  	}
   245  	left, err := v.UnmarshalMsg(bts)
   246  	if err != nil {
   247  		t.Fatal(err)
   248  	}
   249  	if len(left) > 0 {
   250  		t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left)
   251  	}
   252  
   253  	left, err = msgp.Skip(bts)
   254  	if err != nil {
   255  		t.Fatal(err)
   256  	}
   257  	if len(left) > 0 {
   258  		t.Errorf("%d bytes left over after Skip(): %q", len(left), left)
   259  	}
   260  }
   261  
   262  func BenchmarkMarshalMsgHashes(b *testing.B) {
   263  	v := types.Hashes{}
   264  	b.ReportAllocs()
   265  	b.ResetTimer()
   266  	for i := 0; i < b.N; i++ {
   267  		v.MarshalMsg(nil)
   268  	}
   269  }
   270  
   271  func BenchmarkAppendMsgHashes(b *testing.B) {
   272  	v := types.Hashes{}
   273  	bts := make([]byte, 0, v.Msgsize())
   274  	bts, _ = v.MarshalMsg(bts[0:0])
   275  	b.SetBytes(int64(len(bts)))
   276  	b.ReportAllocs()
   277  	b.ResetTimer()
   278  	for i := 0; i < b.N; i++ {
   279  		bts, _ = v.MarshalMsg(bts[0:0])
   280  	}
   281  }
   282  
   283  func BenchmarkUnmarshalHashes(b *testing.B) {
   284  	v := types.Hashes{}
   285  	bts, _ := v.MarshalMsg(nil)
   286  	b.ReportAllocs()
   287  	b.SetBytes(int64(len(bts)))
   288  	b.ResetTimer()
   289  	for i := 0; i < b.N; i++ {
   290  		_, err := v.UnmarshalMsg(bts)
   291  		if err != nil {
   292  			b.Fatal(err)
   293  		}
   294  	}
   295  }
   296  
   297  func TestEncodeDecodeHashes(t *testing.T) {
   298  	v := types.Hashes{}
   299  	var buf bytes.Buffer
   300  	msgp.Encode(&buf, &v)
   301  
   302  	m := v.Msgsize()
   303  	if buf.Len() > m {
   304  		t.Logf("WARNING: Msgsize() for %v is inaccurate", v)
   305  	}
   306  
   307  	vn := types.Hashes{}
   308  	err := msgp.Decode(&buf, &vn)
   309  	if err != nil {
   310  		t.Error(err)
   311  	}
   312  
   313  	buf.Reset()
   314  	msgp.Encode(&buf, &v)
   315  	err = msgp.NewReader(&buf).Skip()
   316  	if err != nil {
   317  		t.Error(err)
   318  	}
   319  }
   320  
   321  func BenchmarkEncodeHashes(b *testing.B) {
   322  	v := types.Hashes{}
   323  	var buf bytes.Buffer
   324  	msgp.Encode(&buf, &v)
   325  	b.SetBytes(int64(buf.Len()))
   326  	en := msgp.NewWriter(msgp.Nowhere)
   327  	b.ReportAllocs()
   328  	b.ResetTimer()
   329  	for i := 0; i < b.N; i++ {
   330  		v.EncodeMsg(en)
   331  	}
   332  	en.Flush()
   333  }
   334  
   335  func BenchmarkDecodeHashes(b *testing.B) {
   336  	v := types.Hashes{}
   337  	var buf bytes.Buffer
   338  	msgp.Encode(&buf, &v)
   339  	b.SetBytes(int64(buf.Len()))
   340  	rd := msgp.NewEndlessReader(buf.Bytes(), b)
   341  	dc := msgp.NewReader(rd)
   342  	b.ReportAllocs()
   343  	b.ResetTimer()
   344  	for i := 0; i < b.N; i++ {
   345  		err := v.DecodeMsg(dc)
   346  		if err != nil {
   347  			b.Fatal(err)
   348  		}
   349  	}
   350  }