Add tests to mlp
This commit is contained in:
parent
65a4a2e6bd
commit
b7e6f6cf01
5 changed files with 176 additions and 13 deletions
118
mlp/booster_test.go
Normal file
118
mlp/booster_test.go
Normal file
|
@ -0,0 +1,118 @@
|
|||
package mlp_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.fromouter.space/mcg/draft"
|
||||
"git.fromouter.space/mcg/draft/mlp"
|
||||
)
|
||||
|
||||
// TestAlternates tries to get alternates (SR/UR/RR)
|
||||
// This might require a while since it needs to generate MANY packs!
|
||||
// This test *requires* an internet connection!
|
||||
func TestAlternates(t *testing.T) {
|
||||
// Load Premiere/CN as they have their own UR ratios
|
||||
prSet, err := mlp.LoadSetHTTP(mlp.SetPremiere)
|
||||
if err != nil {
|
||||
t.Errorf("Could not fetch set data: %s", err.Error())
|
||||
}
|
||||
|
||||
cnSet, err := mlp.LoadSetHTTP(mlp.SetCanterlotNights)
|
||||
if err != nil {
|
||||
t.Errorf("Could not fetch set data: %s", err.Error())
|
||||
}
|
||||
|
||||
// Load set with Royal rares
|
||||
eoSet, err := mlp.LoadSetHTTP(mlp.SetEquestrialOdysseys)
|
||||
if err != nil {
|
||||
t.Errorf("Could not fetch set data: %s", err.Error())
|
||||
}
|
||||
|
||||
// Find all Premiere URs
|
||||
prURs := []string{}
|
||||
for _, card := range prSet.Cards {
|
||||
if card.Rarity == mlp.RarityUltraRare {
|
||||
prURs = append(prURs, card.ID)
|
||||
}
|
||||
}
|
||||
|
||||
// Find all CN URs
|
||||
cnURs := []string{}
|
||||
for _, card := range cnSet.Cards {
|
||||
if card.Rarity == mlp.RarityUltraRare {
|
||||
cnURs = append(cnURs, card.ID)
|
||||
}
|
||||
}
|
||||
|
||||
// Get some PR packs and search for URs
|
||||
prurfound := false
|
||||
for i := 0; i < 1000; i++ {
|
||||
pack := draft.MakePack(prSet)
|
||||
// Check for ultra rares
|
||||
for _, id := range prURs {
|
||||
if pack[7].ID == id {
|
||||
prurfound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if prurfound {
|
||||
fmt.Printf("PR Ultra Rare found after %d packs\n", i)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !prurfound {
|
||||
t.Errorf("No PR UR found after 1000 packs")
|
||||
}
|
||||
|
||||
// Get some CN packs and search for URs
|
||||
cnurfound := false
|
||||
for i := 0; i < 1000; i++ {
|
||||
pack := draft.MakePack(cnSet)
|
||||
// Check for ultra rares
|
||||
for _, id := range cnURs {
|
||||
if pack[7].ID == id {
|
||||
cnurfound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if cnurfound {
|
||||
fmt.Printf("CN Ultra Rare found after %d packs\n", i)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !cnurfound {
|
||||
t.Errorf("No CN UR found after 1000 packs")
|
||||
}
|
||||
|
||||
eorrfound := false
|
||||
for i := 0; i < 100000; i++ {
|
||||
pack := draft.MakePack(eoSet)
|
||||
// Check for royal rares
|
||||
if pack[6].ID == "eo207/rr1" || pack[6].ID == "eo208/rr2" {
|
||||
fmt.Printf("EO Royal Rare found after %d packs\n", i)
|
||||
eorrfound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !eorrfound {
|
||||
t.Errorf("No EO RR found after 100k packs")
|
||||
}
|
||||
}
|
||||
|
||||
// TestPackFixedSets tries to get packs a set that isn't a true set
|
||||
// This should result in empty packs
|
||||
func TestPackFixedSets(t *testing.T) {
|
||||
set, err := mlp.LoadSet(mlp.SetRockNRave, []byte("{}"))
|
||||
if err != nil {
|
||||
t.Errorf("Could not load set: %s", err.Error())
|
||||
}
|
||||
|
||||
pack := draft.MakePack(set)
|
||||
if len(pack) != 0 {
|
||||
t.Errorf("Expected an empty pack but got %d cards", len(pack))
|
||||
}
|
||||
}
|
|
@ -18,8 +18,8 @@ func TestDraftI8PCube(t *testing.T) {
|
|||
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"),
|
||||
mlp.I8PTypeEntry: mockCards("e1", "e2", "e3", "e4"),
|
||||
mlp.I8PTypeMulti: mockCards("m1", "m2", "m3", "m4", "m5"),
|
||||
mlp.I8PTypeEntry: mockCards("e1", "e2", "e3", "e4", "e5"),
|
||||
mlp.I8PTypeProblem: mockCards("P1", "P2"),
|
||||
}
|
||||
cube := mlp.MakeI8PCube(pool)
|
||||
|
|
|
@ -6,25 +6,25 @@ import "git.fromouter.space/mcg/draft"
|
|||
|
||||
var royalRares = map[SetID][]draft.Card{
|
||||
SetEquestrialOdysseys: {
|
||||
draft.Card{ID: "eo207"}, // Discord, Wrathful
|
||||
draft.Card{ID: "eo208"}, // Pinkie Pie, Remix Master
|
||||
draft.Card{ID: "eo207/rr1"}, // Discord, Wrathful
|
||||
draft.Card{ID: "eo208/rr2"}, // Pinkie Pie, Remix Master
|
||||
},
|
||||
SetHighMagic: {
|
||||
draft.Card{ID: "hm149"}, // Trixie, Highest Level Unicorn
|
||||
draft.Card{ID: "hm147"}, // Fluttershy, Saddle Rager
|
||||
draft.Card{ID: "hm145"}, // Rarity, Radiance
|
||||
draft.Card{ID: "hm149/rr1"}, // Trixie, Highest Level Unicorn
|
||||
draft.Card{ID: "hm147/rr2"}, // Fluttershy, Saddle Rager
|
||||
draft.Card{ID: "hm145/rr3"}, // Rarity, Radiance
|
||||
},
|
||||
SetMarksInTime: {
|
||||
draft.Card{ID: "mt139"}, // Rainbow Dash, One Winged Warrior
|
||||
draft.Card{ID: "mt141"}, // Princess Twilight Sparkle, Time Patrol
|
||||
draft.Card{ID: "mt139/rr1"}, // Rainbow Dash, One Winged Warrior
|
||||
draft.Card{ID: "mt141/rr2"}, // Princess Twilight Sparkle, Time Patrol
|
||||
},
|
||||
SetDefendersOfEquestria: {
|
||||
draft.Card{ID: "de135"}, // Applejack, Captain of the Seven Seas
|
||||
draft.Card{ID: "de135/rr1"}, // Applejack, Captain of the Seven Seas
|
||||
},
|
||||
SetSeaquestriaBeyond: {
|
||||
draft.Card{ID: "sb135"}, // Tempest Shadow, Stormcaller
|
||||
draft.Card{ID: "sb135/rr1"}, // Tempest Shadow, Stormcaller
|
||||
},
|
||||
SetFriendsForever: {
|
||||
draft.Card{ID: "ff136"}, // Mistmane, Pillar of Beauty
|
||||
draft.Card{ID: "ff136/rr1"}, // Mistmane, Pillar of Beauty
|
||||
},
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package mlp
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
@ -59,7 +60,10 @@ func LoadSetHTTP(id SetID) (*Set, error) {
|
|||
setid := strings.ToLower(string(id))
|
||||
|
||||
resp, err := http.Get("https://mcg.zyg.ovh/setdata/" + setid + ".json")
|
||||
if err != nil {
|
||||
if err != nil || resp.StatusCode != 200 {
|
||||
if err == nil {
|
||||
err = fmt.Errorf("server returned non-200 response code (%d)", resp.StatusCode)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
41
mlp/set_test.go
Normal file
41
mlp/set_test.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package mlp_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.fromouter.space/mcg/draft"
|
||||
"git.fromouter.space/mcg/draft/mlp"
|
||||
)
|
||||
|
||||
// TestSet retrieves a set online and generates a couple packs with it
|
||||
// This test *requires* an internet connection!
|
||||
func TestSet(t *testing.T) {
|
||||
deSet, err := mlp.LoadSetHTTP(mlp.SetDefendersOfEquestria)
|
||||
if err != nil {
|
||||
t.Errorf("Could not fetch set data: %s", err.Error())
|
||||
}
|
||||
|
||||
pack1 := draft.MakePack(deSet)
|
||||
pack2 := draft.MakePack(deSet)
|
||||
|
||||
// Make sure both packs have the exact number of cards
|
||||
if len(pack1) != 12 {
|
||||
t.Errorf("Expected 12 cards in pack 1 but got %d", len(pack1))
|
||||
}
|
||||
if len(pack2) != 12 {
|
||||
t.Errorf("Expected 12 cards in pack 2 but got %d", len(pack2))
|
||||
}
|
||||
|
||||
fmt.Printf("Cards in pack 1: %s\n", pack1)
|
||||
fmt.Printf("Cards in pack 2: %s\n", pack2)
|
||||
}
|
||||
|
||||
// TestWrongSet tries to fetch a set that doesn't exist
|
||||
// This test *requires* an internet connection!
|
||||
func TestWrongSet(t *testing.T) {
|
||||
_, err := mlp.LoadSetHTTP("nopenope")
|
||||
if err == nil {
|
||||
t.Errorf("Expected an error but didn't get one!")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue