Browse Source

Remastered architecture of project and tests

master
Ludovic Lagouardette 1 year ago
parent
commit
88607be70e
22 changed files with 118 additions and 18 deletions
  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 View File

@ -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 View File

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

Bytecode.cs → SuperBASIC/Bytecode.cs View File


Functions/Add.cs → SuperBASIC/Functions/Add.cs View File

@ -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 View File

@ -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 View File

@ -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 View File

@ -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 View File

@ -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 View File

@ -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 View File

@ -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 View File

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

LICENCE → SuperBASIC/LICENCE View File


Library.cs → SuperBASIC/Library.cs View File

@ -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 View File


Program.cs → SuperBASIC/Program.cs View File


Runtime.cs → SuperBASIC/Runtime.cs View File

@ -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 View File


Test.basic → SuperBASIC/Test.basic View File


+ 11
- 0
TestsSuperBASIC/CasDeTest/PrebuiltTest-TestA.basic View File

@ -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 View File

@ -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 View File

@ -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 View File

@ -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>

Loading…
Cancel
Save