Bladeren bron

Remastered architecture of project and tests

master
Ludovic Lagouardette 2 jaren geleden
bovenliggende
commit
88607be70e
22 gewijzigde bestanden met toevoegingen van 118 en 18 verwijderingen
  1. +7
    -1
      SuperBASIC.sln
  2. +1
    -1
      SuperBASIC/BasicNumber.cs
  3. +0
    -0
      SuperBASIC/Bytecode.cs
  4. +1
    -1
      SuperBASIC/Functions/Add.cs
  5. +1
    -1
      SuperBASIC/Functions/Compare.cs
  6. +2
    -2
      SuperBASIC/Functions/Constants.cs
  7. +2
    -2
      SuperBASIC/Functions/Goto.cs
  8. +5
    -5
      SuperBASIC/Functions/Memory.cs
  9. +1
    -1
      SuperBASIC/Functions/Multiply.cs
  10. +1
    -1
      SuperBASIC/Functions/Print.cs
  11. +1
    -1
      SuperBASIC/IFunction.cs
  12. +0
    -0
      SuperBASIC/LICENCE
  13. +1
    -1
      SuperBASIC/Library.cs
  14. +0
    -0
      SuperBASIC/Parser.cs
  15. +0
    -0
      SuperBASIC/Program.cs
  16. +1
    -1
      SuperBASIC/Runtime.cs
  17. +0
    -0
      SuperBASIC/SuperBASIC.csproj
  18. +0
    -0
      SuperBASIC/Test.basic
  19. +11
    -0
      TestsSuperBASIC/CasDeTest/PrebuiltTest-TestA.basic
  20. +20
    -0
      TestsSuperBASIC/Mock/MockPrint.cs
  21. +37
    -0
      TestsSuperBASIC/PrebuiltTest.cs
  22. +26
    -0
      TestsSuperBASIC/TestsSuperBASIC.csproj

+ 7
- 1
SuperBASIC.sln Bestand weergeven

