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; configuration.DebugMode = true;
#endif #endif
using (var harness = new TestHarness(configuration)) var harness = new TestHarness(configuration);
{ harness.Run();
harness.Run();
}
} }
} }
} }

View File

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

View File

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

View File

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

View File

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