⚙️ Ajout de tests supplémentaires pour d'autres règles
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is failing Details

pull/74/head
Rémi LAVERGNE 11 months ago
parent 9dc789c3ec
commit a6ddee80af
No known key found for this signature in database
GPG Key ID: CA264B55E97FD220

@ -95,4 +95,141 @@ public class RulesTests
map.RopePaths.Add(new List<Cell> { cell1 });
Assert.False(rules.IsInRopePaths(cell2, map.RopePaths, 0));
}
[Fact]
public void IsInRopePaths_ReturnsTrue_WhenCellsAreInRopePathsButNotInTheSamePath()
{
Rules rules = new Rules();
Cell cell1 = new Cell(0, 0);
Cell cell2 = new Cell(0, 1);
Map map = new Map("background");
map.RopePaths.Add(new List<Cell> { cell1 });
map.RopePaths.Add(new List<Cell> { cell2 });
Assert.True(rules.IsInRopePaths(cell2, map.RopePaths, 0));
}
[Fact]
public void AsValue_ReturnsTrue_WhenCellHasTheSameValue()
{
Rules rules = new Rules();
Cell cell1 = new Cell(0, 0);
Cell cell2 = new Cell(0, 1);
cell1.Value = 5;
cell2.Value = 5;
Map map = new Map("background");
map.RopePaths.Add(new List<Cell> { cell1, cell2 });
Assert.True(rules.AsValue(cell2, map.RopePaths, 0));
}
[Fact]
public void AsValue_ReturnsTrue_WhenCellValueIsAlreadyInRopePaths()
{
Rules rules = new Rules();
Cell cell1 = new Cell(0, 0);
Cell cell2 = new Cell(0, 1);
cell1.Value = 5;
cell2.Value = 5;
Map map = new Map("background");
map.RopePaths.Add(new List<Cell> { cell1 });
Assert.True(rules.AsValue(cell2, map.RopePaths, 0));
}
[Fact]
public void AsValue_ReturnsFalse_WhenCellHasDifferentValue()
{
Rules rules = new Rules();
Cell cell1 = new Cell(0, 0);
Cell cell2 = new Cell(0, 1);
cell1.Value = 5;
cell2.Value = 6;
Map map = new Map("background");
map.RopePaths.Add(new List<Cell> { cell1 });
Assert.False(rules.AsValue(cell2, map.RopePaths, 0));
}
[Fact]
public void NearCellIsValid_ReturnsFalse_WhenChosenCellIsNull()
{
Rules rules = new Rules();
Assert.False(rules.NearCellIsValid(null, new List<Cell>()));
}
[Fact]
public void NearCellIsValid_ReturnsFalse_WhenCellsIsNull()
{
Rules rules = new Rules();
Cell cell = new Cell(0, 0);
Assert.False(rules.NearCellIsValid(cell, null));
}
[Fact]
public void NearCellIsValid_ReturnsFalse_WhenNoAdjacentCells()
{
Rules rules = new Rules();
Cell cell = new Cell(0, 0);
List<Cell> cells = new List<Cell> { new Cell(2, 0) };
Assert.False(rules.NearCellIsValid(cell, cells));
}
[Fact]
public void NearCellIsValid_ReturnsTrue_WhenAdjacentCellExists()
{
Rules rules = new Rules();
Cell cell1 = new Cell(0, 0);
Cell cell2 = new Cell(0, 1);
cell2.Value = 12;
List<Cell> cells = new List<Cell> { cell2 };
Assert.True(rules.NearCellIsValid(cell1, cells));
}
[Fact]
public void IsZoneValidAndAddToZones_DoesNothing_WhenCellIsNull()
{
Rules rules = new Rules();
Map map = new Map("background");
rules.IsZoneValidAndAddToZones(null, map);
Assert.Empty(map.Zones);
}
[Fact]
public void IsZoneValidAndAddToZones_DoesNothing_WhenCellValueIsNull()
{
Rules rules = new Rules();
Map map = new Map("background");
Cell cell = new Cell(0, 0);
rules.IsZoneValidAndAddToZones(cell, map);
Assert.Empty(map.Zones);
}
[Fact]
public void IsZoneValidAndAddToZones_AddsToExistingZone_WhenAdjacentCellWithSameValueExists()
{
Rules rules = new Rules();
Map map = new Map("background");
Cell cell = new Cell(0, 0);
cell.Value = 1;
Cell adjacentCell = new Cell(0, 1);
adjacentCell.Value = 1;
map.Boards.Add(adjacentCell);
map.Zones.Add(new List<Cell> { adjacentCell });
rules.IsZoneValidAndAddToZones(cell, map);
Assert.Contains(cell, map.Zones[0]);
}
[Fact]
public void IsZoneValidAndAddToZones_CreatesNewZone_WhenAdjacentCellWithSameValueExistsButNoExistingZone()
{
Rules rules = new Rules();
Map map = new Map("background");
Cell cell = new Cell(0, 0);
cell.Value = 1;
Cell adjacentCell = new Cell(0, 1);
adjacentCell.Value = 1;
map.Boards.Add(adjacentCell);
rules.IsZoneValidAndAddToZones(cell, map);
Assert.Contains(cell, map.Zones[0]);
}
}
Loading…
Cancel
Save