Make the Fuse test classes more generic, so I can use them again for the Z80 fuse runner.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
3c7ca33efe
commit
63ef445a78
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="RegisterState.cs" company="Adrian Conlon">
|
||||
// <copyright file="AbstractRegisterState.cs" company="Adrian Conlon">
|
||||
// Copyright (c) Adrian Conlon. All rights reserved.
|
||||
// </copyright>
|
||||
namespace Fuse
|
||||
|
@ -6,18 +6,19 @@ namespace Fuse
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using EightBit;
|
||||
|
||||
public class RegisterState
|
||||
public abstract class AbstractRegisterState
|
||||
{
|
||||
private readonly List<Register16> registers = new List<Register16>();
|
||||
|
||||
public ReadOnlyCollection<Register16> Registers => this.registers.AsReadOnly();
|
||||
public ReadOnlyCollection<Register16> Registers => this.MutableRegisters.AsReadOnly();
|
||||
|
||||
public bool Halted { get; private set; } = false;
|
||||
public bool Halted { get; protected set; } = false;
|
||||
|
||||
public int TStates { get; private set; } = -1;
|
||||
public int TStates { get; protected set; } = -1;
|
||||
|
||||
protected List<Register16> MutableRegisters => this.registers;
|
||||
|
||||
public void Parse(Lines lines)
|
||||
{
|
||||
|
@ -25,21 +26,17 @@ namespace Fuse
|
|||
this.ParseInternalState(lines);
|
||||
}
|
||||
|
||||
private void ParseInternalState(Lines lines) => this.ParseInternalState(lines.ReadLine());
|
||||
protected void ParseInternalState(Lines lines) => this.ParseInternalState(lines.ReadLine());
|
||||
|
||||
private void ParseInternalState(string line)
|
||||
protected virtual void ParseInternalState(string line)
|
||||
{
|
||||
var tokens = line.Split(new char[] { ' ', '\t' });
|
||||
this.ParseInternalState(tokens);
|
||||
}
|
||||
|
||||
private void ParseInternalState(string[] tokens)
|
||||
{
|
||||
this.Halted = Convert.ToInt32(tokens[0], CultureInfo.InvariantCulture) == 1;
|
||||
this.TStates = Convert.ToInt32(tokens[1], CultureInfo.InvariantCulture);
|
||||
}
|
||||
protected abstract void ParseInternalState(string[] tokens);
|
||||
|
||||
private void ParseExternalState(Lines lines)
|
||||
protected virtual void ParseExternalState(Lines lines)
|
||||
{
|
||||
var line = lines.ReadLine();
|
||||
foreach (var token in line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries))
|
|
@ -37,10 +37,11 @@
|
|||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AbstractRegisterState.cs" />
|
||||
<Compile Include="Lines.cs" />
|
||||
<Compile Include="MemoryDatum.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RegisterState.cs" />
|
||||
<Compile Include="IRegisterState.cs" />
|
||||
<Compile Include="Result.cs" />
|
||||
<Compile Include="Results.cs" />
|
||||
<Compile Include="Test.cs" />
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
// <copyright file="IRegisterState.cs" company="Adrian Conlon">
|
||||
// Copyright (c) Adrian Conlon. All rights reserved.
|
||||
// </copyright>
|
||||
namespace Fuse
|
||||
{
|
||||
using System.Collections.ObjectModel;
|
||||
using EightBit;
|
||||
|
||||
public interface IRegisterState
|
||||
{
|
||||
ReadOnlyCollection<Register16> Registers
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
bool Halted { get; }
|
||||
|
||||
int TStates { get; }
|
||||
|
||||
void Parse(Lines lines);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,7 @@
|
|||
using System.Reflection;
|
||||
// <copyright file="AssemblyInfo.cs" company="Adrian Conlon">
|
||||
// Copyright (c) Adrian Conlon. All rights reserved.
|
||||
// </copyright>
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
|
|
@ -7,14 +7,15 @@ namespace Fuse
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
public class Result
|
||||
public class Result<T>
|
||||
where T : Fuse.IRegisterState, new()
|
||||
{
|
||||
private readonly TestEvents events = new TestEvents();
|
||||
private readonly List<MemoryDatum> memoryData = new List<MemoryDatum>();
|
||||
|
||||
public string Description { get; private set; }
|
||||
|
||||
public RegisterState RegisterState { get; } = new RegisterState();
|
||||
public T RegisterState { get; } = new T();
|
||||
|
||||
public ReadOnlyCollection<MemoryDatum> MemoryData => this.memoryData.AsReadOnly();
|
||||
|
||||
|
@ -38,7 +39,7 @@ namespace Fuse
|
|||
this.events.Parse(lines);
|
||||
this.RegisterState.Parse(lines);
|
||||
|
||||
var finished = false;
|
||||
bool finished;
|
||||
do
|
||||
{
|
||||
var line = lines.ReadLine();
|
||||
|
|
|
@ -5,13 +5,14 @@ namespace Fuse
|
|||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class Results
|
||||
public class Results<T>
|
||||
where T : Fuse.IRegisterState, new()
|
||||
{
|
||||
private readonly Lines lines;
|
||||
|
||||
public Results(string path) => this.lines = new Lines(path);
|
||||
|
||||
public Dictionary<string, Result> Container { get; } = new Dictionary<string, Result>();
|
||||
public Dictionary<string, Result<T>> Container { get; } = new Dictionary<string, Result<T>>();
|
||||
|
||||
public void Read() => this.lines.Read();
|
||||
|
||||
|
@ -19,7 +20,7 @@ namespace Fuse
|
|||
{
|
||||
while (!this.lines.EndOfFile)
|
||||
{
|
||||
var result = new Result();
|
||||
var result = new Result<T>();
|
||||
if (result.TryParse(this.lines))
|
||||
{
|
||||
this.Container.Add(result.Description, result);
|
||||
|
|
|
@ -6,13 +6,14 @@ namespace Fuse
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class Test
|
||||
public class Test<T>
|
||||
where T : Fuse.IRegisterState, new()
|
||||
{
|
||||
private readonly List<MemoryDatum> memoryData = new List<MemoryDatum>();
|
||||
|
||||
public string Description { get; private set; }
|
||||
|
||||
public RegisterState RegisterState { get; } = new RegisterState();
|
||||
public T RegisterState { get; } = new T();
|
||||
|
||||
public IReadOnlyCollection<MemoryDatum> MemoryData => this.memoryData.AsReadOnly();
|
||||
|
||||
|
@ -35,7 +36,7 @@ namespace Fuse
|
|||
|
||||
this.RegisterState.Parse(lines);
|
||||
|
||||
var finished = false;
|
||||
bool finished;
|
||||
do
|
||||
{
|
||||
var line = lines.ReadLine();
|
||||
|
|
|
@ -5,13 +5,14 @@ namespace Fuse
|
|||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class Tests
|
||||
public class Tests<T>
|
||||
where T : Fuse.IRegisterState, new()
|
||||
{
|
||||
private readonly Lines lines;
|
||||
|
||||
public Tests(string path) => this.lines = new Lines(path);
|
||||
|
||||
public Dictionary<string, Test> Container { get; } = new Dictionary<string, Test>();
|
||||
public Dictionary<string, Test<T>> Container { get; } = new Dictionary<string, Test<T>>();
|
||||
|
||||
public void Read() => this.lines.Read();
|
||||
|
||||
|
@ -19,7 +20,7 @@ namespace Fuse
|
|||
{
|
||||
while (!this.lines.EndOfFile)
|
||||
{
|
||||
var test = new Test();
|
||||
var test = new Test<T>();
|
||||
if (test.TryParse(this.lines))
|
||||
{
|
||||
this.Container.Add(test.Description, test);
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RegisterState.cs" />
|
||||
<Compile Include="TestRunner.cs" />
|
||||
<Compile Include="TestSuite.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Fuse
|
|||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var suite = new TestSuite("fuse-tests\\tests");
|
||||
var suite = new TestSuite<RegisterState>("fuse-tests\\tests");
|
||||
suite.Read();
|
||||
suite.Parse();
|
||||
suite.Run();
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
// <copyright file="RegisterState.cs" company="Adrian Conlon">
|
||||
// Copyright (c) Adrian Conlon. All rights reserved.
|
||||
// </copyright>
|
||||
namespace Fuse
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
public class RegisterState : AbstractRegisterState, IRegisterState
|
||||
{
|
||||
protected override void ParseInternalState(string[] tokens)
|
||||
{
|
||||
this.Halted = Convert.ToInt32(tokens[0], CultureInfo.InvariantCulture) == 1;
|
||||
this.TStates = Convert.ToInt32(tokens[1], CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,13 +14,14 @@ namespace Fuse
|
|||
PC,
|
||||
}
|
||||
|
||||
public class TestRunner : EightBit.GameBoy.Bus
|
||||
public class TestRunner<T> : EightBit.GameBoy.Bus
|
||||
where T : Fuse.IRegisterState, new()
|
||||
{
|
||||
private readonly Test test;
|
||||
private readonly Result result;
|
||||
private readonly Test<T> test;
|
||||
private readonly Result<T> result;
|
||||
private readonly EightBit.Ram ram = new EightBit.Ram(0x10000);
|
||||
|
||||
public TestRunner(Test test, Result result)
|
||||
public TestRunner(Test<T> test, Result<T> result)
|
||||
{
|
||||
this.test = test;
|
||||
this.result = result;
|
||||
|
|
|
@ -3,15 +3,16 @@
|
|||
// </copyright>
|
||||
namespace Fuse
|
||||
{
|
||||
public class TestSuite
|
||||
public class TestSuite<T>
|
||||
where T : Fuse.IRegisterState, new()
|
||||
{
|
||||
private readonly Tests tests;
|
||||
private readonly Results results;
|
||||
private readonly Tests<T> tests;
|
||||
private readonly Results<T> results;
|
||||
|
||||
public TestSuite(string path)
|
||||
{
|
||||
this.tests = new Tests(path + ".in");
|
||||
this.results = new Results(path + ".expected");
|
||||
this.tests = new Tests<T>(path + ".in");
|
||||
this.results = new Results<T>(path + ".expected");
|
||||
}
|
||||
|
||||
public void Read()
|
||||
|
@ -37,7 +38,7 @@ namespace Fuse
|
|||
|
||||
var input = test.Value;
|
||||
var result = this.results.Container[key];
|
||||
var runner = new TestRunner(input, result);
|
||||
var runner = new TestRunner<T>(input, result);
|
||||
|
||||
runner.Run();
|
||||
if (runner.Failed)
|
||||
|
|
Loading…
Reference in New Issue