mirror of
https://github.com/tiennm99/noitu.git
synced 2026-10-13 00:15:01 +00:00
wsapi_test.go was 2688 lines and 82 tests spanning every topic in the package. Pure moves: wsapi_test.go keeps the harness (the hand-built dictionary, the server-over-a-real-socket helpers, and the client-side driving methods every topic file below uses); game_test.go, presence_test.go, resume_test.go, lobby_test.go, protocol_test.go, ratelimit_test.go, bot_board_test.go, chat_test.go, deadend_test.go and report_test.go each hold one topic's tests. Three tests about sanitizing and distinguishing nicknames moved into the existing nickname_test.go alongside its fuzz target. hub_test.go was three lines of comment pointing at hub.go; the note now lives there instead, next to roomCount. Verified by counting: the wsapi package's declaration count is unchanged, `go test -list` finds the same tests it did before the split, and go build/vet/test -race and golangci-lint stay clean.
32 lines
914 B
Go
32 lines
914 B
Go
package wsapi
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/tiennm99dev/noitu/server/internal/game"
|
|
)
|
|
|
|
// The bot's frozen view of a position.
|
|
|
|
func TestFreezeBoardIncludesTheOpeningWord(t *testing.T) {
|
|
// The engine counts the opening word as played but Snapshot's history does
|
|
// not list it. A frozen board that missed it would let the bot choose a
|
|
// word the engine then rejects as already used — the two would disagree
|
|
// about the position while appearing to share one dictionary.
|
|
dict := chainDict()
|
|
e, err := game.New(dict, []game.PlayerID{"p1", "p2"}, "a b", time.Second, time.Now())
|
|
if err != nil {
|
|
t.Fatalf("engine: %v", err)
|
|
}
|
|
|
|
board := freezeBoard(e)
|
|
if !board.Used("a b") {
|
|
t.Error("frozen board does not consider the opening word played")
|
|
}
|
|
if !slices.Contains(board.LegalMoves(), "b c") {
|
|
t.Errorf("legal moves = %v, want the one continuation", board.LegalMoves())
|
|
}
|
|
}
|