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

Golang assert.Assert函数代码示例

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

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



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

示例1: TestHostnamesInheritFromDefault

func TestHostnamesInheritFromDefault(t *testing.T) {
	assert := assert.Assert(t)

	yml := loadFile("config_hostnames_inherit_from_default.yml")
	setting, err := kasi.ParseConfig(yml)
	assert.Equal(err, nil)

	assert.Equal(len(setting.Services), 1)
	assert.Equal(len(setting.Services[0].Hostnames), 2)

	for _, h := range []string{"my0.github.com", "my1.github.com"} {
		if sort.SearchStrings(setting.Services[0].Hostnames, h) == 2 {
			t.Error("failed to parse hostnames")
		}
	}

	ymlOverride := loadFile("config_hostnames_override_default.yml")
	setting, err = kasi.ParseConfig(ymlOverride)
	assert.Nil(err)

	assert.Equal(len(setting.Services), 1)
	assert.Equal(len(setting.Services[0].Hostnames), 1)

	for _, h := range []string{"my2.github.com"} {
		if sort.SearchStrings(setting.Services[0].Hostnames, h) == 2 {
			t.Error("failed to parse hostnames")
		}
	}
}
开发者ID:haiheipijuan,项目名称:kasi,代码行数:29,代码来源:conf_hostnames_test.go


示例2: TestEndpointsOpen

func TestEndpointsOpen(t *testing.T) {
	assert := assert.Assert(t)

	var yml string
	var setting *kasi_conf.CoreSetting
	var err error

	yml = loadFile("config_simple_endpoint0.yml")
	setting, err = kasi.ParseConfig(yml)
	assert.Nil(err)
	assert.Equal(len(setting.Services[0].Endpoints), 1)

	yml = loadFile("config_opened_endpoint.yml")
	setting, err = kasi.ParseConfig(yml)
	assert.Nil(err)
	assert.Equal(len(setting.Services[0].Endpoints), 1)

	yml = loadFile("config_closed_endpoint.yml")

	setting, err = kasi.ParseConfig(yml)
	assert.Nil(err)

	assert.False(setting.Services[0].Opened(), "")
	assert.Equal(len(setting.Services[0].Endpoints), 0)
}
开发者ID:haiheipijuan,项目名称:kasi,代码行数:25,代码来源:conf_endpoint_test.go


示例3: TestMiddleware

func TestMiddleware(t *testing.T) {
	assert := assert.Assert(t)

	yml := loadFile("conf_middlewares.yml")
	setting, err := kasi.ParseConfig(yml)
	assert.Equal(err, nil)

	assert.Equal(len(setting.Middlewares), 2)
	service0, _ := setting.GetServiceByID("service0")
	assert.Equal(service0.Middleware, "base")
	service1, _ := setting.GetServiceByID("service1")
	assert.Equal(service1.Middleware, "extend")

	assert.Equal(len(service0.Endpoints[0].Middleware), 2)
	assert.Equal(service0.Endpoints[0].Middleware[0], "a.js")
	assert.Equal(service0.Endpoints[0].Middleware[1], "b.js")

	assert.Equal(len(service0.Endpoints[0].Middleware), 2)
	assert.Nil(service0.Endpoints[1].Middleware)

	assert.Equal(len(service1.Endpoints[0].Middleware), 2)
	assert.Equal(service1.Endpoints[0].Middleware[0], "a.js")
	assert.Equal(service1.Endpoints[0].Middleware[1], "b.js")

	assert.Equal(len(service1.Endpoints[1].Middleware), 2)
	assert.Equal(service1.Endpoints[1].Middleware[0], "c.js")
	assert.Equal(service1.Endpoints[1].Middleware[1], "d.js")
}
开发者ID:haiheipijuan,项目名称:kasi,代码行数:28,代码来源:conf_middlewares_test.go


示例4: TestServices

func TestServices(t *testing.T) {
	assert := assert.Assert(t)
	services := new(Services)
	assert.Equal(len(services.Services), 0)

	// Addition
	services.Add(Service{Name: "google.com", Password: "asdf1234", Meta: "Personal"})
	assert.Equal(len(services.Services), 1)
	assert.Equal(services.Services[0].Name, "google.com")

	// replacement
	services.Add(Service{Name: "google.com", Password: "lkjpoiu"})
	assert.Equal(len(services.Services), 1)
	assert.Equal(services.Services[0].Password, "lkjpoiu")

	// Addition
	services.Add(Service{Name: "facebook.com", Password: "1234"})
	assert.Equal(len(services.Services), 2)

	// another replacement
	services.Add(Service{Name: "google.com", Password: "asghasd"})
	assert.Equal(services.Get("google.com").Password, "asghasd")
	assert.Equal(len(services.Services), 2)

	services.Add(Service{Name: "golang.org"})
	goServices := services.Search("go")
	assert.Equal(len(goServices), 2)
	assert.True(goServices[0].Name[:2] == "go", "Service 0 begins with go")
	assert.True(goServices[1].Name[:2] == "go", "Service 1 begins with go")
	assert.Equal(len(services.Search("*")), 3)
}
开发者ID:seanpont,项目名称:passman,代码行数:31,代码来源:passman_test.go


