本文整理汇总了Golang中github.com/seanpont/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
示例2: 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")
}
示例3: 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")
}
}
}
示例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)
}
示例5: 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")
}
示例6: 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))
}
示例7: 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)
}
示例8: 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})
}
示例9: 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")
}
示例10: 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")
}
示例11: 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)
}
示例12: 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})
}
示例13: TestID
func TestID(t *testing.T) {
assert := assert.Assert(t)
var yml string
var setting *kasi_conf.CoreSetting
var err error
yml = loadFile("config_check_id.yml")
setting, err = kasi.ParseConfig(yml)
assert.Equal(err, nil)
assert.Equal(setting.Services[0].GetID(), "this-is-service-id")
assert.Equal(setting.Services[0].Endpoints[0].GetID(), "findme")
assert.Equal(len(setting.Services[0].Endpoints[1].GetID()), 36)
assert.Equal(setting.Services[0].Endpoints[1].GetID(), setting.Services[0].Endpoints[1].GetID())
}
示例14: TestHostnamesWithStrings
func TestHostnamesWithStrings(t *testing.T) {
assert := assert.Assert(t)
yml := loadFile("config_hostnames_strings.yml")
setting, err := kasi.ParseConfig(yml)
assert.Nil(err)
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")
}
}
}
示例15: 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,
)
}
}