@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30907.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperBASIC", "SuperBASIC.csproj", "{51942D92-4C96-4FD9-AA5B-C35661E3B063}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SuperBASIC", "SuperBASIC\SuperBASIC.csproj", "{51942D92-4C96-4FD9-AA5B-C35661E3B063}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsSuperBASIC", "TestsSuperBASIC\TestsSuperBASIC.csproj", "{68535611-B607-4476-B887-0B8D713F3A4D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +17,10 @@ Global
{51942D92-4C96-4FD9-AA5B-C35661E3B063}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51942D92-4C96-4FD9-AA5B-C35661E3B063}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51942D92-4C96-4FD9-AA5B-C35661E3B063}.Release|Any CPU.Build.0 = Release|Any CPU
{68535611-B607-4476-B887-0B8D713F3A4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68535611-B607-4476-B887-0B8D713F3A4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68535611-B607-4476-B887-0B8D713F3A4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68535611-B607-4476-B887-0B8D713F3A4D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

BasicNumber.cs → SuperBASIC/BasicNumber.cs Bestand weergeven

@ -11,7 +11,7 @@ namespace SuperBASIC
Memory
};
struct BasicNumber
public struct BasicNumber
{
internal NumberType type;

Bytecode.cs → SuperBASIC/Bytecode.cs Bestand weergeven


Functions/Add.cs → SuperBASIC/Functions/Add.cs Bestand weergeven

@ -4,7 +4,7 @@ using System.Text;
namespace SuperBASIC.Functions
{
class Add : IFunction
public class Add : IFunction
{
float IFunction.Apply(List<BasicNumber> arguments)
{

Functions/Compare.cs → SuperBASIC/Functions/Compare.cs Bestand weergeven

@ -4,7 +4,7 @@ using System.Text;
namespace SuperBASIC.Functions
{
class Compare : IFunction
public class Compare : IFunction
{
float IFunction.Apply(List<BasicNumber> arguments)
{

Functions/Constants.cs → SuperBASIC/Functions/Constants.cs Bestand weergeven

@ -4,14 +4,14 @@ using System.Text;
namespace SuperBASIC.Functions
{
class Pi : IFunction
public class Pi : IFunction
{
float IFunction.Apply(List<BasicNumber> arguments)
{
return (float)Math.PI;
}
}
class Euler : IFunction
public class Euler : IFunction
{
float IFunction.Apply(List<BasicNumber> arguments)
{

Functions/Goto.cs → SuperBASIC/Functions/Goto.cs Bestand weergeven

@ -4,7 +4,7 @@ using System.Text;
namespace SuperBASIC.Functions
{
class Goto : IFunction
public class Goto : IFunction
{
public float Apply(List<BasicNumber> arguments)
{
@ -13,7 +13,7 @@ namespace SuperBASIC.Functions
return arguments[0].runtime.register;
}
}
class JumpZero : IFunction
public class JumpZero : IFunction
{
public float Apply(List<BasicNumber> arguments)
{

Functions/Memory.cs → SuperBASIC/Functions/Memory.cs Bestand weergeven

@ -5,12 +5,12 @@ using System.Text;
namespace SuperBASIC.Functions
{
#if MEMORY
static class Memory
static public class Memory
{
internal static float[] memory = new float[Int16.MaxValue];
internal static float MemoryGet(Int16 pos) => memory[pos];
internal static float MemorySet(Int16 pos, float value)
public static float MemoryGet(Int16 pos) => memory[pos];
public static float MemorySet(Int16 pos, float value)
{
memory[pos] = value;
return value;
@ -30,7 +30,7 @@ namespace SuperBASIC.Functions
}
class MemoryLoad : IFunction
public class MemoryLoad : IFunction
{
float IFunction.Apply(List<BasicNumber> arguments)
{
@ -42,7 +42,7 @@ namespace SuperBASIC.Functions
throw new Memory.BadMemoryAccess("Could not access requested memory");
}
}
class MemoryStore : IFunction
public class MemoryStore : IFunction
{
float IFunction.Apply(List<BasicNumber> arguments)
{

Functions/Multiply.cs → SuperBASIC/Functions/Multiply.cs Bestand weergeven

@ -4,7 +4,7 @@ using System.Text;
namespace SuperBASIC.Functions
{
class Multiply : IFunction
public class Multiply : IFunction
{
float IFunction.Apply(List<BasicNumber> arguments)
{

Functions/Print.cs → SuperBASIC/Functions/Print.cs Bestand weergeven

@ -4,7 +4,7 @@ using System.Text;
namespace SuperBASIC.Functions
{
class Print : IFunction
public class Print : IFunction
{
float IFunction.Apply(List<BasicNumber> arguments)
{

IFunction.cs → SuperBASIC/IFunction.cs Bestand weergeven

@ -4,7 +4,7 @@ using System.Text;
namespace SuperBASIC
{
interface IFunction
public interface IFunction
{
public float Apply(List<BasicNumber> arguments);
}

LICENCE → SuperBASIC/LICENCE Bestand weergeven


Library.cs → SuperBASIC/Library.cs Bestand weergeven

@ -4,7 +4,7 @@ using System.Text;
namespace SuperBASIC
{
class Library
public class Library
{
internal List<IFunction> functions;
internal List<int> arities;

Parser.cs → SuperBASIC/Parser.cs Bestand weergeven


Program.cs → SuperBASIC/Program.cs Bestand weergeven


Runtime.cs → SuperBASIC/Runtime.cs Bestand weergeven

@ -4,7 +4,7 @@ using System.Text;
namespace SuperBASIC
{
class Runtime
public class Runtime
{
public float register;
internal Library lib;

SuperBASIC.csproj → SuperBASIC/SuperBASIC.csproj Bestand weergeven


Test.basic → SuperBASIC/Test.basic Bestand weergeven


+ 11
- 0
TestsSuperBASIC/CasDeTest/PrebuiltTest-TestA.basic Bestand weergeven

@ -0,0 +1,11 @@
MEMSTORE 1 0
MEMSTORE 0 10
WHILE MEMLOAD 0
MEMLOAD 0
ADD $ -1
MEMSTORE 0 $
MEMLOAD 1
ADD $ 1
MEMSTORE 1 $
PRINT M1
WEND

+ 20
- 0
TestsSuperBASIC/Mock/MockPrint.cs Bestand weergeven

@ -0,0 +1,20 @@
using SuperBASIC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestsSuperBASIC.Mock
{
class MockPrint : SuperBASIC.IFunction
{
public List<float> output = new List<float>();
float IFunction.Apply(List<BasicNumber> arguments)
{
output.Add(arguments[0]);
return 0;
}
}
}

+ 37
- 0
TestsSuperBASIC/PrebuiltTest.cs Bestand weergeven

@ -0,0 +1,37 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SuperBASIC;
using System.IO;
using System.Linq;
namespace TestsSuperBASIC
{
[TestClass]
public class PrebuiltTest
{
[TestMethod]
public void TestA()
{
Library lib = new Library();
var printer = new Mock.MockPrint();
lib.AddFunction(printer, 1, "PRINT");
lib.AddFunction(new SuperBASIC.Functions.MemoryLoad(), 1, "MEMLOAD");
lib.AddFunction(new SuperBASIC.Functions.MemoryStore(), 2, "MEMSTORE");
lib.AddFunction(new SuperBASIC.Functions.Multiply(), 2, "MULTIPLY");
lib.AddFunction(new SuperBASIC.Functions.Add(), 2, "ADD");
lib.AddFunction(new SuperBASIC.Functions.Compare(), 2, "COMPARE");
lib.AddFunction(new SuperBASIC.Functions.JumpZero(), 2, "JZ");
lib.AddFunction(new SuperBASIC.Functions.Goto(), 1, "GOTO");
lib.AddFunction(new SuperBASIC.Functions.Pi(), 0, "PI");
lib.AddFunction(new SuperBASIC.Functions.Euler(), 0, "EULER");
Runtime r = new Runtime(lib);
r.OpenFile(Directory.GetCurrentDirectory() + "\\CasDeTest\\PrebuiltTest-TestA.basic");
r.Run();
foreach(var (expected, received) in Enumerable.Range(1,10).Zip(printer.output))
{
Assert.AreEqual(expected, received);
}
}
}
}

+ 26
- 0
TestsSuperBASIC/TestsSuperBASIC.csproj Bestand weergeven

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="coverlet.collector" Version="3.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SuperBASIC\SuperBASIC.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="CasDeTest\PrebuiltTest-TestA.basic">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

Laden…
Annuleren
Opslaan