本文整理汇总了Golang中github.com/bronze1man/kmg/kmgTest.NewTestTools函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTestTools函数的具体用法?Golang NewTestTools怎么用?Golang NewTestTools使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTestTools函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestManager
func TestManager(ot *testing.T) {
t := kmgTest.NewTestTools(ot)
testCaseTable := []struct {
in [][]string
out [][]string
}{
{
[][]string{{}}, [][]string{},
},
{
[][]string{{" ", " "}, {""}}, [][]string{},
},
{
[][]string{
{"1", "2", " "},
{"1", " ", " "},
{" ", " ", " "},
{"1"},
{" ", " "},
},
[][]string{
{"1", "2"},
{"1", " "},
{"1", ""},
},
},
}
for _, testCase := range testCaseTable {
ret := Trim2DArray(testCase.in)
t.Equal(ret, testCase.out)
}
}
示例2: TestFloatCompare
func TestFloatCompare(ot *testing.T) {
t := kmgTest.NewTestTools(ot)
for i, testCase := range []struct {
f func(x float64, y float64) bool
x float64
y float64
result bool
}{
{Float64LessThan, 1.0, 2.0, true},
{Float64LessThan, 2.0, 1.0, false},
{Float64LessThan, 2.0, 2.0, false},
{Float64LessEqualThan, 1.0, 2.0, true},
{Float64LessEqualThan, 1.0, 1.0, true},
{Float64LessEqualThan, 2.0, 1.0, false}, //5
{Float64GreaterThan, 1.0, 2.0, false},
{Float64GreaterThan, 2.0, 1.0, true},
{Float64GreaterThan, 1.0, 1.0, false},
{Float64Equal, 1.0, 1.0, true},
{Float64Equal, 1.0, 2.0, false}, //10
{Float64Equal, 1.0 / 3.0 * 3.0, 1.0, true},
{Float64GreaterEqualThan, 1.0, 2.0, false},
{Float64GreaterEqualThan, 2.0, 1.0, true},
{Float64GreaterEqualThan, 1.0, 1.0, true},
} {
t.EqualMsg(testCase.f(testCase.x, testCase.y), testCase.result,
"fail at %d", i)
}
}
示例3: TestNewUrlByString
func TestNewUrlByString(ot *testing.T) {
t := kmgTest.NewTestTools(ot)
url, err := NewUrlByString("http://www.google.com")
t.Equal(nil, err)
t.Equal("http://www.google.com", url.String())
}
示例4: TestUnmarshalWithFalseSetterIgnoresValue
func TestUnmarshalWithFalseSetterIgnoresValue(ot *testing.T) {
c := kmgTest.NewTestTools(ot)
setterResult[2] = false
setterResult[4] = false
defer func() {
delete(setterResult, 2)
delete(setterResult, 4)
}()
m := map[string]*typeWithSetter{}
data := "{abc: 1, def: 2, ghi: 3, jkl: 4}"
err := Unmarshal([]byte(data), m)
c.Equal(err, nil)
c.Ok(m["abc"] != nil)
c.Equal(m["def"], nil)
c.Ok(m["ghi"] != nil)
c.Equal(m["jkl"], nil)
c.Equal(m["abc"].value, 1)
c.Equal(m["ghi"].value, 3)
/*
c.Assert(err, IsNil)
c.Assert(m["abc"], NotNil)
c.Assert(m["def"], IsNil)
c.Assert(m["ghi"], NotNil)
c.Assert(m["jkl"], IsNil)
c.Assert(m["abc"].value, Equals, 1)
c.Assert(m["ghi"].value, Equals, 3)
*/
}
示例5: TestPeriodList
func TestPeriodList(ot *testing.T) {
t := kmgTest.NewTestTools(ot)
itemList := ScratchItemList3{
[]int{1, 2},
[]int{2, 3},
[]int{3, 4},
}
periodList := PeriodList{
{
Period: Period{Start: MustFromMysqlFormat("2001-01-00 23:30:00"), End: MustFromMysqlFormat("2001-01-01 23:30:00")},
OriginIndex: 0,
},
{
Period: Period{Start: MustFromMysqlFormat("2001-01-03 23:30:00"), End: MustFromMysqlFormat("2001-01-04 23:30:00")},
OriginIndex: 1,
},
{
Period: Period{Start: MustFromMysqlFormat("2001-01-02 23:30:00"), End: MustFromMysqlFormat("2001-01-03 23:30:00")},
OriginIndex: 2,
},
}
periodList.Sort()
i, exist := periodList.SelectFromTime(MustFromMysqlFormat("2001-01-01 23:00:00"))
t.Equal(exist, true)
t.Equal(itemList[i], []int{1, 2})
i, exist = periodList.SelectFromTime(MustFromMysqlFormat("2001-01-03 23:00:00"))
t.Equal(exist, true)
t.Equal(itemList[i], []int{3, 4})
}
示例6: TestGetPeriodFromSortedList
func TestGetPeriodFromSortedList(ot *testing.T) {
t := kmgTest.NewTestTools(ot)
SortedList := []Period{
{
Start: MustFromMysqlFormat("2001-01-01 00:00:00"),
End: MustFromMysqlFormat("2001-01-01 01:00:00"),
},
{
Start: MustFromMysqlFormat("2001-01-01 02:00:00"),
End: MustFromMysqlFormat("2001-01-01 03:00:00"),
},
{
Start: MustFromMysqlFormat("2001-01-01 03:00:00"),
End: MustFromMysqlFormat("2001-01-01 04:00:00"),
},
}
for _, testcase := range []struct {
t time.Time
i int
ok bool
}{
{MustFromMysqlFormat("2001-01-00 23:30:00"), 0, false},
{MustFromMysqlFormat("2001-01-01 00:30:00"), 0, true},
{MustFromMysqlFormat("2001-01-01 03:00:00"), 2, true},
{MustFromMysqlFormat("2001-01-01 04:30:00"), 0, false},
} {
i, ok := GetPeriodFromSortedList(testcase.t, SortedList)
t.Equal(i, testcase.i)
t.Equal(ok, testcase.ok)
}
}
示例7: TestUnmarshalErrors
func TestUnmarshalErrors(ot *testing.T) {
c := kmgTest.NewTestTools(ot)
for _, item := range unmarshalErrorTests {
var value interface{}
err := Unmarshal([]byte(item.data), &value)
c.Equal(err.Error(), item.error)
}
}
示例8: TestCreateCert
func TestCreateCert(ot *testing.T) {
t := kmgTest.NewTestTools(ot)
config, err := CreateTlsConfig()
t.Equal(err, nil)
t.Ok(config != nil)
_ = tls.NewListener(&mockListener{}, config)
}
示例9: TestUnmarshalNaN
func TestUnmarshalNaN(ot *testing.T) {
c := kmgTest.NewTestTools(ot)
value := map[string]interface{}{}
err := Unmarshal([]byte("notanum: .NaN"), &value)
c.Equal(err, nil)
c.Equal(math.IsNaN(value["notanum"].(float64)), true)
//c.Assert(err, IsNil)
//c.Assert(math.IsNaN(value["notanum"].(float64)), Equals, true)
}
示例10: TestStringType
func TestStringType(ot *testing.T) {
t := kmgTest.NewTestTools(ot)
var data *string
data = new(string)
m, err := NewContext(data)
t.Equal(err, nil)
err = m.SaveByPath(Path{"ptr"}, "123")
t.Equal(err, nil)
t.Ok(data != nil)
t.Equal(*data, "123")
}
示例11: Test1
func Test1(ot *testing.T) {
t := kmgTest.NewTestTools(ot)
//加密数据,可以正确解密测试
for _, origin := range [][]byte{
[]byte(""),
[]byte("1"),
[]byte("12"),
[]byte("123"),
[]byte("1234"),
[]byte("12345"),
[]byte("123456"),
[]byte("1234567"),
[]byte("12345678"),
[]byte("123456789"),
[]byte("1234567890"),
[]byte("123456789012345"),
[]byte("1234567890123456"),
[]byte("12345678901234567"),
} {
ob, err := Encrypt([]byte("1"), origin)
t.Equal(err, nil)
ret, err := Decrypt([]byte("1"), ob)
t.Equal(err, nil)
t.Equal(ret, origin)
sob, err := EncryptString("1", origin)
t.Equal(err, nil)
sret, err := DecryptString("1", sob)
t.Equal(err, nil)
t.Equal(sret, origin)
}
//任意数据传入解密不会挂掉,并且会报错
for _, origin := range [][]byte{
[]byte(""),
[]byte("1"),
[]byte("12"),
[]byte("123"),
[]byte("1234"),
[]byte("12345"),
[]byte("123456"),
[]byte("1234567"),
[]byte("12345678"),
[]byte("123456789"),
[]byte("1234567890"),
[]byte("123456789012345"),
[]byte("1234567890123456"),
[]byte("12345678901234567"),
} {
_, err := Decrypt([]byte("1"), origin)
t.Ok(err != nil)
}
}
示例12: TestStringTransformSubType
func TestStringTransformSubType(ot *testing.T) {
t := kmgTest.NewTestTools(ot)
in := &StringTranT1{
T2: "6",
}
err := StringTransformSubType(in, map[string]map[string]string{
"github.com/bronze1man/kmg/typeTransform.StringTranT2": {
"6": "Fire",
},
})
t.Equal(err, nil)
t.Equal(in.T2, StringTranT2("Fire"))
}
示例13: TestStructType
func TestStructType(ot *testing.T) {
t := kmgTest.NewTestTools(ot)
data := &struct {
A string
}{}
m, err := NewContext(data)
t.Equal(err, nil)
err = m.SaveByPath(Path{"ptr", "A"}, "123")
t.Equal(err, nil)
t.Ok(data != nil)
t.Equal(data.A, "123")
}
示例14: TestStructGetAllFieldMap
func TestStructGetAllFieldMap(ot *testing.T) {
t := kmgTest.NewTestTools(ot)
t1 := reflect.TypeOf(&GetAllFieldT1{})
ret := StructGetAllFieldMap(t1)
t.Equal(ret["A"].Index, []int{0, 0})
t.Equal(ret["B"].Index, []int{2})
t.Equal(ret["C"].Index, []int{0, 2, 2})
t.Equal(ret["D"].Index, []int{1, 1})
t.Equal(len(ret), 7)
ret = StructGetAllFieldMap(reflect.TypeOf(&GetAllFieldT5{}))
t.Equal(ret["A"].Index, []int{1})
t.Equal(len(ret), 2)
}
示例15: TestGetFullName
func TestGetFullName(ot *testing.T) {
t := kmgTest.NewTestTools(ot)
name := GetTypeFullName(reflect.TypeOf(""))
t.Equal(name, "string")
name = GetTypeFullName(reflect.TypeOf(1))
t.Equal(name, "int")
name = GetTypeFullName(reflect.TypeOf(&ta{}))
t.Equal(name, "github.com/bronze1man/kmg/kmgReflect.ta")
name = GetTypeFullName(reflect.TypeOf([]string{}))
t.Equal(name, "")
}