recipe_test.gno
2.72 Kb · 86 lines
1package brawl
2
3import "testing"
4
5func TestRecipeRoundTrip(t *testing.T) {
6 for _, s := range []string{"Blink Thief/84/D82S11", "O'Hare/150/S22P13T21", "Pick/20/P11", "Z-9/200/H00I90K11"} {
7 r, err := ParseRecipe(s)
8 if err != nil {
9 t.Fatalf("%s: %s", s, err.Error())
10 }
11 if r.String() != s {
12 t.Fatalf("%s wrote back as %s", s, r.String())
13 }
14 }
15}
16
17func TestRecipeRefused(t *testing.T) {
18 for _, s := range []string{"", "A/20/", "A/020/P11", "A/19/P11", "A/201/H00", " A/80/H00", "A/80/H01",
19 "A/32/S11S11", "A/32/Q11", "A/31/S11", "A/99/S11H00I90K11", "A|B/80/H00", "A/200/S32", "A/20/h00"} {
20 if _, err := ParseRecipe(s); err == nil {
21 t.Fatalf("%q should be refused", s)
22 }
23 }
24}
25
26// Recipes built like the built-in specials must cost at least as much as the
27// class's own cooldown, so a copy is never a cheaper version of the original.
28// (The Trickster's feint has no recipe effect, so it has no copy.)
29func TestCopiesCostMore(t *testing.T) {
30 copies := []struct {
31 class int
32 fx string
33 }{
34 {Hunter, "S15K25"},
35 {Brawler, "S21K91T41"},
36 {Coward, "D82I70"},
37 {Reader, "P24"},
38 }
39 for _, c := range copies {
40 r, err := ParseRecipe("X/200/" + c.fx)
41 if err != nil {
42 t.Fatal(err.Error())
43 }
44 if r.Cost() < SpecialCD[c.class] {
45 t.Fatalf("%s costs %d, under the class's %d", c.fx, r.Cost(), SpecialCD[c.class])
46 }
47 }
48}
49
50// With no recipe the variants play exactly like Play, Duel and Versus.
51func TestNoRecipeSame(t *testing.T) {
52 a, b := noisy(3), noisy(4)
53 x1, y1 := Play(9, Hunter, Reader, a, b)
54 x2, y2 := PlayMoves(9, Hunter, Reader, a, b, "", "")
55 x3, y3 := Duel(9, Hunter, Reader, a, b)
56 x4, y4 := DuelMoves(9, Hunter, Reader, a, b, "", "")
57 x5, y5 := Versus(9, Hunter, Hard, a)
58 x6, y6 := VersusMove(9, Hunter, Hard, a, "")
59 if x1 != x2 || y1 != y2 || x3 != x4 || y3 != y4 || x5 != x6 || y5 != y6 {
60 t.Fatal("a variant with no recipe plays differently")
61 }
62}
63
64// A recipe replaces the class special and sets its own cooldown.
65func TestRecipeUsed(t *testing.T) {
66 g := New(5, Hunter, Brawler)
67 g.Equip(0, MustRecipe("Magnet/40/P24"))
68 g.Step(Still, Special, Still, None)
69 if g.F[0].CD != 40 {
70 t.Fatalf("cooldown %d, want 40", g.F[0].CD)
71 }
72}
73
74func TestDescribe(t *testing.T) {
75 got := MustRecipe("Blink Thief/84/D82S11").Describe()
76 want := "dash 4 squares to the nearest gold, then steal 1 gold within 1.45 squares"
77 if got != want {
78 t.Fatalf("%q", got)
79 }
80}
81
82// For gas: one ranked replay against the Hard bot, with and without a recipe.
83// Run with gno test -print-runtime-metrics -run Gas.
84func TestGasVersus(t *testing.T) { Versus(3, Hunter, Hard, gen(77)) }
85func TestGasVersusMove(t *testing.T) { VersusMove(3, Hunter, Hard, gen(77), "Sniper/54/S15K25") }
86func TestGasParse(t *testing.T) { MustRecipe("O'Hare/150/S22P13T21") }