示例5: TestJoinURL

func TestJoinURL(t *testing.T) {
	assert := assert.Assert(t)

	var base, target string

	// 2 FQDN url
	base = "http://a0.com/b0/c0.html"
	target = "http://a1.com/b1/c1.html"
	assert.Equal(joinURL(base, target), target)

	// 1 FQDN and 1 path
	base = "http://a0.com/b0/c0.html"
	target = "/b1/c1.html"
	assert.Equal(joinURL(base, target), "http://a0.com"+target)

	// 1 invalid url and 1 valid url
	base = "****************\\*"
	target = "/b1/c1.html"
	assert.Equal(joinURL(base, target), target)

	// 2 path, but one is relative
	base = "/b0/c0.html"
	target = "b1/c1.html"
	assert.Equal(joinURL(base, target), base+"/"+target)

	// merge querystring
	base = "/b0/c0.html?a=1&b=2"
	target = "b1/c1.html?a=3"
	assert.Equal(joinURL(base, target), "/b0/c0.html/b1/c1.html?a=3&b=2")
}
开发者ID:haiheipijuan,项目名称:kasi,代码行数:30,代码来源:util_test.go


示例6: TestParseTimeUnit

func TestParseTimeUnit(t *testing.T) {
	assert := assert.Assert(t)

	cases := []struct {
		in   string
		want time.Duration
	}{
		{"10", time.Nanosecond * 10},
		{"100000", time.Nanosecond * 100 * 1000},
		{"1s", time.Second * 1},
		{"2s", time.Second * 2},
		{"3m", time.Minute * 3},
		{"4h", time.Hour * 4},
		{"5d", time.Hour * 24 * 5},
		{"6M", time.Hour * 24 * 30 * 6},
		{"7y", time.Hour * 24 * 365 * 7},
	}
	for _, c := range cases {
		assert.Equal(
			func() time.Duration {
				p, err := parseTimeUnit(c.in)
				assert.Nil(err)
				return p
			}(),
			c.want,
		)
	}
}
开发者ID:haiheipijuan,项目名称:kasi,代码行数:28,代码来源:util_test.go


示例7: Test_ConnectCounter

func Test_ConnectCounter(t *testing.T) {
	assert := assert.Assert(t)
	cc := new(ConnectCounter)
	assert.False(cc.incr(true), "f1")
	assert.False(cc.incr(true), "f2")
	assert.False(cc.incr(true), "f3")
	assert.True(cc.incr(true), "t")
}
开发者ID:seanpont,项目名称:connect4,代码行数:8,代码来源:game_test.go


示例8: TestPasswordGenerationWithWords

func TestPasswordGenerationWithWords(t *testing.T) {
	assert := assert.Assert(t)
	generator := NewPasswordGenerator("w24")
	assert.Equal(generator.length, 24)
	assert.Equal(generator.words, true)
	password := generator.generate()
	assert.True(len(password) >= 24, "length")
}
开发者ID:seanpont,项目名称:passman,代码行数:8,代码来源:passman_test.go


示例9: TestBoard_turn_switches_after_each_play

func TestBoard_turn_switches_after_each_play(t *testing.T) {
	assert := assert.Assert(t)
	g := NewGame()
	assert.Equal(g.Turn(), byte(1))
	g.Play(1)
	assert.Equal(g.Turn(), byte(2))
	g.Play(1)
	assert.Equal(g.Turn(), byte(1))
}
开发者ID:seanpont,项目名称:connect4,代码行数:9,代码来源:game_test.go


示例10: TestDuplicatedID

func TestDuplicatedID(t *testing.T) {
	assert := assert.Assert(t)

	var yml string
	var err error

	yml = loadFile("config_duplicated_id.yml")
	_, err = kasi.ParseConfig(yml)
	assert.NotNil(err)
}
开发者ID:haiheipijuan,项目名称:kasi,代码行数:10,代码来源:conf_id_test.go


示例11: Test_C4Game

func Test_C4Game(t *testing.T) {
	assert := assert.Assert(t)
	game := GameWrapper{NewGame()}
	g := minimax.Game(game)
	assert.NotNil(g, "not nil")

	game1 := game.Copy()
	game1.Play(1)
	assert.NotEqual(game, game1)
}
开发者ID:seanpont,项目名称:connect4,代码行数:10,代码来源:solver_test.go


示例12: Test_HasWonUtilityFunction_returns_1_when_won

func Test_HasWonUtilityFunction_returns_1_when_won(t *testing.T) {
	assert := assert.Assert(t)
	game := NewGame()
	wrapper := GameWrapper{game}
	game.SetRows("1110000")
	assert.Equal(HasWon(wrapper), 0)
	hasWon, _ := game.Play(4) // now it's player 2's turn, but 1 won
	assert.True(hasWon, "should have won")
	assert.Equal(HasWon(wrapper), 1)
}
开发者ID:seanpont,项目名称:connect4,代码行数:10,代码来源:solver_test.go


