Files
RobustToolbox/Robust.UnitTesting/Shared/Toolshed/ArithmeticTest.cs
T
909fd326a0 Toolshed part 2 (#4256)
* Save work.

* three billion tweaks

* Rune-aware parser.

* a

* all shedded out for the night

* a

* oogh

* Publicizes a lot of common generic commands, so custom toolshed envs can include them.

* Implement parsing for all number types.

* i think i might implode

* a

* Tests.

* a

* Enum parser test.

* do u like parsers

* oopls

* ug fixes

* Toolshed is approaching a non-insignificant part of the engine's size.

* Pool toolshed's tests, also type tests.

* bwa

* tests pass :yay:

* Update Robust.Shared/CVars.cs

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>

* how did this not fail tests

* awa

* many levels of silly

---------

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
2023-08-23 16:03:34 -05:00

72 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Numerics;
using System.Threading.Tasks;
using NUnit.Framework;
using Is = NUnit.Framework.Is;
namespace Robust.UnitTesting.Shared.Toolshed;
[TestFixture]
public sealed class ArithmeticTest : ToolshedTest
{
[Test]
public async Task OrderOfOperations()
{
await Server.WaitAssertion(() =>
{
// Toolshed always parses left-to-right with no precedence.
Assert.That(1.0f / 3.0f, Is.EqualTo(InvokeCommand<float>("f 1 / 3")));
Assert.That((1.0f + 1.0f) / 3.0f, Is.EqualTo(InvokeCommand<float>("f 1 + 1 / 3")));
Assert.That(float.Pow(2.0f + 2.0f, 3.0f), Is.EqualTo(InvokeCommand<float>("f 2 + 2 pow 3")));
});
}
[Test]
public async Task EveryNumericTypeOperateable()
{
await Server.WaitAssertion(() =>
{
InvokeCommand<byte, byte>("+ 1", 1);
InvokeCommand<sbyte, sbyte>("+ 1", 1);
InvokeCommand<short, short>("+ 1", 1);
InvokeCommand<ushort, ushort>("+ 1", 1);
InvokeCommand<int, int>("+ 1", 1);
InvokeCommand<uint, uint>("+ 1", 1);
InvokeCommand<long, long>("+ 1", 1);
InvokeCommand<ulong, ulong>("+ 1", 1);
InvokeCommand<nint, nint>("+ 1", 1);
InvokeCommand<nuint, nuint>("+ 1", 1);
InvokeCommand<float, float>("+ 1", 1);
InvokeCommand<double, double>("+ 1", 1);
InvokeCommand<BigInteger, BigInteger>("+ 1", 1);
InvokeCommand<decimal, decimal>("+ 1", 1);
InvokeCommand<Half, Half>("+ 1", Half.CreateTruncating(1)); // Can't use a constant for this one.
});
}
[Test]
public async Task NoOverflowException()
{
await Server.WaitAssertion(() =>
{
InvokeCommand<byte, byte>("+ 1", byte.MaxValue);
});
}
[Test]
public async Task Iterations()
{
await Server.WaitAssertion(() =>
{
var list = new List<float>();
for (var i = 0; i < 100; i++)
{
list.Add(i + 1);
}
Assert.That(list, Is.EquivalentTo(InvokeCommand<IEnumerable<float>>("f 0 iterate + 1 100")));
});
}
}