package brawl import "testing" func TestRecipeRoundTrip(t *testing.T) { for _, s := range []string{"Blink Thief/84/D82S11", "O'Hare/150/S22P13T21", "Pick/20/P11", "Z-9/200/H00I90K11"} { r, err := ParseRecipe(s) if err != nil { t.Fatalf("%s: %s", s, err.Error()) } if r.String() != s { t.Fatalf("%s wrote back as %s", s, r.String()) } } } func TestRecipeRefused(t *testing.T) { for _, s := range []string{"", "A/20/", "A/020/P11", "A/19/P11", "A/201/H00", " A/80/H00", "A/80/H01", "A/32/S11S11", "A/32/Q11", "A/31/S11", "A/99/S11H00I90K11", "A|B/80/H00", "A/200/S32", "A/20/h00"} { if _, err := ParseRecipe(s); err == nil { t.Fatalf("%q should be refused", s) } } } // Recipes built like the built-in specials must cost at least as much as the // class's own cooldown, so a copy is never a cheaper version of the original. // (The Trickster's feint has no recipe effect, so it has no copy.) func TestCopiesCostMore(t *testing.T) { copies := []struct { class int fx string }{ {Hunter, "S15K25"}, {Brawler, "S21K91T41"}, {Coward, "D82I70"}, {Reader, "P24"}, } for _, c := range copies { r, err := ParseRecipe("X/200/" + c.fx) if err != nil { t.Fatal(err.Error()) } if r.Cost() < SpecialCD[c.class] { t.Fatalf("%s costs %d, under the class's %d", c.fx, r.Cost(), SpecialCD[c.class]) } } } // With no recipe the variants play exactly like Play, Duel and Versus. func TestNoRecipeSame(t *testing.T) { a, b := noisy(3), noisy(4) x1, y1 := Play(9, Hunter, Reader, a, b) x2, y2 := PlayMoves(9, Hunter, Reader, a, b, "", "") x3, y3 := Duel(9, Hunter, Reader, a, b) x4, y4 := DuelMoves(9, Hunter, Reader, a, b, "", "") x5, y5 := Versus(9, Hunter, Hard, a) x6, y6 := VersusMove(9, Hunter, Hard, a, "") if x1 != x2 || y1 != y2 || x3 != x4 || y3 != y4 || x5 != x6 || y5 != y6 { t.Fatal("a variant with no recipe plays differently") } } // A recipe replaces the class special and sets its own cooldown. func TestRecipeUsed(t *testing.T) { g := New(5, Hunter, Brawler) g.Equip(0, MustRecipe("Magnet/40/P24")) g.Step(Still, Special, Still, None) if g.F[0].CD != 40 { t.Fatalf("cooldown %d, want 40", g.F[0].CD) } } func TestDescribe(t *testing.T) { got := MustRecipe("Blink Thief/84/D82S11").Describe() want := "dash 4 squares to the nearest gold, then steal 1 gold within 1.45 squares" if got != want { t.Fatalf("%q", got) } } // For gas: one ranked replay against the Hard bot, with and without a recipe. // Run with gno test -print-runtime-metrics -run Gas. func TestGasVersus(t *testing.T) { Versus(3, Hunter, Hard, gen(77)) } func TestGasVersusMove(t *testing.T) { VersusMove(3, Hunter, Hard, gen(77), "Sniper/54/S15K25") } func TestGasParse(t *testing.T) { MustRecipe("O'Hare/150/S22P13T21") }