Growth Rate Library wrapper and tests

This commit is contained in:
Deukhoofd 2020-05-06 12:39:28 +02:00
parent 32d07be361
commit cc66729529
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 80 additions and 1 deletions

View File

@ -0,0 +1,37 @@
using PkmnLibSharp.Utilities;
namespace PkmnLibSharp.Library.GrowthRates
{
public class GrowthRateLibrary : PointerWrapper
{
public GrowthRateLibrary(ulong initialCapacity) : base(
Creatureliblibrary.Generated.GrowthRateLibrary.Construct(initialCapacity))
{
}
public byte CalculateLevel(string growthRateName, uint experience)
{
byte b = 0;
Creatureliblibrary.Generated.GrowthRateLibrary.CalculateLevel(ref b, Ptr, growthRateName.ToPtr(),
experience).Assert();
return b;
}
public uint CalculateExperience(string growthRateName, byte level)
{
uint i = 0;
Creatureliblibrary.Generated.GrowthRateLibrary.CalculateExperience(ref i, Ptr, growthRateName.ToPtr(),
level).Assert();
return i;
}
public void AddGrowthRate(string name, GrowthRate gr)
{
Creatureliblibrary.Generated.GrowthRateLibrary.AddGrowthRate(Ptr, name.ToPtr(), gr.Ptr).Assert();
}
protected override void DeletePtr()
{
Creatureliblibrary.Generated.GrowthRateLibrary.Destruct(Ptr);
}
}
}

View File

@ -30,7 +30,7 @@ namespace PkmnLibSharp.Utilities
Cached.TryAdd(ptr, weakRef);
}
internal static bool TryResolvePointer<T>(IntPtr p, out T result) where T : PointerWrapper
public static bool TryResolvePointer<T>(IntPtr p, out T result) where T : PointerWrapper
{
if (Cached.TryGetValue(p, out var val))
{

View File

@ -0,0 +1,42 @@
using NUnit.Framework;
using PkmnLibSharp.Library.GrowthRates;
namespace PkmnLibSharpTests.Library
{
public class GrowthRateLibraryTests
{
[Test]
public void ConstructDestruct()
{
var gr = new GrowthRateLibrary(0);
gr.Dispose();
}
[Test]
public void AddGrowthRate()
{
var gr = new GrowthRateLibrary(1);
gr.AddGrowthRate("foobar", new LookupGrowthRate(new uint[]{0,10,20,30,40,50}));
gr.Dispose();
}
[Test]
public void CalculateLevel()
{
var gr = new GrowthRateLibrary(1);
gr.AddGrowthRate("foobar", new LookupGrowthRate(new uint[]{0,10,20,30,40,50}));
Assert.AreEqual(5, gr.CalculateLevel("foobar", 40));
gr.Dispose();
}
[Test]
public void CalculateExperience()
{
var gr = new GrowthRateLibrary(1);
gr.AddGrowthRate("foobar", new LookupGrowthRate(new uint[]{0,10,20,30,40,50}));
Assert.AreEqual(40, gr.CalculateExperience("foobar", 5));
gr.Dispose();
}
}
}