improve unit testing cases

This commit is contained in:
John
2020-03-19 22:56:12 +08:00
parent 36401a063d
commit 0b6d04485e
213 changed files with 10757 additions and 10522 deletions

View File

@ -21,47 +21,47 @@ func Test_BeEncodeAndBeDecode(t *testing.T) {
//t.Logf("%s:%v, encoded:%v\n", k, v, ve)
switch v.(type) {
case int:
gtest.Assert(gbinary.BeDecodeToInt(ve), v)
gtest.Assert(gbinary.BeDecodeToInt(ve1), v)
t.Assert(gbinary.BeDecodeToInt(ve), v)
t.Assert(gbinary.BeDecodeToInt(ve1), v)
case int8:
gtest.Assert(gbinary.BeDecodeToInt8(ve), v)
gtest.Assert(gbinary.BeDecodeToInt8(ve1), v)
t.Assert(gbinary.BeDecodeToInt8(ve), v)
t.Assert(gbinary.BeDecodeToInt8(ve1), v)
case int16:
gtest.Assert(gbinary.BeDecodeToInt16(ve), v)
gtest.Assert(gbinary.BeDecodeToInt16(ve1), v)
t.Assert(gbinary.BeDecodeToInt16(ve), v)
t.Assert(gbinary.BeDecodeToInt16(ve1), v)
case int32:
gtest.Assert(gbinary.BeDecodeToInt32(ve), v)
gtest.Assert(gbinary.BeDecodeToInt32(ve1), v)
t.Assert(gbinary.BeDecodeToInt32(ve), v)
t.Assert(gbinary.BeDecodeToInt32(ve1), v)
case int64:
gtest.Assert(gbinary.BeDecodeToInt64(ve), v)
gtest.Assert(gbinary.BeDecodeToInt64(ve1), v)
t.Assert(gbinary.BeDecodeToInt64(ve), v)
t.Assert(gbinary.BeDecodeToInt64(ve1), v)
case uint:
gtest.Assert(gbinary.BeDecodeToUint(ve), v)
gtest.Assert(gbinary.BeDecodeToUint(ve1), v)
t.Assert(gbinary.BeDecodeToUint(ve), v)
t.Assert(gbinary.BeDecodeToUint(ve1), v)
case uint8:
gtest.Assert(gbinary.BeDecodeToUint8(ve), v)
gtest.Assert(gbinary.BeDecodeToUint8(ve1), v)
t.Assert(gbinary.BeDecodeToUint8(ve), v)
t.Assert(gbinary.BeDecodeToUint8(ve1), v)
case uint16:
gtest.Assert(gbinary.BeDecodeToUint16(ve1), v)
gtest.Assert(gbinary.BeDecodeToUint16(ve), v)
t.Assert(gbinary.BeDecodeToUint16(ve1), v)
t.Assert(gbinary.BeDecodeToUint16(ve), v)
case uint32:
gtest.Assert(gbinary.BeDecodeToUint32(ve1), v)
gtest.Assert(gbinary.BeDecodeToUint32(ve), v)
t.Assert(gbinary.BeDecodeToUint32(ve1), v)
t.Assert(gbinary.BeDecodeToUint32(ve), v)
case uint64:
gtest.Assert(gbinary.BeDecodeToUint64(ve), v)
gtest.Assert(gbinary.BeDecodeToUint64(ve1), v)
t.Assert(gbinary.BeDecodeToUint64(ve), v)
t.Assert(gbinary.BeDecodeToUint64(ve1), v)
case bool:
gtest.Assert(gbinary.BeDecodeToBool(ve), v)
gtest.Assert(gbinary.BeDecodeToBool(ve1), v)
t.Assert(gbinary.BeDecodeToBool(ve), v)
t.Assert(gbinary.BeDecodeToBool(ve1), v)
case string:
gtest.Assert(gbinary.BeDecodeToString(ve), v)
gtest.Assert(gbinary.BeDecodeToString(ve1), v)
t.Assert(gbinary.BeDecodeToString(ve), v)
t.Assert(gbinary.BeDecodeToString(ve1), v)
case float32:
gtest.Assert(gbinary.BeDecodeToFloat32(ve), v)
gtest.Assert(gbinary.BeDecodeToFloat32(ve1), v)
t.Assert(gbinary.BeDecodeToFloat32(ve), v)
t.Assert(gbinary.BeDecodeToFloat32(ve1), v)
case float64:
gtest.Assert(gbinary.BeDecodeToFloat64(ve), v)
gtest.Assert(gbinary.BeDecodeToFloat64(ve1), v)
t.Assert(gbinary.BeDecodeToFloat64(ve), v)
t.Assert(gbinary.BeDecodeToFloat64(ve1), v)
default:
if v == nil {
continue
@ -71,7 +71,7 @@ func Test_BeEncodeAndBeDecode(t *testing.T) {
if err != nil {
t.Errorf("test data: %s, %v, error:%v", k, v, err)
}
gtest.Assert(res, v)
t.Assert(res, v)
}
}
}
@ -80,5 +80,5 @@ func Test_BeEncodeStruct(t *testing.T) {
user := User{"wenzi1", 999, "www.baidu.com"}
ve := gbinary.BeEncode(user)
s := gbinary.BeDecodeToString(ve)
gtest.Assert(string(s), s)
t.Assert(string(s), s)
}

View File

@ -21,47 +21,47 @@ func Test_LeEncodeAndLeDecode(t *testing.T) {
//t.Logf("%s:%v, encoded:%v\n", k, v, ve)
switch v.(type) {
case int:
gtest.Assert(gbinary.LeDecodeToInt(ve), v)
gtest.Assert(gbinary.LeDecodeToInt(ve1), v)
t.Assert(gbinary.LeDecodeToInt(ve), v)
t.Assert(gbinary.LeDecodeToInt(ve1), v)
case int8:
gtest.Assert(gbinary.LeDecodeToInt8(ve), v)
gtest.Assert(gbinary.LeDecodeToInt8(ve1), v)
t.Assert(gbinary.LeDecodeToInt8(ve), v)
t.Assert(gbinary.LeDecodeToInt8(ve1), v)
case int16:
gtest.Assert(gbinary.LeDecodeToInt16(ve), v)
gtest.Assert(gbinary.LeDecodeToInt16(ve1), v)
t.Assert(gbinary.LeDecodeToInt16(ve), v)
t.Assert(gbinary.LeDecodeToInt16(ve1), v)
case int32:
gtest.Assert(gbinary.LeDecodeToInt32(ve), v)
gtest.Assert(gbinary.LeDecodeToInt32(ve1), v)
t.Assert(gbinary.LeDecodeToInt32(ve), v)
t.Assert(gbinary.LeDecodeToInt32(ve1), v)
case int64:
gtest.Assert(gbinary.LeDecodeToInt64(ve), v)
gtest.Assert(gbinary.LeDecodeToInt64(ve1), v)
t.Assert(gbinary.LeDecodeToInt64(ve), v)
t.Assert(gbinary.LeDecodeToInt64(ve1), v)
case uint:
gtest.Assert(gbinary.LeDecodeToUint(ve), v)
gtest.Assert(gbinary.LeDecodeToUint(ve1), v)
t.Assert(gbinary.LeDecodeToUint(ve), v)
t.Assert(gbinary.LeDecodeToUint(ve1), v)
case uint8:
gtest.Assert(gbinary.LeDecodeToUint8(ve), v)
gtest.Assert(gbinary.LeDecodeToUint8(ve1), v)
t.Assert(gbinary.LeDecodeToUint8(ve), v)
t.Assert(gbinary.LeDecodeToUint8(ve1), v)
case uint16:
gtest.Assert(gbinary.LeDecodeToUint16(ve1), v)
gtest.Assert(gbinary.LeDecodeToUint16(ve), v)
t.Assert(gbinary.LeDecodeToUint16(ve1), v)
t.Assert(gbinary.LeDecodeToUint16(ve), v)
case uint32:
gtest.Assert(gbinary.LeDecodeToUint32(ve1), v)
gtest.Assert(gbinary.LeDecodeToUint32(ve), v)
t.Assert(gbinary.LeDecodeToUint32(ve1), v)
t.Assert(gbinary.LeDecodeToUint32(ve), v)
case uint64:
gtest.Assert(gbinary.LeDecodeToUint64(ve), v)
gtest.Assert(gbinary.LeDecodeToUint64(ve1), v)
t.Assert(gbinary.LeDecodeToUint64(ve), v)
t.Assert(gbinary.LeDecodeToUint64(ve1), v)
case bool:
gtest.Assert(gbinary.LeDecodeToBool(ve), v)
gtest.Assert(gbinary.LeDecodeToBool(ve1), v)
t.Assert(gbinary.LeDecodeToBool(ve), v)
t.Assert(gbinary.LeDecodeToBool(ve1), v)
case string:
gtest.Assert(gbinary.LeDecodeToString(ve), v)
gtest.Assert(gbinary.LeDecodeToString(ve1), v)
t.Assert(gbinary.LeDecodeToString(ve), v)
t.Assert(gbinary.LeDecodeToString(ve1), v)
case float32:
gtest.Assert(gbinary.LeDecodeToFloat32(ve), v)
gtest.Assert(gbinary.LeDecodeToFloat32(ve1), v)
t.Assert(gbinary.LeDecodeToFloat32(ve), v)
t.Assert(gbinary.LeDecodeToFloat32(ve1), v)
case float64:
gtest.Assert(gbinary.LeDecodeToFloat64(ve), v)
gtest.Assert(gbinary.LeDecodeToFloat64(ve1), v)
t.Assert(gbinary.LeDecodeToFloat64(ve), v)
t.Assert(gbinary.LeDecodeToFloat64(ve1), v)
default:
if v == nil {
continue
@ -71,7 +71,7 @@ func Test_LeEncodeAndLeDecode(t *testing.T) {
if err != nil {
t.Errorf("test data: %s, %v, error:%v", k, v, err)
}
gtest.Assert(res, v)
t.Assert(res, v)
}
}
}
@ -80,5 +80,5 @@ func Test_LeEncodeStruct(t *testing.T) {
user := User{"wenzi1", 999, "www.baidu.com"}
ve := gbinary.LeEncode(user)
s := gbinary.LeDecodeToString(ve)
gtest.Assert(string(s), s)
t.Assert(string(s), s)
}

View File

@ -56,47 +56,47 @@ func Test_EncodeAndDecode(t *testing.T) {
//t.Logf("%s:%v, encoded:%v\n", k, v, ve)
switch v.(type) {
case int:
gtest.Assert(gbinary.DecodeToInt(ve), v)
gtest.Assert(gbinary.DecodeToInt(ve1), v)
t.Assert(gbinary.DecodeToInt(ve), v)
t.Assert(gbinary.DecodeToInt(ve1), v)
case int8:
gtest.Assert(gbinary.DecodeToInt8(ve), v)
gtest.Assert(gbinary.DecodeToInt8(ve1), v)
t.Assert(gbinary.DecodeToInt8(ve), v)
t.Assert(gbinary.DecodeToInt8(ve1), v)
case int16:
gtest.Assert(gbinary.DecodeToInt16(ve), v)
gtest.Assert(gbinary.DecodeToInt16(ve1), v)
t.Assert(gbinary.DecodeToInt16(ve), v)
t.Assert(gbinary.DecodeToInt16(ve1), v)
case int32:
gtest.Assert(gbinary.DecodeToInt32(ve), v)
gtest.Assert(gbinary.DecodeToInt32(ve1), v)
t.Assert(gbinary.DecodeToInt32(ve), v)
t.Assert(gbinary.DecodeToInt32(ve1), v)
case int64:
gtest.Assert(gbinary.DecodeToInt64(ve), v)
gtest.Assert(gbinary.DecodeToInt64(ve1), v)
t.Assert(gbinary.DecodeToInt64(ve), v)
t.Assert(gbinary.DecodeToInt64(ve1), v)
case uint:
gtest.Assert(gbinary.DecodeToUint(ve), v)
gtest.Assert(gbinary.DecodeToUint(ve1), v)
t.Assert(gbinary.DecodeToUint(ve), v)
t.Assert(gbinary.DecodeToUint(ve1), v)
case uint8:
gtest.Assert(gbinary.DecodeToUint8(ve), v)
gtest.Assert(gbinary.DecodeToUint8(ve1), v)
t.Assert(gbinary.DecodeToUint8(ve), v)
t.Assert(gbinary.DecodeToUint8(ve1), v)
case uint16:
gtest.Assert(gbinary.DecodeToUint16(ve1), v)
gtest.Assert(gbinary.DecodeToUint16(ve), v)
t.Assert(gbinary.DecodeToUint16(ve1), v)
t.Assert(gbinary.DecodeToUint16(ve), v)
case uint32:
gtest.Assert(gbinary.DecodeToUint32(ve1), v)
gtest.Assert(gbinary.DecodeToUint32(ve), v)
t.Assert(gbinary.DecodeToUint32(ve1), v)
t.Assert(gbinary.DecodeToUint32(ve), v)
case uint64:
gtest.Assert(gbinary.DecodeToUint64(ve), v)
gtest.Assert(gbinary.DecodeToUint64(ve1), v)
t.Assert(gbinary.DecodeToUint64(ve), v)
t.Assert(gbinary.DecodeToUint64(ve1), v)
case bool:
gtest.Assert(gbinary.DecodeToBool(ve), v)
gtest.Assert(gbinary.DecodeToBool(ve1), v)
t.Assert(gbinary.DecodeToBool(ve), v)
t.Assert(gbinary.DecodeToBool(ve1), v)
case string:
gtest.Assert(gbinary.DecodeToString(ve), v)
gtest.Assert(gbinary.DecodeToString(ve1), v)
t.Assert(gbinary.DecodeToString(ve), v)
t.Assert(gbinary.DecodeToString(ve1), v)
case float32:
gtest.Assert(gbinary.DecodeToFloat32(ve), v)
gtest.Assert(gbinary.DecodeToFloat32(ve1), v)
t.Assert(gbinary.DecodeToFloat32(ve), v)
t.Assert(gbinary.DecodeToFloat32(ve1), v)
case float64:
gtest.Assert(gbinary.DecodeToFloat64(ve), v)
gtest.Assert(gbinary.DecodeToFloat64(ve1), v)
t.Assert(gbinary.DecodeToFloat64(ve), v)
t.Assert(gbinary.DecodeToFloat64(ve1), v)
default:
if v == nil {
continue
@ -106,7 +106,7 @@ func Test_EncodeAndDecode(t *testing.T) {
if err != nil {
t.Errorf("test data: %s, %v, error:%v", k, v, err)
}
gtest.Assert(res, v)
t.Assert(res, v)
}
}
}
@ -115,7 +115,7 @@ func Test_EncodeStruct(t *testing.T) {
user := User{"wenzi1", 999, "www.baidu.com"}
ve := gbinary.Encode(user)
s := gbinary.DecodeToString(ve)
gtest.Assert(string(s), s)
t.Assert(string(s), s)
}
func Test_Bits(t *testing.T) {
@ -123,10 +123,10 @@ func Test_Bits(t *testing.T) {
bits := make([]gbinary.Bit, 0)
res := gbinary.EncodeBits(bits, testBitData[i], 64)
gtest.Assert(gbinary.DecodeBits(res), testBitData[i])
gtest.Assert(gbinary.DecodeBitsToUint(res), uint(testBitData[i]))
t.Assert(gbinary.DecodeBits(res), testBitData[i])
t.Assert(gbinary.DecodeBitsToUint(res), uint(testBitData[i]))
gtest.Assert(gbinary.DecodeBytesToBits(gbinary.EncodeBitsToBytes(res)), res)
t.Assert(gbinary.DecodeBytesToBits(gbinary.EncodeBitsToBytes(res)), res)
}
}