Add Numeric For Loops

This commit is contained in:
2018-11-23 14:38:45 +01:00
parent 1928979b40
commit d2c14d213c
21 changed files with 256 additions and 22 deletions

View File

@@ -1,9 +1,7 @@
using System;
using System.Diagnostics;
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
namespace UpsilonTests.GeneralTests
{
public class BasicMathExpressions : TestClass
{

View File

@@ -0,0 +1,63 @@
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests.GeneralTests
{
public class ForLoopTests : TestClass
{
public ForLoopTests(StaticScriptFixture fix) : base(fix)
{
}
[Fact]
public void BasicNumericForLoopTest()
{
const string input = @"
a = 0
for i=0,5 do
a = a + i
end
return a
";
var script = new Script(input, BoundScope, StaticScope);
Assert.Empty(script.Diagnostics.Messages);
var result = script.Evaluate<long>();
Assert.Empty(script.Diagnostics.Messages);
Assert.Equal(15, result);
}
[Fact]
public void NumericForLoopWithDifferentStepTest()
{
const string input = @"
a = 0
for i=0,10,2 do
a = a + i
end
return a
";
var script = new Script(input, BoundScope, StaticScope);
Assert.Empty(script.Diagnostics.Messages);
var result = script.Evaluate<long>();
Assert.Empty(script.Diagnostics.Messages);
Assert.Equal(30, result);
}
[Fact]
public void NumericForLoopWithNegativeStepTest()
{
const string input = @"
a = 0
for i=5,0,-1 do
a = a + i
end
return a";
var script = new Script(input, BoundScope, StaticScope);
Assert.Empty(script.Diagnostics.Messages);
var result = script.Evaluate<long>();
Assert.Empty(script.Diagnostics.Messages);
Assert.Equal(15, result);
}
}
}

View File

@@ -1,9 +1,7 @@
using Upsilon.BaseTypes;
using Upsilon.BaseTypes.Number;
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
namespace UpsilonTests.GeneralTests
{
public class FunctionTests : TestClass
{

View File

@@ -1,9 +1,7 @@
using Upsilon.BaseTypes;
using Upsilon.BaseTypes.Number;
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
namespace UpsilonTests.GeneralTests
{
public class IfTests : TestClass
{

View File

@@ -1,9 +1,7 @@
using Upsilon.BaseTypes.Number;
using Upsilon.Evaluator;
using Upsilon.Parser;
using Xunit;
namespace UpsilonTests
namespace UpsilonTests.GeneralTests
{
public class MathPrecedence : TestClass
{

View File

@@ -1,8 +1,7 @@
using Upsilon.BaseTypes.Number;
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
namespace UpsilonTests.GeneralTests
{
public class ScopeTests : TestClass
{

View File

@@ -1,7 +1,7 @@
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
namespace UpsilonTests.GeneralTests
{
public class StringTests : TestClass
{

View File

@@ -1,7 +1,7 @@
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
namespace UpsilonTests.GeneralTests
{
public class TableTests : TestClass
{

View File

@@ -2,7 +2,7 @@ using System.Collections.Generic;
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
namespace UpsilonTests.GeneralTests
{
public class UserDataDictionaryTests : TestClass
{

View File

@@ -2,7 +2,7 @@ using System.Collections.Generic;
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
namespace UpsilonTests.GeneralTests
{
public class UserDataListTests : TestClass
{

View File

@@ -2,10 +2,11 @@ using System;
using Upsilon.BaseTypes.UserData;
using Upsilon.Evaluator;
using Xunit;
// ReSharper disable UnusedMember.Local
// ReSharper disable ClassNeverInstantiated.Global
namespace UpsilonTests
namespace UpsilonTests.GeneralTests
{
public class UserDataOperatorTests : TestClass, IClassFixture<UserDataOperatorTests.UserDataOperatorTestsFixture>
{

View File

@@ -2,9 +2,10 @@ using System;
using Upsilon.BaseTypes.UserData;
using Upsilon.Evaluator;
using Xunit;
// ReSharper disable UnusedMember.Local
namespace UpsilonTests
namespace UpsilonTests.GeneralTests
{
public class UserDataTests : TestClass, IClassFixture<UserDataTests.UserDataTestsFixture>
{