Files
InverseOfLife.Test/tests/GeneEncodeDecodeTests.cs
2025-01-18 08:30:10 +00:00

124 lines
4.1 KiB
C#

using NUnit.Framework;
namespace InverseOfLife.Test;
[TestFixture]
public class GeneEncodeDecodeTests
{
[Test]
public void EncodeAndDecode_ShouldHandleResolution1Correctly()
{
int resolution = 1;
int width = 8;
int height = 8;
var board = new Board(width, height);
board.Toggle(0, 0);
board.Toggle(7, 7);
board.Toggle(3, 5);
var gene = new Gene(resolution, board);
var restoredBoard = gene.Restore(width, height);
Assert.IsTrue(restoredBoard.Lives.Contains((0, 0)), "Cell (0, 0) should be alive.");
Assert.IsTrue(restoredBoard.Lives.Contains((7, 7)), "Cell (7, 7) should be alive.");
Assert.IsTrue(restoredBoard.Lives.Contains((3, 5)), "Cell (3, 5) should be alive.");
Assert.That(restoredBoard.Lives, Is.EquivalentTo(board.Lives), "Restored board should match the original board.");
}
[Test]
public void EncodeAndDecode_ShouldHandleResolution2Correctly()
{
int resolution = 2;
int width = 4;
int height = 4;
var board = new Board(width, height);
board.Toggle(0, 0);
board.Toggle(3, 3);
board.Toggle(2, 1);
board.Toggle(1, 2);
var gene = new Gene(resolution, board);
var restoredBoard = gene.Restore(width, height);
Assert.IsTrue(restoredBoard.Lives.Contains((0, 0)), "Cell (0, 0) should be alive.");
Assert.IsTrue(restoredBoard.Lives.Contains((3, 3)), "Cell (3, 3) should be alive.");
Assert.IsTrue(restoredBoard.Lives.Contains((2, 1)), "Cell (2, 1) should be alive.");
Assert.IsTrue(restoredBoard.Lives.Contains((1, 2)), "Cell (1, 2) should be alive.");
Assert.That(restoredBoard.Lives, Is.EquivalentTo(board.Lives), "Restored board should match the original board.");
}
[Test]
public void EncodeAndDecode_ShouldHandleEmptyBoardResolution1()
{
int resolution = 1;
int width = 8;
int height = 8;
var board = new Board(width, height);
var gene = new Gene(resolution, board);
var restoredBoard = gene.Restore(width, height);
Assert.IsEmpty(restoredBoard.Lives, "Restored board should be empty.");
}
[Test]
public void EncodeAndDecode_ShouldHandleEmptyBoardResolution2()
{
int resolution = 2;
int width = 4;
int height = 4;
var board = new Board(width, height);
var gene = new Gene(resolution, board);
var restoredBoard = gene.Restore(width, height);
Assert.IsEmpty(restoredBoard.Lives, "Restored board should be empty.");
}
[Test]
public void EncodeAndDecode_ShouldHandleFullBoardResolution1()
{
int resolution = 1;
int width = 8;
int height = 8;
var board = new Board(width, height);
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
board.Toggle(x, y);
}
}
var gene = new Gene(resolution, board);
foreach (byte b in gene.RiboseSequence)
{
Console.Write($"{b} ");
Console.WriteLine();
}
var restoredBoard = gene.Restore(width, height);
Console.WriteLine("-");
Console.WriteLine(restoredBoard.ToString());
Console.WriteLine("=");
Assert.That(restoredBoard.Lives, Is.EquivalentTo(board.Lives), "Restored board should match the original full board.");
}
[Test]
public void EncodeAndDecode_ShouldHandleFullBoardResolution2()
{
int resolution = 2;
int width = 4;
int height = 4;
var board = new Board(width, height);
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
board.Toggle(x, y);
}
}
var gene = new Gene(resolution, board);
var restoredBoard = gene.Restore(width, height);
Console.WriteLine(restoredBoard.ToString());
Assert.That(restoredBoard.Lives, Is.EquivalentTo(board.Lives), "Restored board should match the original full board.");
}
}