Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: migrate test-infra to testify for compare_test.go #28045

Merged
merged 3 commits into from
Sep 15, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 40 additions & 44 deletions types/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@ package types

import (
"math"
"testing"
"time"

. "github.com/pingcap/check"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/util/testleak"
"github.com/stretchr/testify/require"
)

var _ = Suite(&testCompareSuite{})
func TestCompare(t *testing.T) {
t.Parallel()

type testCompareSuite struct {
}

func (s *testCompareSuite) TestCompare(c *C) {
defer testleak.AfterTest(c)()
cmpTbl := []struct {
lhs interface{}
rhs interface{}
Expand Down Expand Up @@ -139,15 +135,14 @@ func (s *testCompareSuite) TestCompare(c *C) {
{NewDecFromInt(0), "hello", 0},
}

for i, t := range cmpTbl {
comment := Commentf("%d %v %v", i, t.lhs, t.rhs)
ret, err := compareForTest(t.lhs, t.rhs)
c.Assert(err, IsNil)
c.Assert(ret, Equals, t.ret, comment)
for i, tt := range cmpTbl {
ret, err := compareForTest(tt.lhs, tt.rhs)
require.NoError(t, err)
require.Equal(t, tt.ret, ret, "%d %v %v", i, tt.lhs, tt.rhs)

ret, err = compareForTest(t.rhs, t.lhs)
c.Assert(err, IsNil)
c.Assert(ret, Equals, -t.ret, comment)
ret, err = compareForTest(tt.rhs, tt.lhs)
require.NoError(t, err)
require.Equal(t, -tt.ret, ret, "%d %v %v", i, tt.lhs, tt.rhs)
}
}

Expand All @@ -159,8 +154,9 @@ func compareForTest(a, b interface{}) (int, error) {
return aDatum.CompareDatum(sc, &bDatum)
}

func (s *testCompareSuite) TestCompareDatum(c *C) {
defer testleak.AfterTest(c)()
func TestCompareDatum(t *testing.T) {
t.Parallel()

cmpTbl := []struct {
lhs Datum
rhs Datum
Expand All @@ -177,20 +173,20 @@ func (s *testCompareSuite) TestCompareDatum(c *C) {
}
sc := new(stmtctx.StatementContext)
sc.IgnoreTruncate = true
for i, t := range cmpTbl {
comment := Commentf("%d %v %v", i, t.lhs, t.rhs)
ret, err := t.lhs.CompareDatum(sc, &t.rhs)
c.Assert(err, IsNil)
c.Assert(ret, Equals, t.ret, comment)
for i, tt := range cmpTbl {
ret, err := tt.lhs.CompareDatum(sc, &tt.rhs)
require.NoError(t, err)
require.Equal(t, tt.ret, ret, "%d %v %v", i, tt.lhs, tt.rhs)

ret, err = t.rhs.CompareDatum(sc, &t.lhs)
c.Assert(err, IsNil)
c.Assert(ret, Equals, -t.ret, comment)
ret, err = tt.rhs.CompareDatum(sc, &tt.lhs)
require.NoError(t, err)
require.Equal(t, -tt.ret, ret, "%d %v %v", i, tt.lhs, tt.rhs)
}
}

func (s *testCompareSuite) TestVecCompareIntAndUint(c *C) {
defer testleak.AfterTest(c)()
func TestVecCompareIntAndUint(t *testing.T) {
t.Parallel()

cmpTblUU := []struct {
lhs []uint64
rhs []uint64
Expand All @@ -200,12 +196,12 @@ func (s *testCompareSuite) TestVecCompareIntAndUint(c *C) {
{[]uint64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, []uint64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, []int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
{[]uint64{math.MaxInt64, math.MaxInt64 + 1, math.MaxInt64 + 2, math.MaxInt64 + 3, math.MaxInt64 + 4, math.MaxInt64 + 5, math.MaxInt64 + 6, math.MaxInt64 + 7, math.MaxInt64 + 8, math.MaxInt64 + 9}, []uint64{math.MaxInt64, math.MaxInt64 + 1, math.MaxInt64 + 2, math.MaxInt64 + 3, math.MaxInt64 + 4, math.MaxInt64 + 5, math.MaxInt64 + 6, math.MaxInt64 + 7, math.MaxInt64 + 8, math.MaxInt64 + 9}, []int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
}
for _, t := range cmpTblUU {
for _, tt := range cmpTblUU {
res := []int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
VecCompareUU(t.lhs, t.rhs, res)
c.Assert(len(res), Equals, len(t.ret))
VecCompareUU(tt.lhs, tt.rhs, res)
require.Len(t, res, len(tt.ret))
for i, v := range res {
c.Assert(v, Equals, t.ret[i])
require.Equal(t, tt.ret[i], v)
}
}

Expand All @@ -220,12 +216,12 @@ func (s *testCompareSuite) TestVecCompareIntAndUint(c *C) {
{[]int64{0, -1, -2, -3, -4, -5, -6, -7, -8, -9}, []int64{-9, -8, -7, -6, -5, -4, -3, -2, -1, 0}, []int64{1, 1, 1, 1, 1, -1, -1, -1, -1, -1}},
{[]int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, []int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
}
for _, t := range cmpTblII {
for _, tt := range cmpTblII {
res := []int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
VecCompareII(t.lhs, t.rhs, res)
c.Assert(len(res), Equals, len(t.ret))
VecCompareII(tt.lhs, tt.rhs, res)
require.Len(t, res, len(tt.ret))
for i, v := range res {
c.Assert(v, Equals, t.ret[i])
require.Equal(t, tt.ret[i], v)
}
}

Expand All @@ -239,12 +235,12 @@ func (s *testCompareSuite) TestVecCompareIntAndUint(c *C) {
{[]int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, []uint64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, []int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
{[]int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, []uint64{math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1}, []int64{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}},
}
for _, t := range cmpTblIU {
for _, tt := range cmpTblIU {
res := []int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
VecCompareIU(t.lhs, t.rhs, res)
c.Assert(len(res), Equals, len(t.ret))
VecCompareIU(tt.lhs, tt.rhs, res)
require.Len(t, res, len(tt.ret))
for i, v := range res {
c.Assert(v, Equals, t.ret[i])
require.Equal(t, tt.ret[i], v)
}
}

Expand All @@ -257,12 +253,12 @@ func (s *testCompareSuite) TestVecCompareIntAndUint(c *C) {
{[]uint64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, []int64{-9, -8, -7, -6, -5, -4, -3, -2, -1, 0}, []int64{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}},
{[]uint64{math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1, math.MaxInt64 + 1}, []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, []int64{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}},
}
for _, t := range cmpTblUI {
for _, tt := range cmpTblUI {
res := []int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
VecCompareUI(t.lhs, t.rhs, res)
c.Assert(len(res), Equals, len(t.ret))
VecCompareUI(tt.lhs, tt.rhs, res)
require.Len(t, res, len(tt.ret))
for i, v := range res {
c.Assert(v, Equals, t.ret[i])
require.Equal(t, tt.ret[i], v)
}
}
}