Tidy up test harnesses

This commit is contained in:
Adrian Conlon
2024-10-10 11:27:31 +01:00
parent 5c71acc40a
commit 0d695a6d7a
5 changed files with 19 additions and 69 deletions

View File

@@ -14,10 +14,8 @@ namespace Intel8080.Test
configuration.DebugMode = true;
#endif
using (var harness = new TestHarness(configuration))
{
harness.Run();
}
var harness = new TestHarness(configuration);
harness.Run();
}
}
}

View File

@@ -4,24 +4,13 @@
namespace Intel8080.Test
{
using System;
using System.Diagnostics;
internal class TestHarness : IDisposable
internal class TestHarness(Configuration configuration)
{
private readonly Stopwatch timer = new Stopwatch();
private readonly Board board;
private long totalCycles = 0;
private bool disposed = false;
public TestHarness(Configuration configuration) => this.board = new Board(configuration);
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
private readonly Stopwatch timer = new();
private readonly Board board = new(configuration);
private long totalCycles;
public void Run()
{
@@ -37,20 +26,9 @@ namespace Intel8080.Test
}
this.timer.Stop();
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
System.Console.Out.WriteLine($"\n\nGuest cycles = {this.totalCycles}");
System.Console.Out.WriteLine($"Seconds = {this.timer.ElapsedMilliseconds / 1000.0}");
}
this.disposed = true;
}
System.Console.Out.WriteLine($"\n\nGuest cycles = {this.totalCycles}");
System.Console.Out.WriteLine($"Seconds = {this.timer.ElapsedMilliseconds / 1000.0}");
}
}
}

View File

@@ -11,12 +11,10 @@ namespace M6502.Test
var configuration = new Configuration();
#if DEBUG
configuration.DebugMode;
configuration.DebugMode = false;
#endif
using (var harness = new TestHarness(configuration))
{
harness.Run();
}
var harness = new TestHarness(configuration);
harness.Run();
}
}
}

View File

@@ -14,10 +14,8 @@ namespace EightBit
configuration.DebugMode = true;
#endif
using (var harness = new TestHarness(configuration))
{
harness.Run();
}
var harness = new TestHarness(configuration);
harness.Run();
}
}
}

View File

@@ -4,24 +4,13 @@
namespace EightBit
{
using System;
using System.Diagnostics;
internal class TestHarness : IDisposable
internal sealed class TestHarness(Configuration configuration)
{
private readonly Stopwatch timer = new Stopwatch();
private readonly Board board;
private long totalCycles = 0;
private bool disposed = false;
public TestHarness(Configuration configuration) => this.board = new Board(configuration);
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
private readonly Stopwatch timer = new();
private readonly Board board = new(configuration);
private long totalCycles;
public void Run()
{
@@ -37,20 +26,9 @@ namespace EightBit
}
this.timer.Stop();
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
System.Console.Out.WriteLine($"\n\nGuest cycles = {this.totalCycles}");
System.Console.Out.WriteLine($"Seconds = {this.timer.ElapsedMilliseconds / 1000.0}");
}
this.disposed = true;
}
System.Console.Out.WriteLine($"\n\nGuest cycles = {this.totalCycles}");
System.Console.Out.WriteLine($"Seconds = {this.timer.ElapsedMilliseconds / 1000.0}");
}
}
}