2019-05-31 12:21:50 +00:00
|
|
|
package mlp_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.fromouter.space/mcg/draft"
|
|
|
|
"git.fromouter.space/mcg/draft/mlp"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestDraftI8PCube sets up a I8PCube and drafts 3 packs from it
|
|
|
|
func TestDraftI8PCube(t *testing.T) {
|
|
|
|
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"),
|
2019-05-31 13:13:13 +00:00
|
|
|
mlp.I8PTypeMulti: mockCards("m1", "m2", "m3", "m4", "m5"),
|
|
|
|
mlp.I8PTypeEntry: mockCards("e1", "e2", "e3", "e4", "e5"),
|
2019-05-31 12:21:50 +00:00
|
|
|
mlp.I8PTypeProblem: mockCards("P1", "P2"),
|
|
|
|
}
|
2019-07-01 12:41:42 +00:00
|
|
|
cube := mlp.MakeI8PCube(pool, mlp.DefaultI8PSchema(), 12)
|
2019-05-31 12:21:50 +00:00
|
|
|
|
|
|
|
pack1 := draft.MakePack(cube.Main)
|
|
|
|
pack2 := draft.MakePack(cube.Main)
|
|
|
|
pack3 := draft.MakePack(cube.Problems)
|
|
|
|
|
|
|
|
if len(pack1) != 12 {
|
2019-06-17 20:56:05 +00:00
|
|
|
t.Fatalf("Expected 12 cards in pack 1 but got %d", len(pack1))
|
2019-05-31 12:21:50 +00:00
|
|
|
}
|
|
|
|
if len(pack2) != 12 {
|
2019-06-17 20:56:05 +00:00
|
|
|
t.Fatalf("Expected 12 cards in pack 2 but got %d", len(pack2))
|
2019-05-31 12:21:50 +00:00
|
|
|
}
|
|
|
|
if len(pack3) != 2 {
|
2019-06-17 20:56:05 +00:00
|
|
|
t.Fatalf("Expected 2 cards in pack 3 but got %d", len(pack3))
|
2019-05-31 12:21:50 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 13:40:21 +00:00
|
|
|
t.Logf("Cards in pack1: %s\n", pack1)
|
|
|
|
t.Logf("Cards in pack2: %s\n", pack2)
|
|
|
|
t.Logf("Cards in pack3: %s\n", pack3)
|
2019-05-31 12:21:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestDryCube tries drying up the cube to make the "OtherProvider" not able to pick a card
|
|
|
|
// Expected behavior is to have a 11 card pack generate and not crash.
|
|
|
|
// This should **never** happen! If it does, please go fix your cube!
|
|
|
|
func TestDryCube(t *testing.T) {
|
|
|
|
pool := mlp.I8PPool{
|
|
|
|
mlp.I8PTypeBlue: mockCards("b1"),
|
|
|
|
mlp.I8PTypeOrange: mockCards("o1"),
|
|
|
|
mlp.I8PTypePink: mockCards("p1"),
|
|
|
|
mlp.I8PTypePurple: mockCards("u1"),
|
|
|
|
mlp.I8PTypeWhite: mockCards("w1"),
|
|
|
|
mlp.I8PTypeYellow: mockCards("y1"),
|
|
|
|
mlp.I8PTypeNone: mockCards("n1"),
|
|
|
|
mlp.I8PTypeMulti: mockCards("m1", "m4"),
|
|
|
|
mlp.I8PTypeEntry: mockCards("e1", "e4"),
|
|
|
|
}
|
2019-07-01 12:41:42 +00:00
|
|
|
cube := mlp.MakeI8PCube(pool, mlp.DefaultI8PSchema(), 12)
|
2019-05-31 12:21:50 +00:00
|
|
|
pack := draft.MakePack(cube.Main)
|
|
|
|
if len(pack) != 11 {
|
2019-06-17 20:56:05 +00:00
|
|
|
t.Fatalf("Expected 11 cards in pack but got %d", len(pack))
|
2019-05-31 12:21:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 14:06:52 +00:00
|
|
|
// 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",
|
|
|
|
),
|
|
|
|
}
|
2019-07-01 12:41:42 +00:00
|
|
|
cube := mlp.MakeI8PCube(pool, mlp.DefaultI8PSchema(), 12)
|
2019-06-12 14:06:52 +00:00
|
|
|
|
|
|
|
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
|
2019-05-31 12:21:50 +00:00
|
|
|
func mockCards(ids ...string) []mlp.Card {
|
|
|
|
out := make([]mlp.Card, len(ids))
|
|
|
|
for i, id := range ids {
|
|
|
|
out[i] = mlp.Card{ID: id}
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|