Initial commit
This commit is contained in:
4
PkmnLib.Tests/GlobalUsings.cs
Normal file
4
PkmnLib.Tests/GlobalUsings.cs
Normal file
@@ -0,0 +1,4 @@
|
||||
global using NUnit.Framework;
|
||||
global using FluentAssertions;
|
||||
|
||||
global using LevelInt = byte;
|
||||
25
PkmnLib.Tests/PkmnLib.Tests.csproj
Normal file
25
PkmnLib.Tests/PkmnLib.Tests.csproj
Normal file
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
|
||||
<PackageReference Include="NUnit" Version="3.13.3"/>
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1"/>
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1"/>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PkmnLib.Static\PkmnLib.Static.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
46
PkmnLib.Tests/Static/GrowthRateTests.cs
Normal file
46
PkmnLib.Tests/Static/GrowthRateTests.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using PkmnLib.Static;
|
||||
|
||||
namespace PkmnLib.Tests.Static;
|
||||
|
||||
public class GrowthRateTests
|
||||
{
|
||||
[Test]
|
||||
public void EmptyLookupGrowthRateTestShouldThrowArgumentException()
|
||||
{
|
||||
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.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LookupGrowthRateTest()
|
||||
{
|
||||
var growthRate = new LookupGrowthRate("Test", [0, 1, 2, 3, 4, 5]);
|
||||
growthRate.CalculateLevel(0).Should().Be(1);
|
||||
growthRate.CalculateLevel(1).Should().Be(2);
|
||||
growthRate.CalculateLevel(2).Should().Be(3);
|
||||
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);
|
||||
growthRate.CalculateExperience(4).Should().Be(3);
|
||||
growthRate.CalculateExperience(5).Should().Be(4);
|
||||
growthRate.CalculateExperience(6).Should().Be(5);
|
||||
}
|
||||
}
|
||||
48
PkmnLib.Tests/Static/StringKeyTests.cs
Normal file
48
PkmnLib.Tests/Static/StringKeyTests.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Tests.Static;
|
||||
|
||||
public class StringKeyTests
|
||||
{
|
||||
private static IEnumerable StringKeyEqualityTestCases
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new TestCaseData("test", "test").Returns(true);
|
||||
yield return new TestCaseData("test", "test2").Returns(false);
|
||||
yield return new TestCaseData("test2", "test2").Returns(true);
|
||||
yield return new TestCaseData("Test", "test").Returns(true);
|
||||
yield return new TestCaseData("TeSt", "tesT").Returns(true);
|
||||
yield return new TestCaseData("TeSt", "tesv").Returns(false);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCaseSource(nameof(StringKeyEqualityTestCases))]
|
||||
public bool StringKeyEqualityTest(string k1, string k2)
|
||||
{
|
||||
var sk1 = new StringKey(k1);
|
||||
var sk2 = new StringKey(k2);
|
||||
return sk1 == sk2;
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCaseSource(nameof(StringKeyEqualityTestCases))]
|
||||
public bool HashCodeEqualityTest(string k1, string k2)
|
||||
{
|
||||
var sk1 = new StringKey(k1);
|
||||
var sk2 = new StringKey(k2);
|
||||
return sk1.GetHashCode() == sk2.GetHashCode();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCaseSource(nameof(StringKeyEqualityTestCases))]
|
||||
public bool HashSetEqualityTest(string k1, string k2)
|
||||
{
|
||||
var sk1 = new StringKey(k1);
|
||||
var sk2 = new StringKey(k2);
|
||||
var hs = new HashSet<StringKey> { sk1 };
|
||||
return hs.Contains(sk2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user