gutil test 20190623 16:42

This commit is contained in:
陈国潮 2019-06-23 16:45:30 +08:00
parent a5ab2ba332
commit abe14e049a
2 changed files with 72 additions and 45 deletions

View File

@ -8,81 +8,114 @@ import (
) )
func Test_ComparatorString(t *testing.T) { func Test_ComparatorString(t *testing.T) {
j := gutil.ComparatorString(1, 1)
gtest.Assert(j, 0) gtest.Assert(gutil.ComparatorString(1, 1), 0)
gtest.Assert(gutil.ComparatorString(1, 2), -1)
gtest.Assert(gutil.ComparatorString(2, 1), 1)
} }
func Test_ComparatorInt(t *testing.T) { func Test_ComparatorInt(t *testing.T) {
j := gutil.ComparatorInt(1, 1)
gtest.Assert(j, 0) gtest.Assert(gutil.ComparatorInt(1, 1), 0)
gtest.Assert(gutil.ComparatorInt(1, 2), -1)
gtest.Assert(gutil.ComparatorInt(2, 1), 1)
} }
func Test_ComparatorInt8(t *testing.T) { func Test_ComparatorInt8(t *testing.T) {
j := gutil.ComparatorInt8(1, 1)
gtest.Assert(j, 0) gtest.Assert(gutil.ComparatorInt8(1, 1), 0)
gtest.Assert(gutil.ComparatorInt8(1, 2), -1)
gtest.Assert(gutil.ComparatorInt8(2, 1), 1)
} }
func Test_ComparatorInt16(t *testing.T) { func Test_ComparatorInt16(t *testing.T) {
j := gutil.ComparatorInt16(1, 1)
gtest.Assert(j, 0) gtest.Assert(gutil.ComparatorInt16(1, 1), 0)
gtest.Assert(gutil.ComparatorInt16(1, 2), -1)
gtest.Assert(gutil.ComparatorInt16(2, 1), 1)
} }
func Test_ComparatorInt32(t *testing.T) { func Test_ComparatorInt32(t *testing.T) {
j := gutil.ComparatorInt32(1, 1)
gtest.Assert(j, 0) gtest.Assert(gutil.ComparatorInt32(1, 1), 0)
gtest.Assert(gutil.ComparatorInt32(1, 2), -1)
gtest.Assert(gutil.ComparatorInt32(2, 1), 1)
} }
func Test_ComparatorInt64(t *testing.T) { func Test_ComparatorInt64(t *testing.T) {
j := gutil.ComparatorInt64(1, 1)
gtest.Assert(j, 0) gtest.Assert(gutil.ComparatorInt64(1, 1), 0)
gtest.Assert(gutil.ComparatorInt64(1, 2), -1)
gtest.Assert(gutil.ComparatorInt64(2, 1), 1)
} }
func Test_ComparatorUint(t *testing.T) { func Test_ComparatorUint(t *testing.T) {
j := gutil.ComparatorUint(1, 1) j := gutil.ComparatorUint(1, 1)
gtest.Assert(j, 0) gtest.Assert(j, 0)
gtest.Assert(gutil.ComparatorUint(1, 1), 0)
gtest.Assert(gutil.ComparatorUint(1, 2), -1)
gtest.Assert(gutil.ComparatorUint(2, 1), 1)
} }
func Test_ComparatorUint8(t *testing.T) { func Test_ComparatorUint8(t *testing.T) {
j := gutil.ComparatorUint8(1, 1)
gtest.Assert(j, 0) gtest.Assert(gutil.ComparatorUint8(1, 1), 0)
gtest.Assert(gutil.ComparatorUint8(1, 2), 255)
gtest.Assert(gutil.ComparatorUint8(2, 1), 1)
} }
func Test_ComparatorUint16(t *testing.T) { func Test_ComparatorUint16(t *testing.T) {
j := gutil.ComparatorUint16(1, 1)
gtest.Assert(j, 0) gtest.Assert(gutil.ComparatorUint16(1, 1), 0)
gtest.Assert(gutil.ComparatorUint16(1, 2), 65535)
gtest.Assert(gutil.ComparatorUint16(2, 1), 1)
} }
func Test_ComparatorUint32(t *testing.T) { func Test_ComparatorUint32(t *testing.T) {
j := gutil.ComparatorUint32(1, 1)
gtest.Assert(j, 0) gtest.Assert(gutil.ComparatorUint32(1, 1), 0)
gtest.Assert(gutil.ComparatorUint32(1, 2), 4294967295)
gtest.Assert(gutil.ComparatorUint32(2, 1), 1)
} }
func Test_ComparatorUint64(t *testing.T) { func Test_ComparatorUint64(t *testing.T) {
j := gutil.ComparatorUint64(1, 1)
gtest.Assert(j, 0) gtest.Assert(gutil.ComparatorUint64(1, 1), 0)
gtest.Assert(gutil.ComparatorUint64(1, 2), -1)
gtest.Assert(gutil.ComparatorUint64(2, 1), 1)
} }
func Test_ComparatorFloat32(t *testing.T) { func Test_ComparatorFloat32(t *testing.T) {
j := gutil.ComparatorFloat32(1, 1)
gtest.Assert(j, 0) gtest.Assert(gutil.ComparatorFloat32(1, 1), 0)
gtest.Assert(gutil.ComparatorFloat32(1, 2), -1)
gtest.Assert(gutil.ComparatorFloat32(2, 1), 1)
} }
func Test_ComparatorFloat64(t *testing.T) { func Test_ComparatorFloat64(t *testing.T) {
j := gutil.ComparatorFloat64(1, 1)
gtest.Assert(j, 0) gtest.Assert(gutil.ComparatorFloat64(1, 1), 0)
gtest.Assert(gutil.ComparatorFloat64(1, 2), -1)
gtest.Assert(gutil.ComparatorFloat64(2, 1), 1)
} }
func Test_ComparatorByte(t *testing.T) { func Test_ComparatorByte(t *testing.T) {
j := gutil.ComparatorByte(1, 1)
gtest.Assert(j, 0) gtest.Assert(gutil.ComparatorByte(1, 1), 0)
gtest.Assert(gutil.ComparatorByte(1, 2), 255)
gtest.Assert(gutil.ComparatorByte(2, 1), 1)
} }
func Test_ComparatorRune(t *testing.T) { func Test_ComparatorRune(t *testing.T) {
j := gutil.ComparatorRune(1, 1)
gtest.Assert(j, 0) gtest.Assert(gutil.ComparatorRune(1, 1), 0)
gtest.Assert(gutil.ComparatorRune(1, 2), -1)
gtest.Assert(gutil.ComparatorRune(2, 1), 1)
} }
func Test_ComparatorTime(t *testing.T) { func Test_ComparatorTime(t *testing.T) {
j := gutil.ComparatorTime("2019-06-14", "2019-06-14") j := gutil.ComparatorTime("2019-06-14", "2019-06-14")
gtest.Assert(j, 0) gtest.Assert(j, 0)
k := gutil.ComparatorTime("2019-06-15", "2019-06-14") k := gutil.ComparatorTime("2019-06-15", "2019-06-14")

View File

@ -12,43 +12,39 @@ func Test_Dump(t *testing.T) {
gutil.Dump(map[int]int{ gutil.Dump(map[int]int{
100: 100, 100: 100,
}) })
gtest.Assert("", "")
}) })
gtest.Case(t, func() { gtest.Case(t, func() {
gutil.Dump(map[string]interface{}{"": func() {}}) gutil.Dump(map[string]interface{}{"": func() {}})
gtest.Assert("", "")
}) })
gtest.Case(t, func() { gtest.Case(t, func() {
gutil.Dump([]byte("gutil Dump test")) gutil.Dump([]byte("gutil Dump test"))
gtest.Assert("", "")
}) })
} }
func Test_PrintBacktrace(t *testing.T) { func Test_PrintBacktrace(t *testing.T) {
gtest.Case(t, func() { gtest.Case(t, func() {
gutil.PrintBacktrace() gutil.PrintBacktrace()
gtest.Assert("", "")
}) })
} }
func Test_TryCatch(t *testing.T) { func Test_TryCatch(t *testing.T) {
gutil.TryCatch(func() { gtest.Case(t, func() {
}, func(err interface{}) { gutil.TryCatch(func() {
panic("gutil TryCatch test")
})
}) })
gtest.Assert("", "")
gutil.TryCatch(func() { gtest.Case(t, func() {
}) gutil.TryCatch(func() {
gtest.Assert("", "") panic("gutil TryCatch test")
gutil.TryCatch(func() { }, func(err interface{}) {
panic("gutil TryCatch test") gtest.Assert(err, "gutil TryCatch test")
}, func(err interface{}) { })
}) })
gtest.Assert("", "")
} }
func Test_IsEmpty(t *testing.T) { func Test_IsEmpty(t *testing.T) {
@ -58,9 +54,7 @@ func Test_IsEmpty(t *testing.T) {
func Test_Throw(t *testing.T) { func Test_Throw(t *testing.T) {
gtest.Case(t, func() { gtest.Case(t, func() {
defer func() { defer func() {
if e := recover(); e != nil { gtest.Assert(recover(), "gutil Throw test")
gtest.Assert(e, "gutil Throw test")
}
}() }()
gutil.Throw("gutil Throw test") gutil.Throw("gutil Throw test")