board_test.gno
1.15 Kb · 45 lines
1package brawl
2
3import (
4 "strconv"
5 "testing"
6)
7
8func fake(id int, who string, g int) string {
9 return encode(&Ghost{ID: id, Player: address(who), Name: "p" + strconv.Itoa(id), Gold: g, Inputs: "a|b"})
10}
11
12func TestBoard(t *testing.T) {
13 board = [TopSize]string{}
14 for i := 0; i < 12; i++ {
15 who := "player" + strconv.Itoa(i)
16 g := 10 + i
17 if p := place(who, g); p >= 0 {
18 insert(fake(100+i, who, g), who)
19 }
20 }
21 if gold(board[0]) != 21 || gold(board[TopSize-1]) != 12 {
22 t.Fatalf("board ends: %d .. %d", gold(board[0]), gold(board[TopSize-1]))
23 }
24 if place("newcomer", 12) != -1 || place("newcomer", 13) != TopSize-1 {
25 t.Fatal("a newcomer must beat the 10th place")
26 }
27 // a player keeps one place, and only a better score moves it
28 if place("player5", 14) != -1 {
29 t.Fatal("player5 already has 15")
30 }
31 insert(fake(200, "player5", 30), "player5")
32 n := 0
33 for _, s := range board {
34 if player(s) == "player5" {
35 n++
36 }
37 }
38 if n != 1 || gold(board[0]) != 30 {
39 t.Fatalf("player5 holds %d places, top is %d", n, gold(board[0]))
40 }
41 if g := decode(board[0]); g.Inputs != "a|b" || g.Name != "p200" {
42 t.Fatalf("decode: %+v", g)
43 }
44 board = [TopSize]string{}
45}