func TestItem(t *testing.T) { ver := gen3.OpenROM(ROM(t)) if ver == nil { t.Fatalf("failed to open ROM") } item := ver.ItemByIndex(1) if v := item.Index(); v != 1 { t.Errorf("Index: unexpected result %d", v) } if v := item.Name(); v != "MASTER BALL" { t.Errorf("Name: unexpected result \"%s\"", v) } if v := item.Description(); v != "The best BALL that\ncatches a POKéMON\nwithout fail." { t.Errorf("Description: unexpected result \"%s\"", v) } if v := item.Price(); v != 0 { t.Errorf("Price: unexpected result %d", v) } item = ver.ItemByIndex(13) if v := item.Index(); v != 13 { t.Errorf("Index: unexpected result %d", v) } if v := item.Name(); v != "POTION" { t.Errorf("Name: unexpected result \"%s\"", v) } if v := item.Description(); v != "Restores the HP of\na POKéMON by\n20 points." { t.Errorf("Description: unexpected result \"%s\"", v) } if v := item.Price(); v != 300 { t.Errorf("Price: unexpected result %d", v) } }
func TestEvolution(t *testing.T) { ver := gen3.OpenROM(ROM(t)) if ver == nil { t.Fatalf("failed to open ROM") } evo := ver.SpeciesByIndex(1).Evolutions()[0] if v := evo.Target(); v != ver.SpeciesByIndex(2) { if v == nil { t.Errorf("Target: unexpected result <nil>") } else { t.Errorf("Target: unexpected result %d (%s)", v.Index(), v.Name()) } } if v := evo.Method(); v != 4 { t.Errorf("Method: unexpected result %d", v) } if v := evo.Param(); v != 16 { t.Errorf("Param: unexpected result %d", v) } type ev struct { species string evo int method string } expected := []ev{ {"CHANSEY", 0, "Friendship"}, {"EEVEE", 3, "Friendship (Day)"}, {"EEVEE", 4, "Friendship (Night)"}, {"BULBASAUR", 0, "Level 16"}, {"HAUNTER", 0, "Trade"}, {"ONIX", 0, "Trade holding METAL COAT"}, {"EEVEE", 0, "Use THUNDERSTONE"}, {"TYROGUE", 1, "Level 20 if ATK > DEF"}, {"TYROGUE", 2, "Level 20 if ATK = DEF"}, {"TYROGUE", 0, "Level 20 if ATK < DEF"}, {"WURMPLE", 0, "Personality[1] (7)"}, {"WURMPLE", 1, "Personality[2] (7)"}, {"NINCADA", 0, "Level 20 (Spawns extra)"}, {"NINCADA", 1, "Level 20 (Spawned)"}, {"FEEBAS", 0, "Beauty (170)"}, } for _, e := range expected { species := ver.SpeciesByName(e.species) evo := species.Evolutions()[e.evo] if evo.MethodString() != e.method { t.Errorf("MethodString: unexpected result: %s (%d) -> \"%s\"", e.species, e.evo, evo.MethodString()) } } }
func TestPokedex(t *testing.T) { ver := gen3.OpenROM(ROM(t)) if ver == nil { t.Fatalf("failed to open ROM") } dex := ver.Pokedex()[0] if v := dex.Name(); v != "National" { t.Errorf("Name: unexpected result \"%s\"", v) } if v := dex.Size(); v != 386 { t.Errorf("Size: unexpected result \"%s\"", v) } type sp struct { name string num int } for _, s := range []sp{{"Bulbasaur", 1}, {"Mew", 151}, {"Treecko", 252}, {"Deoxys", 386}} { species := ver.SpeciesByName(s.name) if v := dex.Species(s.num); v != species { if v == nil { t.Errorf("Species: %s: unexpected result <nil>", species.Name()) } else { t.Errorf("Species: %s: unexpected result %d (%s)", species.Name(), v.Index(), v.Name()) } } if v := dex.SpeciesNumber(species); v != s.num { t.Errorf("SpeciesNumber: %s: unexpected result %d", species.Name(), v) } } ExpectPanic(t, "Species", func() { dex.Species(-1) }) ExpectPanic(t, "Species", func() { dex.Species(0) }) ExpectPanic(t, "Species", func() { dex.Species(dex.Size() + 1) }) if v := dex.AllSpecies(); len(v) != dex.Size() { t.Errorf("AllSpecies: unexpected length of result %d", len(v)) } }
func TestAbility(t *testing.T) { ver := gen3.OpenROM(ROM(t)) if ver == nil { t.Fatalf("failed to open ROM") } ability := ver.AbilityByIndex(1) if v := ability.Index(); v != 1 { t.Errorf("Index: unexpected result %d", v) } if v := ability.Name(); v != "STENCH" { t.Errorf("Name: unexpected result \"%s\"", v) } if v := ability.Description(); v != "Helps repel wild POKéMON." { t.Errorf("Description: unexpected result \"%s\"", v) } }
func TestMove(t *testing.T) { ver := gen3.OpenROM(ROM(t)) if ver == nil { t.Fatalf("failed to open ROM") } move := ver.MoveByIndex(1) if v := move.Index(); v != 1 { t.Errorf("Index: unexpected result \"%s\"", v) } if v := move.Name(); v != "POUND" { t.Errorf("Name: unexpected result \"%s\"", v) } if v := move.Description(); v != "Pounds the foe with\nforelegs or tail." { t.Errorf("Description: unexpected result \"%s\"", v) } if v := move.Type(); v != pkm.TypeNormal { t.Errorf("Type: unexpected result \"%s\"", v) } if v := move.BasePower(); v != 40 { t.Errorf("BasePower: unexpected result %d", v) } if v := move.Accuracy(); v != 100 { t.Errorf("Accuracy: unexpected result %d", v) } if v := move.Effect(); v != 0 { t.Errorf("Effect: unexpected result %d", v) } if v := move.EffectAccuracy(); v != 0 { t.Errorf("EffectAccuracy: unexpected result %d", v) } if v := move.Affectee(); v != 0 { t.Errorf("Affectee: unexpected result %d", v) } if v := move.Priority(); v != 0 { t.Errorf("Priority: unexpected result %d", v) } if v := move.Flags(); v != pkm.Contact|pkm.Protect|pkm.MirrorMove|pkm.KingsRock { t.Errorf("Flags: unexpected result %s", v) } }
func TestTM(t *testing.T) { ver := gen3.OpenROM(ROM(t)) if ver == nil { t.Fatalf("failed to open ROM") } tm := ver.TMByIndex(0) if v := tm.Index(); v != 0 { t.Errorf("Index: unexpected result %d", v) } if v := tm.Name(); v != "TM01" { t.Errorf("Name: unexpected result \"%s\"", v) } if v := tm.Move(); v.Index() != 264 { t.Errorf("Move: unexpected result %d", v.Index()) } tm = ver.TMByIndex(35) if v := tm.Index(); v != 35 { t.Errorf("Index: unexpected result %d", v) } if v := tm.Name(); v != "TM36" { t.Errorf("Name: unexpected result \"%s\"", v) } if v := tm.Move(); v.Index() != 188 { t.Errorf("Move: unexpected result %d", v.Index()) } tm = ver.TMByIndex(50) if v := tm.Index(); v != 50 { t.Errorf("Index: unexpected result %d", v) } if v := tm.Name(); v != "HM01" { t.Errorf("Name: unexpected result \"%s\"", v) } if v := tm.Move(); v.Index() != 15 { t.Errorf("Move: unexpected result %d", v.Index()) } }
func TestVersion(t *testing.T) { ver := gen3.OpenROM(ROM(t)) if ver == nil { t.Fatalf("failed to open ROM") } if !strings.Contains(ver.Name(), "Emerald") { t.Errorf("Name: unexpected name `%s`", ver.Name()) } if ver.GameCode() != gen3.CodeEmeraldEN { t.Errorf("GameCode: got game code %s, expected %s", ver.GameCode(), gen3.CodeEmeraldEN) } if ver.Query() == nil { t.Errorf("Query: expected Query") } if len(ver.Codecs()) == 0 { t.Errorf("Codecs: expected at least one codec") } if ver.DefaultCodec() == nil { t.Errorf("DefaultCodec: expected default codec") } if ver.Codecs()[0] != ver.DefaultCodec() { t.Errorf("Codecs: first codec should be default codec") } ExpectPanic(t, "SpeciesByIndex", func() { ver.SpeciesByIndex(-1) }) ExpectPanic(t, "SpeciesByIndex", func() { ver.SpeciesByIndex(ver.SpeciesIndexSize()) }) ExpectPanic(t, "SpeciesByIndex", func() { ver.SpeciesByIndex(ver.SpeciesIndexSize() + 1) }) for i := 0; i < ver.SpeciesIndexSize(); i++ { s := ver.SpeciesByIndex(i) if s.Index() != i { t.Errorf("SpeciesByIndex: returned index %d, expected %d", s.Index(), i) break } } if ver.SpeciesByName("BULBASAUR") == nil { t.Errorf("SpeciesByName: returned nil species") } else { if ver.SpeciesByName("BULBASAUR").Index() != 1 { t.Errorf("SpeciesByName: expected index 1") } if ver.SpeciesByName("Bulbasaur") == nil { t.Errorf("SpeciesByName: not case-insensitive") } } if ver.SpeciesByName("") != nil { t.Errorf("SpeciesByName: expected nil") } if ver.SpeciesByName(ver.SpeciesByIndex(ver.SpeciesIndexSize()-1).Name()) == nil { t.Errorf("SpeciesByName: returned nil last species") } if len(ver.Pokedex()) == 0 { t.Errorf("Pokedex: expected at least one pokedex") } if ver.PokedexByName("National") == nil { t.Errorf("PokedexByName: expected pokedex") } if ver.PokedexByName("Standard") == nil { t.Errorf("PokedexByName: expected pokedex") } if ver.PokedexByName("") != nil { t.Errorf("PokedexByName: unexpected pokedex") } if len(ver.Items()) != ver.ItemIndexSize() { t.Errorf("Items: expected length %d, got %d", ver.ItemIndexSize(), len(ver.Items())) } ExpectPanic(t, "ItemByIndex", func() { ver.ItemByIndex(-1) }) ExpectPanic(t, "ItemByIndex", func() { ver.ItemByIndex(ver.ItemIndexSize()) }) ExpectPanic(t, "ItemByIndex", func() { ver.ItemByIndex(ver.ItemIndexSize() + 1) }) for i := 0; i < ver.ItemIndexSize(); i++ { s := ver.ItemByIndex(i) if s.Index() != i { t.Errorf("ItemByIndex: returned index %d, expected %d", s.Index(), i) break } } if ver.ItemByName("MASTER BALL") == nil { t.Errorf("ItemByName: returned nil item") } else { if ver.ItemByName("MASTER BALL").Index() != 1 { t.Errorf("ItemByName: expected index 1") } if ver.ItemByName("Master Ball") == nil { t.Errorf("ItemByName: not case-insensitive") } } if ver.ItemByName("") != nil { t.Errorf("ItemByName: expected nil") } if ver.ItemByName(ver.ItemByIndex(ver.ItemIndexSize()-1).Name()) == nil { t.Errorf("ItemByName: returned nil last species") } if len(ver.Abilities()) != ver.AbilityIndexSize() { t.Errorf("Abilities: expected length %d, got %d", ver.AbilityIndexSize(), len(ver.Abilities())) } ExpectPanic(t, "AbilityByIndex", func() { ver.AbilityByIndex(-1) }) ExpectPanic(t, "AbilityByIndex", func() { ver.AbilityByIndex(ver.AbilityIndexSize()) }) ExpectPanic(t, "AbilityByIndex", func() { ver.AbilityByIndex(ver.AbilityIndexSize() + 1) }) for i := 0; i < ver.AbilityIndexSize(); i++ { s := ver.AbilityByIndex(i) if s.Index() != i { t.Errorf("AbilityByIndex: returned index %d, expected %d", s.Index(), i) break } } if ver.AbilityByName("STENCH") == nil { t.Errorf("AbilityByName: returned nil item") } else { if ver.AbilityByName("STENCH").Index() != 1 { t.Errorf("AbilityByName: expected index 1") } if ver.AbilityByName("Stench") == nil { t.Errorf("AbilityByName: not case-insensitive") } } if ver.AbilityByName("") != nil { t.Errorf("AbilityByName: expected nil") } if ver.AbilityByName(ver.AbilityByIndex(ver.AbilityIndexSize()-1).Name()) == nil { t.Errorf("AbilityByName: returned nil last species") } if len(ver.Moves()) != ver.MoveIndexSize() { t.Errorf("Moves: expected length %d, got %d", ver.MoveIndexSize(), len(ver.Moves())) } ExpectPanic(t, "MoveByIndex", func() { ver.MoveByIndex(-1) }) ExpectPanic(t, "MoveByIndex", func() { ver.MoveByIndex(ver.MoveIndexSize()) }) ExpectPanic(t, "MoveByIndex", func() { ver.MoveByIndex(ver.MoveIndexSize() + 1) }) for i := 0; i < ver.MoveIndexSize(); i++ { s := ver.MoveByIndex(i) if s.Index() != i { t.Errorf("MoveByIndex: returned index %d, expected %d", s.Index(), i) break } } if ver.MoveByName("POUND") == nil { t.Errorf("MoveByName: returned nil item") } else { if ver.MoveByName("POUND").Index() != 1 { t.Errorf("MoveByName: expected index 1") } if ver.MoveByName("Pound") == nil { t.Errorf("MoveByName: not case-insensitive") } } if ver.MoveByName("") != nil { t.Errorf("MoveByName: expected nil") } if ver.MoveByName(ver.MoveByIndex(ver.MoveIndexSize()-1).Name()) == nil { t.Errorf("MoveByName: returned nil last species") } if len(ver.TMs()) != ver.TMIndexSize() { t.Errorf("TMs: expected length %d, got %d", ver.TMIndexSize(), len(ver.TMs())) } ExpectPanic(t, "TMByIndex", func() { ver.TMByIndex(-1) }) ExpectPanic(t, "TMByIndex", func() { ver.TMByIndex(ver.TMIndexSize()) }) ExpectPanic(t, "TMByIndex", func() { ver.TMByIndex(ver.TMIndexSize() + 1) }) for i := 0; i < ver.TMIndexSize(); i++ { s := ver.TMByIndex(i) if s.Index() != i { t.Errorf("TMByIndex: returned index %d, expected %d", s.Index(), i) break } } if ver.TMByName("TM01") == nil { t.Errorf("TMByName: returned nil item") } else { if ver.TMByName("TM01").Index() != 0 { t.Errorf("TMByName: expected index 1") } if ver.TMByName("tm01") == nil { t.Errorf("TMByName: not case-insensitive") } } if ver.TMByName("") != nil { t.Errorf("TMByName: expected nil") } if ver.TMByName("AAAA") != nil { t.Errorf("TMByName: expected nil") } if ver.TMByName("MM01") != nil { t.Errorf("TMByName: expected nil") } if ver.TMByName("TM99") != nil { t.Errorf("TMByName: expected nil") } if ver.TMByName("AAAAA") != nil { t.Errorf("TMByName: expected nil") } if ver.TMByName(ver.TMByIndex(ver.TMIndexSize()-1).Name()) == nil { t.Errorf("TMByName: returned nil last species") } ExpectPanic(t, "BankIndexSize", func() { ver.BankIndexSize() }) ExpectPanic(t, "Banks", func() { ver.Banks() }) ExpectPanic(t, "BankByIndex", func() { ver.BankByIndex(0) }) ExpectPanic(t, "AllMaps", func() { ver.AllMaps() }) ExpectPanic(t, "MapByName", func() { ver.MapByName("") }) ver.ScanBanks() ExpectPanic(t, "BankByIndex", func() { ver.BankByIndex(257) }) if v := ver.BankIndexSize(); v != 34 { t.Errorf("BankIndexSize: unexpected result %d", v) } if v := ver.Banks(); len(v) != 34 { t.Errorf("Banks: unexpected result length %d", len(v)) } if v := ver.BankByIndex(0); v == nil || v.Index() != 0 { t.Errorf("BankByIndex: unexpected result %d", v.Index) } if v := ver.AllMaps(); len(v) != 518 { t.Errorf("AllMaps: unexpected result length %d", v) } if m := ver.MapByName("RUSTURF TUNNEL"); m == nil { t.Errorf("MapByName: unexpected result <nil>") } else if m.BankIndex() != 24 || m.Index() != 4 { t.Errorf("MapByName: unexpected result %d.%d (%s)", m.BankIndex(), m.Index(), m.Name()) } else { if v := ver.MapByName("Rusturf Tunnel"); v != m { t.Errorf("MapByName: not case-insensitive") } } if v := ver.MapByName("unknown"); v != nil { t.Errorf("MapByName: expected nil result") t.Logf("Result: %d.%d", v.BankIndex(), v.Index()) } }
func TestSpecies(t *testing.T) { ver := gen3.OpenROM(ROM(t)) if ver == nil { t.Fatalf("failed to open ROM") } species := ver.SpeciesByIndex(1) if v := species.Index(); v != 1 { t.Errorf("Index: unexpected result %d", v) } if v := species.Name(); v != "BULBASAUR" { t.Errorf("Name: unexpected result \"%s\"", v) } if v := species.Description(); v != "BULBASAUR can be seen napping in bright\nsunlight. There is a seed on its back.\nBy soaking up the sun’s rays, the seed\ngrows progressively larger." { t.Errorf("Description: unexpected result \"%s\"", v) } if v := species.Category(); v != "SEED" { t.Errorf("Category: unexpected result \"%s\"", v) } if v := species.Height(); v != 7 { t.Errorf("Height: unexpected result %d", v) } if v := species.Weight(); v != 69 { t.Errorf("Weight: unexpected result %d", v) } if v := species.BaseStats(); v != (pkm.Stats{45, 49, 49, 45, 65, 65}) { t.Errorf("BaseStats: unexpected result %#v", v) } if v := species.Type(); v != [2]pkm.Type{pkm.TypeGrass, pkm.TypePoison} { t.Errorf("Type: unexpected result %#v", v) } if v := species.CatchRate(); v != 45 { t.Errorf("CatchRate: unexpected result %d", v) } if v := species.ExpYield(); v != 64 { t.Errorf("ExpYield: unexpected result %d", v) } if v := species.EffortPoints(); v != 256 { t.Errorf("EffortPoints: unexpected result %d", v) } if v := species.HeldItem(); v != [2]pkm.Item{ver.ItemByIndex(0), ver.ItemByIndex(0)} { t.Errorf("HeldItem: unexpected result %#v", v) } if v := species.GenderRatio(); v != 31 { t.Errorf("GenderRatio: unexpected result %d", v) } if v := species.EggCycles(); v != 20 { t.Errorf("EggCycles: unexpected result %d", v) } if v := species.BaseFriendship(); v != 70 { t.Errorf("BaseFriendship: unexpected result %d", v) } if v := species.LevelType(); v != 3 { t.Errorf("LevelType: unexpected result %d", v) } if v := species.EggGroup(); v != [2]pkm.EggGroup{pkm.EggMonster, pkm.EggGrass} { t.Errorf("EggGroup: unexpected result %#v", v) } if v := species.Ability(); v != [2]pkm.Ability{ver.AbilityByIndex(65), ver.AbilityByIndex(0)} { t.Errorf("Ability: unexpected result %#v", v) } if v := species.SafariRate(); v != 0 { t.Errorf("SafariRate: unexpected result %d", v) } if v := species.Color(); v != pkm.ColorGreen { t.Errorf("Color: unexpected result %s", v) } { moves := []pkm.LevelMove{ {Level: 1, Move: ver.MoveByName("TACKLE")}, {Level: 4, Move: ver.MoveByName("GROWL")}, {Level: 7, Move: ver.MoveByName("LEECH SEED")}, {Level: 10, Move: ver.MoveByName("VINE WHIP")}, {Level: 15, Move: ver.MoveByName("POISONPOWDER")}, {Level: 15, Move: ver.MoveByName("SLEEP POWDER")}, {Level: 20, Move: ver.MoveByName("RAZOR LEAF")}, {Level: 25, Move: ver.MoveByName("SWEET SCENT")}, {Level: 32, Move: ver.MoveByName("GROWTH")}, {Level: 39, Move: ver.MoveByName("SYNTHESIS")}, {Level: 46, Move: ver.MoveByName("SOLARBEAM")}, } v := species.LearnedMoves() if len(v) != len(moves) { t.Errorf("LearnedMoves: unexpected result length %d", len(v)) } else { for i, m := range v { if m.Level != moves[i].Level { t.Errorf("LearnedMoves: %d unexpected level %d", i, m.Level) } if m.Move != moves[i].Move { t.Errorf("LearnedMoves: %d unexpected move %d (%s)", i, m.Move.Index(), m.Move.Name()) } } } } if v := species.CanLearnTM(ver.TMByIndex(1)); v { t.Errorf("CanLearnTM: unexpected result: %t", v) } if v := species.CanLearnTM(ver.TMByIndex(5)); !v { t.Errorf("CanLearnTM: unexpected result: %t", v) } { tms := []bool{ 0: false, 1: false, 2: false, 3: false, 4: false, 5: true, 6: false, 7: false, 8: true, 9: true, 10: true, 11: false, 12: false, 13: false, 14: false, 15: false, 16: true, 17: false, 18: true, 19: false, 20: true, 21: true, 22: false, 23: false, 24: false, 25: false, 26: true, 27: false, 28: false, 29: false, 30: false, 31: true, 32: false, 33: false, 34: false, 35: true, 36: false, 37: false, 38: false, 39: false, 40: false, 41: true, 42: true, 43: true, 44: true, 45: false, 46: false, 47: false, 48: false, 49: false, 50: true, 51: false, 52: false, 53: true, 54: true, 55: true, 56: false, 57: false, } for _, tm := range species.LearnableTMs() { if !tms[tm.Index()] { t.Errorf("LearnableTMs: unexpected result %d (%s)", tm.Index(), tm.Name()) } } } if evos := species.Evolutions(); len(evos) != 1 { t.Errorf("Evolutions: unexpected result length %d", len(evos)) } else { if v := evos[0].Target(); v.Index() != 2 { t.Errorf("Evolutions: unexpected target %d (%s)", v.Index(), v.Name()) } if v := evos[0].Method(); v != 4 { t.Errorf("Evolutions: unexpected method %d", v) } if v := evos[0].Param(); v != 16 { t.Errorf("Evolutions: unexpected param %d", v) } } species = ver.SpeciesByIndex(133) if evos := species.Evolutions(); len(evos) != 5 { t.Errorf("Evolutions: unexpected result length %d", len(evos)) } else { target := [5]int{135, 134, 136, 196, 197} method := [5]uint16{7, 7, 7, 2, 3} param := [5]uint16{96, 97, 95, 0, 0} for i, evo := range evos { if v := evo.Target(); v.Index() != target[i] { t.Errorf("Evolutions: %d: unexpected target %d (%s)", i, v.Index(), v.Name()) } if v := evo.Method(); v != method[i] { t.Errorf("Evolutions: %d: unexpected method %d", i, v) } if v := evo.Param(); v != param[i] { t.Errorf("Evolutions: %d: unexpected param %d", i, v) } } } if species, ok := species.(gen3.Species); ok { if v := species.Flipped(); v { t.Errorf("Flipped: unexpected result %t", v) } } }