• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang kmgTest.NewTestTools函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/bronze1man/kmg/kmgTest.NewTestTools函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTestTools函数的具体用法?Golang NewTestTools怎么用?Golang NewTestTools使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewTestTools函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: TestUnmarshalWholeDocumentWithSetter

func TestUnmarshalWholeDocumentWithSetter(ot *testing.T) {
	c := kmgTest.NewTestTools(ot)
	obj := &typeWithSetter{}
	err := Unmarshal([]byte(setterTests[0].data), obj)
	c.Equal(err, nil)
	c.Equal(obj.tag, setterTests[0].tag)
	//c.Assert(err, IsNil)
	//c.Assert(obj.tag, Equals, setterTests[0].tag)

	value, ok := obj.value.(map[interface{}]interface{})
	c.Equal(ok, true)
	c.Equal(value["_"], setterTests[0].value)

	//c.Assert(ok, Equals, true)
	//c.Assert(value["_"], DeepEquals, setterTests[0].value)
}
开发者ID:iizotop,项目名称:kmg,代码行数:16,代码来源:decode_test.go


示例17: TestUnicodeMarshal

func TestUnicodeMarshal(ot *testing.T) {
	t := kmgTest.NewTestTools(ot)
	testCaseTable := []struct {
		in  string
		out string
	}{
		{
			`中文`, "中文\n",
		},
	}
	for _, testCase := range testCaseTable {
		outByte, err := Marshal(testCase.in)
		t.Equal(err, nil)
		t.Equal(string(outByte), testCase.out)
	}
}
开发者ID:iizotop,项目名称:kmg,代码行数:16,代码来源:goyaml_test.go


示例18: TestRsaPublicDecryptPKCS1v15

func TestRsaPublicDecryptPKCS1v15(ot *testing.T) {
	t := kmgTest.NewTestTools(ot)
	priv, err := rsa.GenerateKey(rand.Reader, 256)
	t.Equal(err, nil)
	for _, datas := range []string{
		"\000",
		"\000\000",
		"123456789012345678901",
	} {
		data := []byte(datas)
		enc, err := RsaPrivateEncryptPKCS1v15(priv, data)
		t.Equal(err, nil)
		dout, err := RsaPublicDecryptPKCS1v15(&priv.PublicKey, enc)
		t.Equal(err, nil)
		t.Equal(dout, data)
	}
}
开发者ID:iizotop,项目名称:kmg,代码行数:17,代码来源:rsa_test.go


示例19: TestWriteRead

func TestWriteRead(ot *testing.T) {
	t := kmgTest.NewTestTools(ot)
	buf := &bytes.Buffer{}
	inData := [][]string{
		{"中文"},
		{"1", "", "2"},
	}
	err := Array2XlsxIo(inData, buf)
	t.Equal(err, nil)
	r := bytes.NewReader(buf.Bytes())
	zr, err := zip.NewReader(r, int64(buf.Len()))
	t.Equal(err, nil)
	xlsxFile, err := xlsx.ReadZipReader(zr)
	t.Equal(err, nil)
	outData, err := xlsx2ArrayXlsxFile(xlsxFile)
	t.Equal(err, nil)
	t.Equal(outData[0], inData)
}
开发者ID:keysonZZZ,项目名称:kmg,代码行数:18,代码来源:WriteRead_test.go


示例20: TestUnmarshalWithSetter

func TestUnmarshalWithSetter(ot *testing.T) {
	c := kmgTest.NewTestTools(ot)
	for _, item := range setterTests {
		obj := &typeWithSetterField{}
		err := Unmarshal([]byte(item.data), obj)
		c.Equal(err, nil)
		c.Ok(obj.Field != nil)
		c.Equal(obj.Field.tag, item.tag)
		c.Equal(obj.Field.value, item.value)
		/*
			c.Assert(err, IsNil)
			c.Assert(obj.Field, NotNil,
				Commentf("Pointer not initialized (%#v)", item.value))
			c.Assert(obj.Field.tag, Equals, item.tag)
			c.Assert(obj.Field.value, DeepEquals, item.value)
		*/
	}
}
开发者ID:iizotop,项目名称:kmg,代码行数:18,代码来源:decode_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang error_handler.ErrorExit函数代码示例发布时间:2022-05-24
下一篇:
Golang kmgTest.Equal函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap