Imrpoved tests; building up to larger sprites
This commit is contained in:
parent
2bf19084f7
commit
2e75b8d354
|
@ -0,0 +1,103 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using SpriteCompiler.Problem;
|
||||
using SpriteCompiler.AI;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpriteCompiler.Test
|
||||
{
|
||||
/// <summary>
|
||||
/// Incremental tests that build a 16x32 mario sprite one line at a time
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class MarioTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void TestFirstLine()
|
||||
{
|
||||
// Arrange
|
||||
var problem = SpriteGeneratorSearchProblem.CreateSearchProblem();
|
||||
var search = SpriteGeneratorSearchProblem.Create();
|
||||
var sprite = new List<SpriteByte>
|
||||
{
|
||||
new SpriteByte(0x11, 0x00, 3),
|
||||
new SpriteByte(0x11, 0x00, 4),
|
||||
new SpriteByte(0x10, 0x0F, 5)
|
||||
};
|
||||
|
||||
// Act : solve the problem
|
||||
var solution = search.Search(problem, new SpriteGeneratorState(sprite));
|
||||
|
||||
// Assert : The initial state IS the goal state
|
||||
WriteOutSolution(solution);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestLines_1_To_2()
|
||||
{
|
||||
// Arrange
|
||||
var problem = SpriteGeneratorSearchProblem.CreateSearchProblem();
|
||||
var search = SpriteGeneratorSearchProblem.Create();
|
||||
var sprite = new List<SpriteByte>
|
||||
{
|
||||
new SpriteByte(0x11, 0x00, 3),
|
||||
new SpriteByte(0x11, 0x00, 4),
|
||||
new SpriteByte(0x10, 0x0F, 5),
|
||||
|
||||
new SpriteByte(0x11, 0x00, 162),
|
||||
new SpriteByte(0x11, 0x00, 163),
|
||||
new SpriteByte(0x11, 0x00, 164),
|
||||
new SpriteByte(0x20, 0x0F, 165),
|
||||
};
|
||||
|
||||
// Act : solve the problem
|
||||
var solution = search.Search(problem, new SpriteGeneratorState(sprite));
|
||||
|
||||
// Assert : The initial state IS the goal state
|
||||
WriteOutSolution(solution);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestLines_1_To_3()
|
||||
{
|
||||
// Arrange
|
||||
var problem = SpriteGeneratorSearchProblem.CreateSearchProblem();
|
||||
var search = SpriteGeneratorSearchProblem.Create();
|
||||
var sprite = new List<SpriteByte>
|
||||
{
|
||||
new SpriteByte(0x11, 0x00, 3),
|
||||
new SpriteByte(0x11, 0x00, 4),
|
||||
new SpriteByte(0x10, 0x0F, 5),
|
||||
|
||||
new SpriteByte(0x11, 0x00, 162),
|
||||
new SpriteByte(0x11, 0x00, 163),
|
||||
new SpriteByte(0x11, 0x00, 164),
|
||||
new SpriteByte(0x20, 0x0F, 165),
|
||||
|
||||
new SpriteByte(0x01, 0xF0, 321),
|
||||
new SpriteByte(0x11, 0x00, 322),
|
||||
new SpriteByte(0x11, 0x00, 323),
|
||||
new SpriteByte(0x12, 0x00, 324),
|
||||
new SpriteByte(0x20, 0x0F, 325)
|
||||
};
|
||||
|
||||
// Act : solve the problem
|
||||
var solution = search.Search(problem, new SpriteGeneratorState(sprite));
|
||||
|
||||
// Assert : The initial state IS the goal state
|
||||
WriteOutSolution(solution);
|
||||
}
|
||||
|
||||
private void WriteOutSolution(IEnumerable<SpriteGeneratorSearchNode> solution)
|
||||
{
|
||||
foreach (var step in solution.Skip(1))
|
||||
{
|
||||
Trace.WriteLine(step.Action.Emit());
|
||||
}
|
||||
|
||||
Trace.WriteLine(string.Format("; Total Cost = {0} cycles", (int)solution.Last().PathCost));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -63,6 +63,7 @@
|
|||
<Compile Include="HeuristicTests.cs" />
|
||||
<Compile Include="RegisterTests.cs" />
|
||||
<Compile Include="StateTests.cs" />
|
||||
<Compile Include="MarioTests.cs" />
|
||||
<Compile Include="Tests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -79,6 +79,32 @@ namespace SpriteCompiler.Test
|
|||
Assert.AreEqual(10, (int)solution.Last().PathCost);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestOverlappingWrite()
|
||||
{
|
||||
// Arrange
|
||||
var problem = SpriteGeneratorSearchProblem.CreateSearchProblem();
|
||||
var search = SpriteGeneratorSearchProblem.Create();
|
||||
|
||||
// Act : solve the problem
|
||||
var solution = search.Search(problem, new SpriteGeneratorState(new byte[] { 0x11, 0x22, 0x22 }));
|
||||
|
||||
// Assert
|
||||
//
|
||||
// Solution should be 18 cycles
|
||||
//
|
||||
// TCS
|
||||
// LDA #$2211
|
||||
// STA 0,s
|
||||
// LDA #$2222
|
||||
// STA 1,s = 18 cycles
|
||||
|
||||
// Write out the solution
|
||||
WriteOutSolution(solution);
|
||||
|
||||
Assert.AreEqual(18, (int)solution.Last().PathCost);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestConsecutiveWordSprite()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue