Rewrite tests (#3)

- rewrite tests
- remove gomega from deps
This commit is contained in:
Evgeniy Kulikov 2019-05-29 14:10:17 +03:00 committed by GitHub
parent d5efd8bdce
commit 6b644651fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 72 deletions

2
go.mod
View file

@ -1,3 +1,3 @@
module github.com/nspcc-dev/tzhash module github.com/nspcc-dev/tzhash
require github.com/onsi/gomega v1.4.2 require github.com/stretchr/testify v1.3.0

34
go.sum
View file

@ -1,26 +1,8 @@
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View file

@ -5,7 +5,7 @@ import (
"math/rand" "math/rand"
"testing" "testing"
. "github.com/onsi/gomega" "github.com/stretchr/testify/require"
) )
func TestHash(t *testing.T) { func TestHash(t *testing.T) {
@ -15,14 +15,12 @@ func TestHash(t *testing.T) {
err error err error
h, h1, h2 [hashSize]byte h, h1, h2 [hashSize]byte
b []byte b []byte
g = NewGomegaWithT(t)
) )
b = make([]byte, 64) b = make([]byte, 64)
n, err = rand.Read(b) n, err = rand.Read(b)
g.Expect(n).To(Equal(64)) require.Equal(t, 64, n)
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
// Test if our hashing is really homomorphic // Test if our hashing is really homomorphic
h = Sum(b) h = Sum(b)
@ -30,13 +28,12 @@ func TestHash(t *testing.T) {
h2 = Sum(b[32:]) h2 = Sum(b[32:])
err = c1.UnmarshalBinary(h1[:]) err = c1.UnmarshalBinary(h1[:])
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
err = c2.UnmarshalBinary(h2[:]) err = c2.UnmarshalBinary(h2[:])
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
c1.Mul(&c1, &c2) c1.Mul(&c1, &c2)
g.Expect(c1.ByteArray()).To(Equal(h)) require.Equal(t, h, c1.ByteArray())
} }
var testCases = []struct { var testCases = []struct {
@ -60,26 +57,24 @@ var testCases = []struct {
func TestConcat(t *testing.T) { func TestConcat(t *testing.T) {
var ( var (
got, expected []byte actual, expect []byte
ps [][]byte ps [][]byte
err error err error
g = NewGomegaWithT(t)
) )
for _, tc := range testCases { for _, tc := range testCases {
expected, err = hex.DecodeString(tc.Hash) expect, err = hex.DecodeString(tc.Hash)
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
ps = make([][]byte, len(tc.Parts)) ps = make([][]byte, len(tc.Parts))
for j := 0; j < len(tc.Parts); j++ { for j := 0; j < len(tc.Parts); j++ {
ps[j], err = hex.DecodeString(tc.Parts[j]) ps[j], err = hex.DecodeString(tc.Parts[j])
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
} }
got, err = Concat(ps) actual, err = Concat(ps)
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
g.Expect(got).To(Equal(expected)) require.Equal(t, expect, actual)
} }
} }
@ -91,21 +86,19 @@ func TestValidate(t *testing.T) {
err error err error
) )
g := NewGomegaWithT(t)
for _, tc := range testCases { for _, tc := range testCases {
hash, _ = hex.DecodeString(tc.Hash) hash, _ = hex.DecodeString(tc.Hash)
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
ps = make([][]byte, len(tc.Parts)) ps = make([][]byte, len(tc.Parts))
for j := 0; j < len(tc.Parts); j++ { for j := 0; j < len(tc.Parts); j++ {
ps[j], _ = hex.DecodeString(tc.Parts[j]) ps[j], _ = hex.DecodeString(tc.Parts[j])
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
} }
got, err = Validate(hash, ps) got, err = Validate(hash, ps)
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
g.Expect(got).To(Equal(true)) require.True(t, got)
} }
} }
@ -128,26 +121,24 @@ func TestSubtract(t *testing.T) {
var ( var (
a, b, c, r []byte a, b, c, r []byte
err error err error
g = NewGomegaWithT(t)
) )
for _, tc := range testCasesSubtract { for _, tc := range testCasesSubtract {
a, err = hex.DecodeString(tc.first) a, err = hex.DecodeString(tc.first)
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
b, err = hex.DecodeString(tc.second) b, err = hex.DecodeString(tc.second)
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
c, err = hex.DecodeString(tc.result) c, err = hex.DecodeString(tc.result)
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
r, err = SubtractR(c, b) r, err = SubtractR(c, b)
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
g.Expect(r).To(Equal(a)) require.Equal(t, a, r)
r, err = SubtractL(c, a) r, err = SubtractL(c, a)
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
g.Expect(r).To(Equal(b)) require.Equal(t, b, r)
} }
} }

View file

@ -6,7 +6,7 @@ import (
"time" "time"
"github.com/nspcc-dev/tzhash/gf127" "github.com/nspcc-dev/tzhash/gf127"
. "github.com/onsi/gomega" "github.com/stretchr/testify/require"
) )
func init() { func init() {
@ -35,23 +35,19 @@ func TestSL2_MarshalBinary(t *testing.T) {
var ( var (
a = random() a = random()
b = new(sl2) b = new(sl2)
g = NewGomegaWithT(t)
) )
data, err := a.MarshalBinary() data, err := a.MarshalBinary()
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
err = b.UnmarshalBinary(data) err = b.UnmarshalBinary(data)
g.Expect(err).NotTo(HaveOccurred()) require.NoError(t, err)
g.Expect(a).To(Equal(b)) require.Equal(t, a, b)
} }
func TestInv(t *testing.T) { func TestInv(t *testing.T) {
var ( var a, b, c *sl2
a, b, c *sl2
g = NewGomegaWithT(t)
)
c = new(sl2) c = new(sl2)
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
@ -59,6 +55,6 @@ func TestInv(t *testing.T) {
b = Inv(a) b = Inv(a)
c = c.Mul(a, b) c = c.Mul(a, b)
g.Expect(*c).To(Equal(id)) require.Equal(t, id, *c)
} }
} }