Esempio n. 1
0
// assumes gobot/server is well formed
func TestBasic(t *testing.T) {
	ts := httptest.NewServer(server.MuxerAPIv1())
	p1 := newClient(t, ts.URL, 1, game.Black)
	p2 := newClient(t, ts.URL, 2, game.White)

	// white can't play yet
	if err := p2.Move(game.Position{0, 2}); err != game.ErrWrongPlayer {
		t.Errorf("move [0,2] expected error '%s', got '%s'", game.ErrWrongPlayer, err)
	}

	v := validator(t)
	v.After(2, wait(t, p2))
	v.Before(1, move(t, p1, 0, 2))
	v.Verify(time.Second)
	v.After(4, wait(t, p1))
	// Throw in an invalid move before scheduling the real one
	// This test is slightly broken
	if err := p2.Move(game.Position{0, 2}); err != game.ErrSpotNotEmpty {
		t.Errorf("move [0,2] expected error '%s', got '%s'", game.ErrSpotNotEmpty, err)
	}
	v.Before(3, move(t, p2, 1, 0))
	v.Verify(time.Second)
	v.After(6, wait(t, p2))
	v.Before(5, pass(t, p1))
	v.Verify(time.Second)
	v.After(8, wait(t, p1))
	v.Before(7, passOver(t, p2))
	v.Verify(time.Second)
	v.After(9, gameOver(t, p1))
	v.After(9, gameOver(t, p2))
	v.After(9, gameOver(t, p1))
	v.After(9, gameOver(t, p2))
	v.Verify(time.Second)

	testPosition(t, p1, game.White, 1, 0)
	testPosition(t, p2, game.White, 1, 0)
}
Esempio n. 2
0
func main() {
	log.Fatal(http.ListenAndServe(*port, server.MuxerAPIv1()))
}