Style cleanup
This commit is contained in:
@@ -10,12 +10,9 @@ public class MoveDataTests
|
||||
public record TestCaseData(IDynamicLibrary Library, IMoveData Move)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return Move.Name + " has valid scripts";
|
||||
}
|
||||
public override string ToString() => Move.Name + " has valid scripts";
|
||||
}
|
||||
|
||||
|
||||
public static IEnumerable<TestCaseData> AllMovesHaveValidScriptsData()
|
||||
{
|
||||
var library = LibraryHelpers.LoadLibrary();
|
||||
@@ -27,9 +24,8 @@ public class MoveDataTests
|
||||
yield return new TestCaseData(library, move);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[MethodDataSource(nameof(AllMovesHaveValidScriptsData))]
|
||||
|
||||
[Test, MethodDataSource(nameof(AllMovesHaveValidScriptsData))]
|
||||
public async Task AllMoveEffectsHaveValidScripts(TestCaseData test)
|
||||
{
|
||||
if (test.Move.SecondaryEffect == null)
|
||||
@@ -43,7 +39,8 @@ public class MoveDataTests
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new AggregateException($"Failed to resolve script for move {test.Move.Name} with effect {scriptName}", e);
|
||||
throw new AggregateException($"Failed to resolve script for move {test.Move.Name} with effect {scriptName}",
|
||||
e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public class SpeciesDataloaderTests
|
||||
typeLibrary.RegisterType("Dark");
|
||||
typeLibrary.RegisterType("Steel");
|
||||
typeLibrary.RegisterType("Fairy");
|
||||
|
||||
|
||||
var library = SpeciesDataLoader.LoadSpecies(file, typeLibrary);
|
||||
await Assert.That(library).IsNotNull();
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ public class TypeDataloaderTests
|
||||
await using var file = File.Open("Data/Types.csv", FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
var library = TypeDataLoader.LoadTypeLibrary(file);
|
||||
await Assert.That(library).IsNotNull();
|
||||
|
||||
|
||||
var fire = library.TryGetTypeIdentifier("Fire", out var fireId);
|
||||
await Assert.That(fire).IsTrue();
|
||||
var grass = library.TryGetTypeIdentifier("Grass", out var grassId);
|
||||
await Assert.That(grass).IsTrue();
|
||||
|
||||
|
||||
var fireEffectiveness = library.GetSingleEffectiveness(fireId, grassId);
|
||||
await Assert.That(fireEffectiveness).IsEqualTo(2.0f);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
global using TUnit;
|
||||
global using FluentAssertions;
|
||||
|
||||
global using LevelInt = byte;
|
||||
@@ -26,8 +26,7 @@ public class IntegrationTestRunner
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[MethodDataSource(nameof(TestCases))]
|
||||
[Test, MethodDataSource(nameof(TestCases))]
|
||||
public async Task RunIntegrationTest(IntegrationTestModel test)
|
||||
{
|
||||
var library = LibraryHelpers.LoadLibrary();
|
||||
@@ -40,11 +39,10 @@ public class IntegrationTestRunner
|
||||
var pokemon = x.Pokemon[index];
|
||||
await Assert.That(library.StaticLibrary.Species.TryGet(pokemon.Species, out var species)).IsTrue();
|
||||
var mon = new PokemonImpl(library, species!, species!.GetDefaultForm(), new AbilityIndex
|
||||
{
|
||||
IsHidden = false,
|
||||
Index = 0,
|
||||
},
|
||||
pokemon.Level, 0, Gender.Genderless, 0, "hardy");
|
||||
{
|
||||
IsHidden = false,
|
||||
Index = 0,
|
||||
}, pokemon.Level, 0, Gender.Genderless, 0, "hardy");
|
||||
foreach (var move in pokemon.Moves)
|
||||
{
|
||||
mon.LearnMove(move, MoveLearnMethod.Unknown, 255);
|
||||
@@ -56,7 +54,7 @@ public class IntegrationTestRunner
|
||||
return new BattlePartyImpl(party, x.Indices.Select(y => new ResponsibleIndex(y[0], y[1])).ToArray());
|
||||
}).ProcessOneAtATime().GetResultsAsync();
|
||||
var battle = new BattleImpl(library, parties, test.BattleSetup.CanFlee, test.BattleSetup.NumberOfSides,
|
||||
test.BattleSetup.PositionsPerSide, randomSeed: test.BattleSetup.Seed);
|
||||
test.BattleSetup.PositionsPerSide, test.BattleSetup.Seed);
|
||||
|
||||
foreach (var action in test.Actions)
|
||||
{
|
||||
|
||||
@@ -37,5 +37,5 @@ public static class LibraryHelpers
|
||||
}),
|
||||
]);
|
||||
return dynamicLibrary;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,8 @@ using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||
|
||||
namespace PkmnLib.Tests.Integration.Models;
|
||||
|
||||
|
||||
[JsonDerivedType(typeof(SetPokemonAction), "setPokemon")]
|
||||
[JsonDerivedType(typeof(SetMoveChoiceAction), "setMoveChoice")]
|
||||
[JsonDerivedType(typeof(SetPassChoiceAction), "setPassChoice")]
|
||||
[JsonDerivedType(typeof(AssertAction), "assert")]
|
||||
[JsonDerivedType(typeof(SetPokemonAction), "setPokemon"), JsonDerivedType(typeof(SetMoveChoiceAction), "setMoveChoice"),
|
||||
JsonDerivedType(typeof(SetPassChoiceAction), "setPassChoice"), JsonDerivedType(typeof(AssertAction), "assert")]
|
||||
public abstract class IntegrationTestAction
|
||||
{
|
||||
public abstract Task Execute(IBattle battle);
|
||||
@@ -36,7 +33,6 @@ public class SetMoveChoiceAction : IntegrationTestAction
|
||||
public string Move { get; set; } = null!;
|
||||
public List<byte> Target { get; set; } = null!;
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task Execute(IBattle battle)
|
||||
{
|
||||
@@ -73,7 +69,7 @@ public class AssertAction : IntegrationTestAction
|
||||
{
|
||||
var list = battle.Path(Value).ToList();
|
||||
var value = list.Count == 1 ? list[0] : list;
|
||||
|
||||
|
||||
var serialized = JsonSerializer.Serialize(value);
|
||||
await Assert.That(serialized).IsEqualTo(Expected.ToJsonString());
|
||||
}
|
||||
|
||||
@@ -8,10 +8,7 @@ public class IntegrationTestModel
|
||||
public IntegrationTestAction[] Actions { get; set; } = null!;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
public class IntegrationTestBattleSetup
|
||||
|
||||
@@ -11,8 +11,7 @@ namespace PkmnLib.Tests.Static;
|
||||
|
||||
public class DeepCloneTests
|
||||
{
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||
[SuppressMessage("ReSharper", "ValueParameterNotUsed")]
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Local"), SuppressMessage("ReSharper", "ValueParameterNotUsed")]
|
||||
private class TestClass : IDeepCloneable
|
||||
{
|
||||
public int Value { get; set; }
|
||||
@@ -70,8 +69,7 @@ public class DeepCloneTests
|
||||
var clone = obj.DeepClone();
|
||||
await Assert.That(clone).IsNotEqualTo(obj);
|
||||
var clonePrivateField =
|
||||
clone.GetType().GetField("_privateField", BindingFlags.NonPublic | BindingFlags.Instance)!
|
||||
.GetValue(clone);
|
||||
clone.GetType().GetField("_privateField", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(clone);
|
||||
await Assert.That(clonePrivateField).IsEqualTo(1);
|
||||
}
|
||||
|
||||
@@ -93,28 +91,24 @@ public class DeepCloneTests
|
||||
await Assert.That(library.StaticLibrary.Species.TryGet("bulbasaur", out var bulbasaur)).IsTrue();
|
||||
await Assert.That(library.StaticLibrary.Species.TryGet("charmander", out var charmander)).IsTrue();
|
||||
var party1 = new PokemonParty(6);
|
||||
party1.SwapInto(new PokemonImpl(library, bulbasaur!,
|
||||
bulbasaur!.GetDefaultForm(), new AbilityIndex
|
||||
{
|
||||
IsHidden = false,
|
||||
Index = 0,
|
||||
}, 50, 0,
|
||||
Gender.Male, 0, "hardy"), 0);
|
||||
party1.SwapInto(new PokemonImpl(library, bulbasaur!, bulbasaur!.GetDefaultForm(), new AbilityIndex
|
||||
{
|
||||
IsHidden = false,
|
||||
Index = 0,
|
||||
}, 50, 0, Gender.Male, 0, "hardy"), 0);
|
||||
var party2 = new PokemonParty(6);
|
||||
party2.SwapInto(new PokemonImpl(library, charmander!,
|
||||
charmander!.GetDefaultForm(), new AbilityIndex
|
||||
{
|
||||
IsHidden = false,
|
||||
Index = 0,
|
||||
}, 50, 0,
|
||||
Gender.Male, 0, "hardy"), 0);
|
||||
party2.SwapInto(new PokemonImpl(library, charmander!, charmander!.GetDefaultForm(), new AbilityIndex
|
||||
{
|
||||
IsHidden = false,
|
||||
Index = 0,
|
||||
}, 50, 0, Gender.Male, 0, "hardy"), 0);
|
||||
|
||||
var parties = new[]
|
||||
{
|
||||
new BattlePartyImpl(party1, [new ResponsibleIndex(0, 0)]),
|
||||
new BattlePartyImpl(party2, [new ResponsibleIndex(1, 0)]),
|
||||
};
|
||||
var battle = new BattleImpl(library, parties, false, 2, 3, randomSeed: 0);
|
||||
var battle = new BattleImpl(library, parties, false, 2, 3, 0);
|
||||
battle.Sides[0].SwapPokemon(0, party1[0]);
|
||||
battle.Sides[1].SwapPokemon(0, party2[0]);
|
||||
party1[0]!.ChangeStatBoost(Statistic.Defense, 2, true);
|
||||
|
||||
@@ -10,21 +10,23 @@ public class GrowthRateTests
|
||||
Action act = () => _ = new LookupGrowthRate("Test", []);
|
||||
act.Should().Throw<ArgumentException>().WithMessage("Experience table must have at least one entry.");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void NonZeroLookupGrowthRateTestShouldThrowArgumentException()
|
||||
{
|
||||
Action act = () => _ = new LookupGrowthRate("Test", [1]);
|
||||
act.Should().Throw<ArgumentException>().WithMessage("Experience table must start at 0.");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TooLargeLookupGrowthRateTestShouldThrowArgumentException()
|
||||
{
|
||||
Action act = () => _ = new LookupGrowthRate("Test", Enumerable.Range(0, LevelInt.MaxValue + 1).Select(i => (uint)i));
|
||||
act.Should().Throw<ArgumentException>().WithMessage($"Experience table may have at most {LevelInt.MaxValue} entries.");
|
||||
Action act = () =>
|
||||
_ = new LookupGrowthRate("Test", Enumerable.Range(0, LevelInt.MaxValue + 1).Select(i => (uint)i));
|
||||
act.Should().Throw<ArgumentException>()
|
||||
.WithMessage($"Experience table may have at most {LevelInt.MaxValue} entries.");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void LookupGrowthRateTest()
|
||||
{
|
||||
@@ -35,7 +37,7 @@ public class GrowthRateTests
|
||||
growthRate.CalculateLevel(3).Should().Be(4);
|
||||
growthRate.CalculateLevel(4).Should().Be(5);
|
||||
growthRate.CalculateLevel(5).Should().Be(6);
|
||||
|
||||
|
||||
growthRate.CalculateExperience(1).Should().Be(0);
|
||||
growthRate.CalculateExperience(2).Should().Be(1);
|
||||
growthRate.CalculateExperience(3).Should().Be(2);
|
||||
|
||||
@@ -15,8 +15,7 @@ public class StringKeyTests
|
||||
yield return () => ("TeSt", "tesv", false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[MethodDataSource(nameof(StringKeyEqualityTestCases))]
|
||||
[Test, MethodDataSource(nameof(StringKeyEqualityTestCases))]
|
||||
public async Task StringKeyEqualityTest(string k1, string k2, bool expected)
|
||||
{
|
||||
var sk1 = new StringKey(k1);
|
||||
@@ -24,8 +23,7 @@ public class StringKeyTests
|
||||
await Assert.That(sk1 == sk2).IsEqualTo(expected);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[MethodDataSource(nameof(StringKeyEqualityTestCases))]
|
||||
[Test, MethodDataSource(nameof(StringKeyEqualityTestCases))]
|
||||
public async Task HashCodeEqualityTest(string k1, string k2, bool expected)
|
||||
{
|
||||
var sk1 = new StringKey(k1);
|
||||
@@ -33,8 +31,7 @@ public class StringKeyTests
|
||||
await Assert.That(sk1.GetHashCode() == sk2.GetHashCode()).IsEqualTo(expected);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[MethodDataSource(nameof(StringKeyEqualityTestCases))]
|
||||
[Test, MethodDataSource(nameof(StringKeyEqualityTestCases))]
|
||||
public async Task HashSetEqualityTest(string k1, string k2, bool expected)
|
||||
{
|
||||
var sk1 = new StringKey(k1);
|
||||
|
||||
Reference in New Issue
Block a user