示例13: TestEnv

func TestEnv(t *testing.T) {
	assert := assert.Assert(t)

	yml := loadFile("config_env.yml")
	setting, err := kasi.ParseConfig(yml)
	assert.Equal(err, nil)

	assert.NotEqual(setting.Env.Hostname, "")
	assert.NotEqual(setting.Env.GOOS, "")
}
开发者ID:haiheipijuan,项目名称:kasi,代码行数:10,代码来源:conf_env_test.go


示例14: TestPasswordGeneration

func TestPasswordGeneration(t *testing.T) {
	assert := assert.Assert(t)
	generator := NewPasswordGenerator("lunc20")
	assert.Equal(generator.length, 20)
	password := generator.generate()
	assert.Equal(len(password), 20)
	assert.True(strings.ContainsAny(password, LOWERCASE), "missing characters")
	assert.True(strings.ContainsAny(password, UPPERCASE), "missing characters")
	assert.True(strings.ContainsAny(password, NUMBERS), "missing characters")
	assert.True(strings.ContainsAny(password, CHARACTERS), "missing characters")
}
开发者ID:seanpont,项目名称:passman,代码行数:11,代码来源:passman_test.go


示例15: Test_Solve_avert_disaster

func Test_Solve_avert_disaster(t *testing.T) {
	assert := assert.Assert(t)
	game := NewGame()
	game.SetRows(
		"2000000",
		"2000000",
		"1110000")
	game.turn = p2
	move := Solve(game, 2)
	assert.Equal(move, 4)
}
开发者ID:seanpont,项目名称:connect4,代码行数:11,代码来源:solver_test.go


示例16: TestHostnamesWithString

func TestHostnamesWithString(t *testing.T) {
	assert := assert.Assert(t)

	yml := loadFile("config_hostnames_string.yml")
	setting, err := kasi.ParseConfig(yml)
	assert.Nil(err)

	assert.Equal(len(setting.Services), 1)
	assert.Equal(len(setting.Services[0].Hostnames), 1)
	assert.Equal(setting.Services[0].Hostnames[0], "my0.github.com")
}
开发者ID:haiheipijuan,项目名称:kasi,代码行数:11,代码来源:conf_hostnames_test.go


示例17: Test_Copy

func Test_Copy(t *testing.T) {
	assert := assert.Assert(t)
	g := NewGame()
	g.SetRows("1212000")
	g1 := g.Copy()
	g1.Play(5)
	assert.Equal(g.turn, p1)
	assert.Equal(g1.turn, p2)
	assert.Equal(g.board[0], []byte{1, 2, 1, 2, 0, 0, 0})
	assert.Equal(g1.board[0], []byte{1, 2, 1, 2, 1, 0, 0})
}
开发者ID:seanpont,项目名称:connect4,代码行数:11,代码来源:game_test.go


示例18: TestMinimax

func TestMinimax(t *testing.T) {
	assert := assert.Assert(t)
	//                     p1   [--p2--]  [------p1------]
	game := NewHeapGame(0, 0, 1, 0, 1, -1, 0, 0, 1, -1, 0, 1, 2, 0, 1)
	fmt.Println(game.utility)
	// best move: 1
	solver := &Solver{HeapUtilityFunction, 2}
	move, utility := solver.Solve(game)
	moveInt := move.(int)
	assert.Equal(moveInt, 1)
	assert.Equal(utility, 1)
}
开发者ID:seanpont,项目名称:connect4,代码行数:12,代码来源:minimax_test.go


示例19: Test_Play_returns_true_when_wins_left_diagonal

func Test_Play_returns_true_when_wins_left_diagonal(t *testing.T) {
	assert := assert.Assert(t)
	g := NewGame()

	g.SetRows(
		"0000000",
		"0001200",
		"0012200",
		"0121200")
	win, err := g.Play(5)
	assert.Nil(err, "error after player 1 played final piece")
	assert.True(win, "player 1 should have won")
}
开发者ID:seanpont,项目名称:connect4,代码行数:13,代码来源:game_test.go


示例20: Test_LegalMoves

func Test_LegalMoves(t *testing.T) {
	assert := assert.Assert(t)
	g := NewGame()
	assert.Equal(g.LegalMoves(),
		[]int{1, 2, 3, 4, 5, 6, 7})

	for row := 0; row < ROWS/2; row++ {
		g.Play(1)
		g.Play(1)
		g.Play(4)
		g.Play(4)
	}
	assert.Equal(g.LegalMoves(),
		[]int{2, 3, 5, 6, 7})
}
开发者ID:seanpont,项目名称:connect4,代码行数:15,代码来源:game_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang assert.Equal函数代码示例发布时间:2022-05-28
下一篇:
Golang fail2go.Conn类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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