PkmnLibSharp/PkmnLibSharpTests/Library/EffectParameterTests.cs

61 lines
1.9 KiB
C#
Raw Normal View History

2021-11-27 10:27:19 +00:00
using System.Linq;
2020-05-02 20:58:08 +00:00
using NUnit.Framework;
using PkmnLibSharp.Library;
2020-05-04 15:54:34 +00:00
using PkmnLibSharp.Utilities;
2020-05-02 20:58:08 +00:00
namespace PkmnLibSharpTests.Library
{
public class EffectParameterTests
{
[Test]
public void CreateInt([Range(-10000000, 10000000, 1000000)] long value)
{
var p = new EffectParameter(value);
Assert.AreEqual(EffectParameterType.Int, p.ParameterType);
Assert.AreEqual(value, p.AsInt());
p.Dispose();
}
[Test]
public void CreateBool()
{
var p = new EffectParameter(true);
Assert.AreEqual(EffectParameterType.Bool, p.ParameterType);
Assert.AreEqual(true, p.AsBool());
p.Dispose();
p = new EffectParameter(false);
Assert.AreEqual(EffectParameterType.Bool, p.ParameterType);
Assert.AreEqual(false, p.AsBool());
p.Dispose();
}
[Test]
public void CreateFloat([Range(-5, 5, 0.25f)] float value)
{
var p = new EffectParameter(value);
Assert.AreEqual(EffectParameterType.Float, p.ParameterType);
Assert.AreEqual(value, p.AsFloat());
p.Dispose();
}
[Test]
public void CreateString()
{
var p = new EffectParameter("foobar");
Assert.AreEqual(EffectParameterType.String, p.ParameterType);
Assert.AreEqual("foobar", p.AsString());
p.Dispose();
}
[Test]
public void ThrowOnWrongType()
{
var p = new EffectParameter(10);
var ex = Assert.Throws<NativeException>(() => { p.AsString(); });
2021-11-27 10:27:19 +00:00
Assert.AreEqual(
"[CreatureLibLibrary] - '[CreatureLib_EffectParameter_AsString] [EffectParameter.hpp:53] \"Cast effect parameter to string, but was Int\"'",
ex.Message.Split('\n').First());
2020-05-02 20:58:08 +00:00
p.Dispose();
}
}
}