Skip to content

Commit

Permalink
util/set: migrate test-infra to testify (pingcap#26488)
Browse files Browse the repository at this point in the history
  • Loading branch information
PragmaTwice authored Jul 29, 2021
1 parent 65400b6 commit 2bace00
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 43 deletions.
21 changes: 8 additions & 13 deletions util/set/float64_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ package set
import (
"testing"

"github.com/pingcap/check"
"github.com/stretchr/testify/assert"
)

func TestT(t *testing.T) {
check.TestingT(t)
}

var _ = check.Suite(&float64SetTestSuite{})

type float64SetTestSuite struct{}
func TestFloat64Set(t *testing.T) {
t.Parallel()
assert := assert.New(t)

func (s *float64SetTestSuite) TestFloat64Set(c *check.C) {
set := NewFloat64Set()
vals := []float64{1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0}
for i := range vals {
Expand All @@ -37,12 +32,12 @@ func (s *float64SetTestSuite) TestFloat64Set(c *check.C) {
set.Insert(vals[i])
set.Insert(vals[i])
}
c.Assert(set.Count(), check.Equals, len(vals))
assert.Equal(len(vals), set.Count())

c.Assert(len(set), check.Equals, len(vals))
assert.Equal(len(vals), len(set))
for i := range vals {
c.Assert(set.Exist(vals[i]), check.IsTrue)
assert.True(set.Exist(vals[i]))
}

c.Assert(set.Exist(3), check.IsFalse)
assert.False(set.Exist(3))
}
34 changes: 19 additions & 15 deletions util/set/int_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
package set

import (
"github.com/pingcap/check"
)
"testing"

var _ = check.Suite(&intSetTestSuite{})
"github.com/stretchr/testify/assert"
)

type intSetTestSuite struct{}
func TestIntSet(t *testing.T) {
t.Parallel()
assert := assert.New(t)

func (s *intSetTestSuite) TestIntSet(c *check.C) {
set := NewIntSet()
vals := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
for i := range vals {
Expand All @@ -31,17 +32,20 @@ func (s *intSetTestSuite) TestIntSet(c *check.C) {
set.Insert(vals[i])
set.Insert(vals[i])
}
c.Assert(set.Count(), check.Equals, len(vals))
assert.Equal(len(vals), set.Count())

c.Assert(len(set), check.Equals, len(vals))
assert.Equal(len(vals), len(set))
for i := range vals {
c.Assert(set.Exist(vals[i]), check.IsTrue)
assert.True(set.Exist(vals[i]))
}

c.Assert(set.Exist(11), check.IsFalse)
assert.False(set.Exist(11))
}

func (s *intSetTestSuite) TestInt64Set(c *check.C) {
func TestInt64Set(t *testing.T) {
t.Parallel()
assert := assert.New(t)

set := NewInt64Set()
vals := []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
for i := range vals {
Expand All @@ -52,16 +56,16 @@ func (s *intSetTestSuite) TestInt64Set(c *check.C) {
set.Insert(vals[i])
}

c.Assert(len(set), check.Equals, len(vals))
assert.Equal(len(vals), len(set))
for i := range vals {
c.Assert(set.Exist(vals[i]), check.IsTrue)
assert.True(set.Exist(vals[i]))
}

c.Assert(set.Exist(11), check.IsFalse)
assert.False(set.Exist(11))

set = NewInt64Set(1, 2, 3, 4, 5, 6)
for i := 1; i < 7; i++ {
c.Assert(set.Exist(int64(i)), check.IsTrue)
assert.True(set.Exist(int64(i)))
}
c.Assert(set.Exist(7), check.IsFalse)
assert.False(set.Exist(7))
}
26 changes: 26 additions & 0 deletions util/set/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2021 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package set

import (
"testing"

"github.com/pingcap/tidb/util/testbridge"
"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
testbridge.WorkaroundGoCheckFlags()
goleak.VerifyTestMain(m)
}
30 changes: 15 additions & 15 deletions util/set/string_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ package set

import (
"fmt"
"testing"

"github.com/pingcap/check"
"github.com/stretchr/testify/assert"
)

var _ = check.Suite(&stringSetTestSuite{})
func TestStringSet(t *testing.T) {
t.Parallel()
assert := assert.New(t)

type stringSetTestSuite struct{}

func (s *stringSetTestSuite) TestStringSet(c *check.C) {
set := NewStringSet()
vals := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}
for i := range vals {
Expand All @@ -33,32 +33,32 @@ func (s *stringSetTestSuite) TestStringSet(c *check.C) {
set.Insert(vals[i])
set.Insert(vals[i])
}
c.Assert(set.Count(), check.Equals, len(vals))
assert.Equal(len(vals), set.Count())

c.Assert(len(set), check.Equals, len(vals))
assert.Equal(len(vals), len(set))
for i := range vals {
c.Assert(set.Exist(vals[i]), check.IsTrue)
assert.True(set.Exist(vals[i]))
}

c.Assert(set.Exist("11"), check.IsFalse)
assert.False(set.Exist("11"))

set = NewStringSet("1", "2", "3", "4", "5", "6")
for i := 1; i < 7; i++ {
c.Assert(set.Exist(fmt.Sprintf("%d", i)), check.IsTrue)
assert.True(set.Exist(fmt.Sprintf("%d", i)))
}
c.Assert(set.Exist("7"), check.IsFalse)
assert.False(set.Exist("7"))

s1 := NewStringSet("1", "2", "3")
s2 := NewStringSet("4", "2", "3")
s3 := s1.Intersection(s2)
c.Assert(s3, check.DeepEquals, NewStringSet("2", "3"))
assert.Equal(NewStringSet("2", "3"), s3)

s4 := NewStringSet("4", "5", "3")
c.Assert(s3.Intersection(s4), check.DeepEquals, NewStringSet("3"))
assert.Equal(NewStringSet("3"), s3.Intersection(s4))

s5 := NewStringSet("4", "5")
c.Assert(s3.Intersection(s5), check.DeepEquals, NewStringSet())
assert.Equal(NewStringSet(), s3.Intersection(s5))

s6 := NewStringSet()
c.Assert(s3.Intersection(s6), check.DeepEquals, NewStringSet())
assert.Equal(NewStringSet(), s3.Intersection(s6))
}

0 comments on commit 2bace00

Please sign in to comment.