mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-16 09:50:45 +00:00
common: improve test (#20354)
This commit is contained in:
parent
56e242b06c
commit
f5e90eecff
2 changed files with 29 additions and 52 deletions
|
|
@ -19,41 +19,43 @@ package common
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
checker "gopkg.in/check.v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type BytesSuite struct{}
|
func TestCopyBytes(t *testing.T) {
|
||||||
|
input := []byte{1, 2, 3, 4}
|
||||||
|
|
||||||
var _ = checker.Suite(&BytesSuite{})
|
v := CopyBytes(input)
|
||||||
|
if !bytes.Equal(v, []byte{1, 2, 3, 4}) {
|
||||||
func (s *BytesSuite) TestCopyBytes(c *checker.C) {
|
t.Fatal("not equal after copy")
|
||||||
data1 := []byte{1, 2, 3, 4}
|
}
|
||||||
exp1 := []byte{1, 2, 3, 4}
|
v[0] = 99
|
||||||
res1 := CopyBytes(data1)
|
if bytes.Equal(v, input) {
|
||||||
c.Assert(res1, checker.DeepEquals, exp1)
|
t.Fatal("result is not a copy")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *BytesSuite) TestLeftPadBytes(c *checker.C) {
|
func TestLeftPadBytes(t *testing.T) {
|
||||||
val1 := []byte{1, 2, 3, 4}
|
|
||||||
exp1 := []byte{0, 0, 0, 0, 1, 2, 3, 4}
|
|
||||||
|
|
||||||
res1 := LeftPadBytes(val1, 8)
|
|
||||||
res2 := LeftPadBytes(val1, 2)
|
|
||||||
|
|
||||||
c.Assert(res1, checker.DeepEquals, exp1)
|
|
||||||
c.Assert(res2, checker.DeepEquals, val1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *BytesSuite) TestRightPadBytes(c *checker.C) {
|
|
||||||
val := []byte{1, 2, 3, 4}
|
val := []byte{1, 2, 3, 4}
|
||||||
exp := []byte{1, 2, 3, 4, 0, 0, 0, 0}
|
padded := []byte{0, 0, 0, 0, 1, 2, 3, 4}
|
||||||
|
|
||||||
resstd := RightPadBytes(val, 8)
|
if r := LeftPadBytes(val, 8); !bytes.Equal(r, padded) {
|
||||||
resshrt := RightPadBytes(val, 2)
|
t.Fatalf("LeftPadBytes(%v, 8) == %v", val, r)
|
||||||
|
}
|
||||||
|
if r := LeftPadBytes(val, 2); !bytes.Equal(r, val) {
|
||||||
|
t.Fatalf("LeftPadBytes(%v, 2) == %v", val, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c.Assert(resstd, checker.DeepEquals, exp)
|
func TestRightPadBytes(t *testing.T) {
|
||||||
c.Assert(resshrt, checker.DeepEquals, val)
|
val := []byte{1, 2, 3, 4}
|
||||||
|
padded := []byte{1, 2, 3, 4, 0, 0, 0, 0}
|
||||||
|
|
||||||
|
if r := RightPadBytes(val, 8); !bytes.Equal(r, padded) {
|
||||||
|
t.Fatalf("RightPadBytes(%v, 8) == %v", val, r)
|
||||||
|
}
|
||||||
|
if r := RightPadBytes(val, 2); !bytes.Equal(r, val) {
|
||||||
|
t.Fatalf("RightPadBytes(%v, 2) == %v", val, r)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFromHex(t *testing.T) {
|
func TestFromHex(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
|
||||||
// This file is part of the go-ethereum library.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
|
||||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
checker "gopkg.in/check.v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Test(t *testing.T) { checker.TestingT(t) }
|
|
||||||
Loading…
Reference in a new issue