mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-29 23:40:27 +00:00
Add more test cases, case insensitive parse
This commit is contained in:
parent
5e3b390fe1
commit
53dbdf62f7
2 changed files with 24 additions and 6 deletions
|
@ -31,20 +31,34 @@ namespace PKHeX.Core
|
|||
|
||||
public static IEnumerable<IEncounterable> GetLearn(string species, IEnumerable<string> moves, string lang = DefaultLang)
|
||||
{
|
||||
if (!Enum.TryParse<Species>(species, out var spec))
|
||||
return Enumerable.Empty<IEncounterable>();
|
||||
var str = GameInfo.GetStrings(lang);
|
||||
if (str == null)
|
||||
return Enumerable.Empty<IEncounterable>();
|
||||
var movestr = str.movelist;
|
||||
var moveIDs = moves.Select(z => Array.IndexOf(movestr, z)).Where(z => z > 0).ToArray();
|
||||
|
||||
var spec = FindIndexIgnoreCase(str.specieslist, species);
|
||||
if (spec <= 0)
|
||||
return Enumerable.Empty<IEncounterable>();
|
||||
|
||||
var moveIDs = moves.Select(z => FindIndexIgnoreCase(str.movelist, z)).Where(z => z > 0).ToArray();
|
||||
|
||||
return GetLearn(spec, moveIDs);
|
||||
}
|
||||
|
||||
public static IEnumerable<IEncounterable> GetLearn(int spec, int[] moveIDs)
|
||||
{
|
||||
var blank = PKMConverter.GetBlank(PKX.Generation);
|
||||
blank.Species = spec;
|
||||
|
||||
var vers = GameUtil.GameVersions;
|
||||
var blank = PKMConverter.GetBlank(PKX.Generation);
|
||||
blank.Species = (int)spec;
|
||||
return EncounterMovesetGenerator.GenerateEncounters(blank, moveIDs, vers);
|
||||
}
|
||||
|
||||
private static int FindIndexIgnoreCase(string[] arr, string val)
|
||||
{
|
||||
bool Match(string item, string find) => item.Length == find.Length && item.IndexOf(find, StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
return Array.FindIndex(arr, i => Match(i, val));
|
||||
}
|
||||
|
||||
public static IEnumerable<string> Summarize(IEnumerable<IEncounterable> encounters)
|
||||
{
|
||||
var types = encounters.GroupBy(z => z.Name);
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace PKHeX.Tests.Legality
|
|||
[InlineData(nameof(Species.Bulbasaur), "Fly")]
|
||||
[InlineData(nameof(Species.Charizard), "Bubble")]
|
||||
[InlineData(nameof(Species.Mew), "Struggle")]
|
||||
[InlineData(nameof(Species.Smeargle), "Chatter")]
|
||||
public static void VerifyCannotLearn(string species, params string[] moves)
|
||||
{
|
||||
var encs = EncounterLearn.GetLearn(species, moves);
|
||||
|
@ -30,6 +31,9 @@ namespace PKHeX.Tests.Legality
|
|||
|
||||
[Theory]
|
||||
[InlineData(nameof(Species.Chansey), "Wish")]
|
||||
[InlineData("Ho-Oh", "Celebrate")]
|
||||
[InlineData(nameof(Species.Pikachu), "Happy Hour")]
|
||||
[InlineData(nameof(Species.Rayquaza), "V-Create")]
|
||||
public static void VerifyCanLearnSpecial(string species, params string[] moves)
|
||||
{
|
||||
var encs = EncounterLearn.GetLearn(species, moves);
|
||||
|
|
Loading…
Reference in a new issue