当前位置: 首页>>代码示例>>Golang>>正文


Golang kmgTest.NewTestTools函数代码示例

本文整理汇总了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)
	}
}
开发者ID:iizotop,项目名称:kmg,代码行数:32,代码来源:Trim2DArray_test.go

示例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)
	}
}
开发者ID:iizotop,项目名称:kmg,代码行数:30,代码来源:FloatCompare_test.go

示例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())

}
开发者ID:iizotop,项目名称:kmg,代码行数:7,代码来源:url_test.go

示例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)
	*/
}
开发者ID:iizotop,项目名称:kmg,代码行数:30,代码来源:decode_test.go

示例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})
}
开发者ID:iizotop,项目名称:kmg,代码行数:29,代码来源:Period3_test.go

示例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)
	}
}
开发者ID:iizotop,项目名称:kmg,代码行数:31,代码来源:Period_test.go

示例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)
	}
}
开发者ID:iizotop,项目名称:kmg,代码行数:8,代码来源:decode_test.go

示例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)
}
开发者ID:iizotop,项目名称:kmg,代码行数:8,代码来源:tls_test.go

示例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)
}
开发者ID:iizotop,项目名称:kmg,代码行数:9,代码来源:decode_test.go

示例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")
}
开发者ID:iizotop,项目名称:kmg,代码行数:12,代码来源:type_test.go

示例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)
	}
}
开发者ID:iizotop,项目名称:kmg,代码行数:52,代码来源:kmgCipher_test.go

示例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"))
}
开发者ID:iizotop,项目名称:kmg,代码行数:13,代码来源:StringTransformSubType_test.go

示例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")
}
开发者ID:iizotop,项目名称:kmg,代码行数:13,代码来源:type_test.go

示例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)
}
开发者ID:iizotop,项目名称:kmg,代码行数:14,代码来源:StructGetAllField_test.go

示例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, "")

}
开发者ID:iizotop,项目名称:kmg,代码行数:15,代码来源:kmgReflect_test.go


注:本文中的github.com/bronze1man/kmg/kmgTest.NewTestTools函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。