From dc14ca9e6f28b82be45f62cb7647b333d9aa687e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=AEittaG=20ordnasselA?= Date: Wed, 12 Jun 2019 16:06:52 +0200 Subject: [PATCH] Add pod test for I8PCube --- mlp/i8pcube.go | 2 +- mlp/i8pcube_test.go | 75 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/mlp/i8pcube.go b/mlp/i8pcube.go index 283a686..63c8023 100644 --- a/mlp/i8pcube.go +++ b/mlp/i8pcube.go @@ -199,7 +199,7 @@ func (c *I8PCube) PackProvider(mainPacks, problemPacks int) draft.PackProvider { for main := 0; main < mainPacks; main++ { packs[main] = draft.MakePack(c.Main) } - for problem := 0; problem < problemPacks; problemPacks++ { + for problem := 0; problem < problemPacks; problem++ { packs[mainPacks+problem] = draft.MakePack(c.Problems) } return packs diff --git a/mlp/i8pcube_test.go b/mlp/i8pcube_test.go index 6d995af..b0ab895 100644 --- a/mlp/i8pcube_test.go +++ b/mlp/i8pcube_test.go @@ -64,6 +64,81 @@ func TestDryCube(t *testing.T) { } } +// TestPodI8PCube sets up a pod for drafting a I8PCube +func TestPodI8PCube(t *testing.T) { + const PlayerCount = 2 + const CardsPerPack = 12 + const MainPacks = 1 + const ProblemPacks = 1 + + const CardsDrafted = PlayerCount * CardsPerPack * (MainPacks + ProblemPacks) + + // Should be barely enough cards to always draft something + pool := mlp.I8PPool{ + mlp.I8PTypeBlue: mockCards("b1", "b2", "b3"), + mlp.I8PTypeOrange: mockCards("o1", "o2", "o3"), + mlp.I8PTypePink: mockCards("p1", "p2", "p3"), + mlp.I8PTypePurple: mockCards("u1", "u2", "u3"), + mlp.I8PTypeWhite: mockCards("w1", "w2", "w3"), + mlp.I8PTypeYellow: mockCards("y1", "y2", "y3"), + mlp.I8PTypeNone: mockCards("n1", "n2", "n3"), + mlp.I8PTypeMulti: mockCards("m1", "m2", "m3", "m4", "m5"), + mlp.I8PTypeEntry: mockCards("e1", "e2", "e3", "e4", "e5"), + mlp.I8PTypeProblem: mockCards( + "P1", "P2", "P3", "P4", + "P5", "P6", "P7", "P8", + "P9", "P10", "P11", "P12", + "Q1", "Q2", "Q3", "Q4", + "P5", "P6", "Q7", "Q8", + "Q9", "Q10", "Q11", "Q12", + ), + } + cube := mlp.MakeI8PCube(pool, mlp.DefaultI8PSchema()) + + remainingStart := i8pCountRemaining(cube) + + // Every players get a main pack and a problem pack + provider := cube.PackProvider(MainPacks, ProblemPacks) + + // Create pod with 2 players + pod := draft.MakePod(PlayerCount, provider) + + for i, player := range pod.Players { + // Get and print packs + t.Logf("Player %d\n", i) + for packi, pack := range player.Packs { + t.Logf(" - Pack #%d: %s\n", packi, pack) + if len(pack) != CardsPerPack { + t.Fatalf("Expected %d cards in pack but only got %d\n", CardsPerPack, len(pack)) + } + } + } + + remainingEnd := i8pCountRemaining(cube) + t.Logf("Remaining cards: %d\n", remainingEnd) + + if remainingEnd != remainingStart-CardsDrafted { + t.Fatalf("Expected %d to be left in the cube but found %d\n", remainingStart-CardsDrafted, remainingEnd) + } +} + +// Counts remaining cards in a I8PCube +func i8pCountRemaining(cube *mlp.I8PCube) int { + total := 0 + + // Count all cards in main pool + for _, pool := range cube.Main.Cards { + total += len(pool) + } + // Count all cards in problem pool + for _, pool := range cube.Problems.Cards { + total += len(pool) + } + + return total +} + +// Creates multiple cards from given IDs func mockCards(ids ...string) []mlp.Card { out := make([]mlp.Card, len(ids)) for i, id := range ids {