poker

package module
v0.0.0-...-4fae0c6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2024 License: MIT Imports: 17 Imported by: 0

README

tdd-server

Создан для обучения ЯП Golang. Курс Learn go with tests.

Documentation

Index

Constants

View Source
const BadPlayerInputErrMsg = "Bad value received for number of players, please try again with a number"
View Source
const PlayerPrompt = "Please enter the number of players: "

Variables

This section is empty.

Functions

func Alerter

func Alerter(duration time.Duration, amount int, to io.Writer)

func AssertContentType

func AssertContentType(t testing.TB, response *httptest.ResponseRecorder, want string)

func AssertFinishCalledWith

func AssertFinishCalledWith(t testing.TB, game *GameSpy, winner string)

func AssertGameNotStarted

func AssertGameNotStarted(t testing.TB, game *GameSpy)

func AssertGameStartedWith

func AssertGameStartedWith(t testing.TB, game *GameSpy, numberOfPlayers int)

func AssertLeague

func AssertLeague(t testing.TB, got, want []Player)

func AssertMessagesSentToUser

func AssertMessagesSentToUser(t testing.TB, stdout *bytes.Buffer, messages ...string)

func AssertNoError

func AssertNoError(t testing.TB, err error)

func AssertPlayerWin

func AssertPlayerWin(t testing.TB, store *StubPlayerStore, winner string)

func AssertResponseBody

func AssertResponseBody(t testing.TB, got, want string)

func AssertScheduledAlert

func AssertScheduledAlert(t testing.TB, got, want ScheduledAlert)

func AssertScoreEquals

func AssertScoreEquals(t testing.TB, got, want int)

func AssertStatus

func AssertStatus(t testing.TB, got *httptest.ResponseRecorder, want int)

func CreateTempFile

func CreateTempFile(t testing.TB, initialData string) (*os.File, func())

func NewGetScoreRequest

func NewGetScoreRequest(name string) *http.Request

func NewLeagueRequest

func NewLeagueRequest() *http.Request

func NewPostWinRequest

func NewPostWinRequest(name string) *http.Request

Types

type BlindAlerter

type BlindAlerter interface {
	ScheduleAlertAt(duration time.Duration, amount int, to io.Writer)
}

type BlindAlerterFunc

type BlindAlerterFunc func(duration time.Duration, amount int, to io.Writer)

func (BlindAlerterFunc) ScheduleAlertAt

func (a BlindAlerterFunc) ScheduleAlertAt(duration time.Duration, amount int, to io.Writer)

type CLI

type CLI struct {
	// contains filtered or unexported fields
}

func NewCLI

func NewCLI(in io.Reader, out io.Writer, game Game) *CLI

func (*CLI) PlayPoker

func (cli *CLI) PlayPoker()

type FileSystemPlayerStore

type FileSystemPlayerStore struct {
	// contains filtered or unexported fields
}

func FileSystemPlayerStoreFromFile

func FileSystemPlayerStoreFromFile(path string) (*FileSystemPlayerStore, func(), error)

func NewFileSystemStore

func NewFileSystemStore(file *os.File) (*FileSystemPlayerStore, error)

func (*FileSystemPlayerStore) GetLeague

func (f *FileSystemPlayerStore) GetLeague() League

func (*FileSystemPlayerStore) GetPlayerScore

func (f *FileSystemPlayerStore) GetPlayerScore(name string) int

func (*FileSystemPlayerStore) RecordWin

func (f *FileSystemPlayerStore) RecordWin(name string)

type Game

type Game interface {
	Start(numberOfPlayers int, alertsDestination io.Writer)
	Finish(winner string)
}

type GameSpy

type GameSpy struct {
	StartCalled     bool
	StartCalledWith int
	BlindAlert      []byte

	FinishedCalled     bool
	FinishedCalledWith string
}

func (*GameSpy) Finish

func (g *GameSpy) Finish(winner string)

func (*GameSpy) Start

func (g *GameSpy) Start(numberOfPlayers int, out io.Writer)

type League

type League []Player

func (League) Find

func (l League) Find(name string) *Player

type Player

type Player struct {
	Name string
	Wins int
}

func GetLeagueFromResponse

func GetLeagueFromResponse(t testing.TB, body io.Reader) (league []Player)

func NewLeague

func NewLeague(rdr io.Reader) ([]Player, error)

type PlayerServer

type PlayerServer struct {
	http.Handler
	// contains filtered or unexported fields
}

func NewPlayerServer

func NewPlayerServer(store PlayerStore, game Game) (*PlayerServer, error)

type PlayerStore

type PlayerStore interface {
	GetPlayerScore(name string) int
	RecordWin(name string)
	GetLeague() League
}

type ScheduledAlert

type ScheduledAlert struct {
	At     time.Duration
	Amount int
}

func (ScheduledAlert) String

func (s ScheduledAlert) String() string

type SpyBlindAlerter

type SpyBlindAlerter struct {
	Alerts []ScheduledAlert
}

func (*SpyBlindAlerter) ScheduleAlertAt

func (s *SpyBlindAlerter) ScheduleAlertAt(at time.Duration, amount int, to io.Writer)

type StubPlayerStore

type StubPlayerStore struct {
	// contains filtered or unexported fields
}

func (*StubPlayerStore) GetLeague

func (s *StubPlayerStore) GetLeague() League

func (*StubPlayerStore) GetPlayerScore

func (s *StubPlayerStore) GetPlayerScore(name string) int

func (*StubPlayerStore) RecordWin

func (s *StubPlayerStore) RecordWin(name string)

type TexasHoldem

type TexasHoldem struct {
	// contains filtered or unexported fields
}

func NewGame

func NewGame(alerter BlindAlerter, store PlayerStore) *TexasHoldem

func (*TexasHoldem) Finish

func (p *TexasHoldem) Finish(winner string)

func (*TexasHoldem) Start

func (p *TexasHoldem) Start(numberOfPlayers int, alertsDestination io.Writer)

Directories

Path Synopsis
cmd
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL