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