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:
Adrian Conlon
2019-08-13 18:51:34 +01:00
parent 3c7ca33efe
commit 63ef445a78
13 changed files with 86 additions and 39 deletions
@@ -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))
+2 -1
View File
@@ -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" />
+22
View File
@@ -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);
}
}
+4 -1
View File
@@ -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;
+4 -3
View File
@@ -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();
+4 -3
View File
@@ -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);
+4 -3
View File
@@ -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();
+4 -3
View File
@@ -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);