Ejemplo n.º 1
0
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")
}
Ejemplo n.º 2
0
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)
}
Ejemplo n.º 3
0
func Test_Play_returns_true_when_wins_in_row(t *testing.T) {
	assert := assert.Assert(t)
	g := NewGame()

	players := []int{1, 2}
	for i := 1; i < 4; i++ {
		for _, p := range players {
			won, err := g.Play(i)
			assert.False(won, "player %v should not have won", p)
			assert.Nil(err, "error after player %d played", p)
		}
	}
	won, err := g.Play(4)
	assert.Nil(err, "error when player 1 played final piece")
	assert.True(won, "player 1 should have won")
}
Ejemplo n.º 4
0
func Test_Solve_aver_vertical_disaster(t *testing.T) {
	assert := assert.Assert(t)
	game := NewGame()
	game.SetRows(
		"1000000",
		"2010000",
		"2211000",
		"2211120")

	over, _ := game.Play(2)
	assert.False(over, "wtf")

	// game.turn = p2
	// move := SolveVerbose(game, 2)
	// assert.Equal(move, 3)

}
Ejemplo n.º 5
0
// Make sure I wrote heap game correctly before I try to win it.
func TestHeapGame(t *testing.T) {
	assert := assert.Assert(t)
	assert.Nil(nil, "good")

	f := HeapUtilityFunction

	game := NewHeapGame(1, 2, 3, 4, 5, 6, 7, 8)
	assert.Equal(f(game), 1)

	legalMoves := game.LegalMoves()
	move := legalMoves[0]
	game1 := game.Copy()
	over, _ := game1.Play(move)
	assert.False(over, "game not yet over")
	assert.NotEqual(game, game1)
	assert.Equal(f(game1), 2)

	game2 := game1.Copy()
	over, _ = game2.Play(1)
	assert.Equal(f(game2), 5)
	assert.True(over, "game should be over")
}