Skip to content

Commit

Permalink
Additional VM tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhett12321 committed Dec 4, 2024
1 parent caa4077 commit 991aac2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
9 changes: 9 additions & 0 deletions NWNX.NET.Tests/src/main/Constants/VMFunctions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NWNX.NET.Tests.Constants;

public static class VMFunctions
{
public const int SubString = 65;
public const int fabs = 67;
public const int abs = 77;
public const int GetModuleName = 561;
}
47 changes: 46 additions & 1 deletion NWNX.NET.Tests/src/main/Tests/VMTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using NWNX.NET.Tests.Constants;

namespace NWNX.NET.Tests
{
Expand All @@ -8,10 +9,54 @@ public sealed class VMTests
[Test]
public void GetModuleNameTest()
{
NWNXAPI.CallBuiltIn(561);
NWNXAPI.CallBuiltIn(VMFunctions.GetModuleName);
string? modName = NWNXAPI.StackPopString();

Assert.That(modName, Is.EqualTo("demo"));
}

[Test]
[TestCase(1, 1)]
[TestCase(0, 0)]
[TestCase(-1, 1)]
[TestCase(-int.MaxValue, int.MaxValue)]
public void AbsTest(int value, int expectedValue)
{
NWNXAPI.StackPushInteger(value);
NWNXAPI.CallBuiltIn(VMFunctions.abs);
int result = NWNXAPI.StackPopInteger();

Assert.That(result, Is.EqualTo(expectedValue));
}

[Test]
[TestCase(1f, 1f)]
[TestCase(0f, 0f)]
[TestCase(-1f, 1f)]
[TestCase(-float.MaxValue, float.MaxValue)]
public void FAbsTest(float value, float expectedValue)
{
NWNXAPI.StackPushFloat(value);
NWNXAPI.CallBuiltIn(VMFunctions.fabs);
float result = NWNXAPI.StackPopFloat();

Assert.That(result, Is.EqualTo(expectedValue));
}

[Test]
[TestCase("example_string", 0, 7, "example")]
[TestCase("test_string", 5, 6, "string")]
[TestCase("", 0, 0, "")]
[TestCase(null, 0, 5, "")]
public void SubStringTest(string str, int start, int count, string expectedValue)
{
NWNXAPI.StackPushInteger(count);
NWNXAPI.StackPushInteger(start);
NWNXAPI.StackPushString(str);
NWNXAPI.CallBuiltIn(VMFunctions.SubString);

string? result = NWNXAPI.StackPopString();
Assert.That(result, Is.EqualTo(expectedValue));
}
}
}

0 comments on commit 991aac2

Please sign in to comment.