From 98d7abd2547942b646f435bb60b6d806e4485357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Tue, 28 May 2024 16:18:32 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20Ajout=20du=20d=C3=A9bu?= =?UTF-8?q?t=20des=20tests=20des=20R=C3=A8gles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Tests/RulesTests.cs | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 source/Trek-12/Tests/RulesTests.cs diff --git a/source/Trek-12/Tests/RulesTests.cs b/source/Trek-12/Tests/RulesTests.cs new file mode 100644 index 0000000..2994420 --- /dev/null +++ b/source/Trek-12/Tests/RulesTests.cs @@ -0,0 +1,39 @@ +namespace Tests; +using Models.Game; +using Models.Rules; + +public class RulesTests +{ + [Fact] + public void IsCellEmpty_ReturnsTrue_WhenCellIsNull() + { + Rules rules = new Rules(); + Assert.True(rules.IsCellEmpty(null)); + } + + [Fact] + public void IsCellEmpty_ReturnsTrue_WhenCellValueIsNull() + { + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + Assert.True(rules.IsCellEmpty(cell)); + } + + [Fact] + public void IsCellEmpty_ReturnsFalse_WhenCellValueIsNotNull() + { + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + cell.Value = 1; + Assert.False(rules.IsCellEmpty(cell)); + } + + [Fact] + public void IsCellValid_ReturnsTrue_WhenCellIsEmptyAndHasAdjacentCells() + { + Rules rules = new Rules(); + Map map = new Map("background"); + Cell selectedCell = map.Boards[0]; + Assert.True(rules.IsCellValid(selectedCell, map.Boards)); + } +} \ No newline at end of file From 379c7095897a7bc9d7040b2b8ed372b2ab921460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Tue, 28 May 2024 16:58:33 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20AjAjout=20de=20=20es?= =?UTF-8?q?=20tests=20sur=20les=20cellules=20adjacentes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Tests/RulesTests.cs | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/source/Trek-12/Tests/RulesTests.cs b/source/Trek-12/Tests/RulesTests.cs index 2994420..3b6fe48 100644 --- a/source/Trek-12/Tests/RulesTests.cs +++ b/source/Trek-12/Tests/RulesTests.cs @@ -28,6 +28,16 @@ public class RulesTests Assert.False(rules.IsCellEmpty(cell)); } + [Fact] + public void IsCellValid_ReturnsFalse_WhenCellIsNotEmptyAndHasAdjacentCells() + { + Rules rules = new Rules(); + Map map = new Map("background"); + Cell selectedCell = map.Boards[0]; + selectedCell.Value = 5; + Assert.False(rules.IsCellValid(selectedCell, map.Boards)); + } + [Fact] public void IsCellValid_ReturnsTrue_WhenCellIsEmptyAndHasAdjacentCells() { @@ -36,4 +46,31 @@ public class RulesTests Cell selectedCell = map.Boards[0]; Assert.True(rules.IsCellValid(selectedCell, map.Boards)); } + + [Fact] + public void IsCellAdjacent_ReturnsFalse_WhenCellsAreNotAdjacent() + { + Rules rules = new Rules(); + Cell cell1 = new Cell(0, 0); + Cell cell2 = new Cell(2, 2); + Assert.False(rules.IsCellAdjacent(cell1, cell2)); + } + + [Fact] + public void IsCellAdjacent_ReturnsTrue_WhenCellsAreSideBySide() + { + Rules rules = new Rules(); + Cell cell1 = new Cell(0, 0); + Cell cell2 = new Cell(0, 1); + Assert.True(rules.IsCellAdjacent(cell1, cell2)); + } + + [Fact] + public void IsCellAdjacent_ReturnsTrue_WhenCellsAreDiagonal() + { + Rules rules = new Rules(); + Cell cell1 = new Cell(0, 0); + Cell cell2 = new Cell(1, 1); + Assert.True(rules.IsCellAdjacent(cell1, cell2)); + } } \ No newline at end of file From 9dc789c3ec44582e31d382c235118e5f7ac8579b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Tue, 28 May 2024 17:08:22 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20Ajout=20des=20tests=20?= =?UTF-8?q?pour=20les=20r=C3=A8gles=20decheminsde=20corde?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Tests/RulesTests.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/source/Trek-12/Tests/RulesTests.cs b/source/Trek-12/Tests/RulesTests.cs index 3b6fe48..a0e46fe 100644 --- a/source/Trek-12/Tests/RulesTests.cs +++ b/source/Trek-12/Tests/RulesTests.cs @@ -73,4 +73,26 @@ public class RulesTests Cell cell2 = new Cell(1, 1); Assert.True(rules.IsCellAdjacent(cell1, cell2)); } + + [Fact] + public void IsInRopePaths_ReturnsTrue_WhenCellsAreInRopePaths() + { + 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 { cell1, cell2 }); + Assert.True(rules.IsInRopePaths(cell2, map.RopePaths, 0)); + } + + [Fact] + public void IsInRopePaths_ReturnsFalse_WhenCellsAreNotInRopePaths() + { + 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 { cell1 }); + Assert.False(rules.IsInRopePaths(cell2, map.RopePaths, 0)); + } } \ No newline at end of file From a6ddee80afa4ce12976268271015c20ea7e03cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Tue, 28 May 2024 20:44:28 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20Ajout=20de=20tests=20s?= =?UTF-8?q?uppl=C3=A9mentaires=20pour=20d'autres=20r=C3=A8gles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Tests/RulesTests.cs | 137 +++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/source/Trek-12/Tests/RulesTests.cs b/source/Trek-12/Tests/RulesTests.cs index a0e46fe..56ec387 100644 --- a/source/Trek-12/Tests/RulesTests.cs +++ b/source/Trek-12/Tests/RulesTests.cs @@ -95,4 +95,141 @@ public class RulesTests map.RopePaths.Add(new List { 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 { cell1 }); + map.RopePaths.Add(new List { 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 { 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 { 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 { 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())); + } + + [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 cells = new List { 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 cells = new List { 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 { 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]); + } } \ No newline at end of file