From 005546e43b0c57fa67adc9da296f46ca90664212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Thu, 30 May 2024 23:37:37 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20Test=20des=20derni?= =?UTF-8?q?=C3=A8res=20r=C3=A8gles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Tests/RulesTests.cs | 243 +++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) diff --git a/source/Trek-12/Tests/RulesTests.cs b/source/Trek-12/Tests/RulesTests.cs index 56ec387..630cca2 100644 --- a/source/Trek-12/Tests/RulesTests.cs +++ b/source/Trek-12/Tests/RulesTests.cs @@ -232,4 +232,247 @@ public class RulesTests rules.IsZoneValidAndAddToZones(cell, map); Assert.Contains(cell, map.Zones[0]); } + + [Fact] + public void IsValueInZones_ReturnsFalse_WhenCellIsNull() + { + Rules rules = new Rules(); + Assert.False(rules.IsValueInZones(null, new List>())); + } + + [Fact] + public void IsValueInZones_ReturnsFalse_WhenZonesAreEmpty() + { + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + cell.Value = 1; + Assert.False(rules.IsValueInZones(cell, new List>())); + } + + [Fact] + public void IsValueInZones_ReturnsFalse_WhenNoZoneContainsCellWithSameValue() + { + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + cell.Value = 1; + List> zones = new List> + { + new List { new Cell(0, 1) { Value = 2 } }, + new List { new Cell(1, 0) { Value = 3 } } + }; + Assert.False(rules.IsValueInZones(cell, zones)); + } + + [Fact] + public void IsValueInZones_ReturnsTrue_WhenZoneContainsCellWithSameValue() + { + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + cell.Value = 1; + List> zones = new List> + { + new List { new Cell(0, 1) { Value = 1 } }, + new List { new Cell(1, 0) { Value = 3 } } + }; + Assert.True(rules.IsValueInZones(cell, zones)); + } + + [Fact] + public void IsCellInZone_ReturnsFalse_WhenCellIsNull() + { + Rules rules = new Rules(); + Assert.False(rules.IsCellInZone(null, new List>())); + } + + [Fact] + public void IsCellInZone_ReturnsFalse_WhenZonesAreEmpty() + { + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + Assert.False(rules.IsCellInZone(cell, new List>())); + } + + [Fact] + public void IsCellInZone_ReturnsFalse_WhenNoZoneContainsCell() + { + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + List> zones = new List> + { + new List { new Cell(0, 1) }, + new List { new Cell(1, 0) } + }; + Assert.False(rules.IsCellInZone(cell, zones)); + } + + [Fact] + public void IsCellInZone_ReturnsTrue_WhenZoneContainsCell() + { + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + List> zones = new List> + { + new List { new Cell(0, 1) }, + new List { cell } + }; + Assert.True(rules.IsCellInZone(cell, zones)); + } + + [Fact] + public void AddToZone_DoesNothing_WhenCellIsNull() + { + Rules rules = new Rules(); + List> zones = new List>(); + rules.AddToZone(null, zones); + Assert.Empty(zones); + } + + [Fact] + public void AddToZone_DoesNothing_WhenCellValueIsNull() + { + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + List> zones = new List>(); + rules.AddToZone(cell, zones); + Assert.Empty(zones); + } + + [Fact] + public void AddToZone_DoesNothing_WhenCellIsAlreadyInZone() + { + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + cell.Value = 1; + List> zones = new List> + { + new List { cell } + }; + rules.AddToZone(cell, zones); + Assert.Single(zones[0]); // Verify if the List has still only one element + } + + [Fact] + public void AddToZone_AddsCellToExistingZone_WhenCellHasSameValueAsZone() + { + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + cell.Value = 1; + List> zones = new List> + { + new List { new Cell(0, 1) { Value = 1 } } + }; + rules.AddToZone(cell, zones); + Assert.Contains(cell, zones[0]); + } + + [Fact] + public void NewZoneIsCreated_DoesNothing_WhenFirstCellIsNull() + { + Rules rules = new Rules(); + Map map = new Map("background"); + rules.NewZoneIsCreated(null, new Cell(0, 0), map); + Assert.Empty(map.Zones); + } + + [Fact] + public void NewZoneIsCreated_DoesNothing_WhenSecondCellIsNull() + { + Rules rules = new Rules(); + Map map = new Map("background"); + rules.NewZoneIsCreated(new Cell(0, 0), null, map); + Assert.Empty(map.Zones); + } + + [Fact] + public void NewZoneIsCreated_DoesNothing_WhenFirstCellValueIsNull() + { + Rules rules = new Rules(); + Map map = new Map("background"); + Cell firstCell = new Cell(0, 0); + rules.NewZoneIsCreated(firstCell, new Cell(0, 1), map); + Assert.Empty(map.Zones); + } + + [Fact] + public void NewZoneIsCreated_DoesNothing_WhenSecondCellValueIsNull() + { + Rules rules = new Rules(); + Map map = new Map("background"); + Cell secondCell = new Cell(0, 0); + rules.NewZoneIsCreated(new Cell(0, 1), secondCell, map); + Assert.Empty(map.Zones); + } + + [Fact] + public void NewZoneIsCreated_CreatesNewZone_WhenBothCellsAreNotNullAndHaveValues() + { + Rules rules = new Rules(); + Map map = new Map("background"); + Cell firstCell = new Cell(0, 0); + firstCell.Value = 1; + Cell secondCell = new Cell(0, 1); + secondCell.Value = 1; + rules.NewZoneIsCreated(firstCell, secondCell, map); + Assert.Single(map.Zones); + Assert.Contains(firstCell, map.Zones[0]); + Assert.Contains(secondCell, map.Zones[0]); + } + + [Fact] + public void EveryAdjacentCells_ReturnsEmptyList_WhenCellIsNull() + { + Rules rules = new Rules(); + List cells = new List { new Cell(0, 0), new Cell(0, 1) }; + Assert.Empty(rules.EveryAdjacentCells(null, cells)); + } + + [Fact] + public void EveryAdjacentCells_ReturnsEmptyList_WhenCellsAreEmpty() + { + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + Assert.Empty(rules.EveryAdjacentCells(cell, new List())); + } + + [Fact] + public void EveryAdjacentCells_ReturnsEmptyList_WhenNoAdjacentCells() + { + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + List cells = new List { new Cell(2, 2), new Cell(3, 3) }; + Assert.Empty(rules.EveryAdjacentCells(cell, cells)); + } + + [Fact] + public void EveryAdjacentCells_ReturnsListWithAdjacentCells_WhenAdjacentCellsExist() + { + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + List cells = new List { new Cell(0, 1), new Cell(1, 0), new Cell(2, 2) }; + List result = rules.EveryAdjacentCells(cell, cells); + Assert.Equal(2, result.Count); + Assert.Contains(new Cell(0, 1), result); + Assert.Contains(new Cell(1, 0), result); + } + + [Fact] + public void FinalCalculusOfZones_ReturnsZero_WhenZonesAreEmpty() + { + Rules rules = new Rules(); + Assert.Equal(0, rules.FinalCalculusOfZones(new List>())); + } + + /* + [Fact] + public void FinalCalculusOfZones_ReturnsCorrectValue_WhenZonesAreNotEmpty() + { + // TODO + } + + [Fact] + public void FinalCalculusOfZones_ReturnsCorrectValue_WhenZoneCountIsGreaterThanNine() + { + // TODO + } + */ } \ No newline at end of file From 636cc3b72244ee4827d8d86ab0a8b465c0a91391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Thu, 30 May 2024 23:38:48 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20VS=C3=83V=C3=A9rifi?= =?UTF-8?q?cation=20si=20param=C3=A8tres=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Models/Rules/Rules.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/Trek-12/Models/Rules/Rules.cs b/source/Trek-12/Models/Rules/Rules.cs index 8a7dc43..73d4467 100644 --- a/source/Trek-12/Models/Rules/Rules.cs +++ b/source/Trek-12/Models/Rules/Rules.cs @@ -174,6 +174,8 @@ namespace Models.Rules public List EveryAdjacentCells(Cell choosenCell, List cells) { List adjacentCells = new List(); + + if (choosenCell == null || cells == null) return adjacentCells; foreach (var cell in cells) { From d999520a9aac299b167f9ed803533b6e1b2a7b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi?= Date: Fri, 31 May 2024 08:28:15 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Ajout=20de=20deux=20tests=20sur=20le=20calc?= =?UTF-8?q?ul=20des=20zones=20+=20r=C3=A9solution=20d'un=20probl=C3=A8me?= =?UTF-8?q?=20sur=20le=20code=20de=20cette=20m=C3=AAme=20fonction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Models/Rules/Rules.cs | 2 +- source/Trek-12/Tests/RulesTests.cs | 55 ++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/source/Trek-12/Models/Rules/Rules.cs b/source/Trek-12/Models/Rules/Rules.cs index 73d4467..95859d7 100644 --- a/source/Trek-12/Models/Rules/Rules.cs +++ b/source/Trek-12/Models/Rules/Rules.cs @@ -197,7 +197,7 @@ namespace Models.Rules calculus += zones[i].Count - 1 + zones[i][0].Value; if (zones[i].Count > 9) { - calculus += (zones[i].Count - 9) * 5; + calculus += (zones[i].Count - 9) * 5 - (zones[i].Count - 9); } } return calculus; diff --git a/source/Trek-12/Tests/RulesTests.cs b/source/Trek-12/Tests/RulesTests.cs index 630cca2..7cfe05a 100644 --- a/source/Trek-12/Tests/RulesTests.cs +++ b/source/Trek-12/Tests/RulesTests.cs @@ -462,17 +462,64 @@ public class RulesTests Assert.Equal(0, rules.FinalCalculusOfZones(new List>())); } - /* [Fact] public void FinalCalculusOfZones_ReturnsCorrectValue_WhenZonesAreNotEmpty() { - // TODO + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + cell.Value = 1; + Cell cell1 = new Cell(0, 1); + cell1.Value = 1; + Cell cell2 = new Cell(0, 2); + cell2.Value = 1; + Cell uncell = new Cell(0, 0); + uncell.Value = 4; + Cell deuxcell = new Cell(0, 1); + deuxcell.Value = 4; + Cell troiscell = new Cell(0, 2); + troiscell.Value = 4; + List> zones = new List> + { + new List { cell, cell1, cell2 }, + new List { uncell, deuxcell, troiscell } + }; + + Assert.Equal(9, rules.FinalCalculusOfZones(zones)); } [Fact] public void FinalCalculusOfZones_ReturnsCorrectValue_WhenZoneCountIsGreaterThanNine() { - // TODO + Rules rules = new Rules(); + Cell cell = new Cell(0, 0); + cell.Value = 5; + Cell cell1 = new Cell(0, 1); + cell1.Value = 5; + Cell cell2 = new Cell(0, 2); + cell2.Value = 5; + Cell cell3 = new Cell(0, 3); + cell3.Value = 5; + Cell cell4 = new Cell(0, 4); + cell4.Value = 5; + Cell cell5 = new Cell(0, 5); + cell5.Value = 5; + Cell cell6 = new Cell(1, 0); + cell6.Value = 5; + Cell cell7 = new Cell(1, 1); + cell7.Value = 5; + Cell cell8 = new Cell(1, 2); + cell8.Value = 5; + Cell cell9 = new Cell(1, 3); + cell9.Value = 5; + Cell cell10 = new Cell(1, 4); + cell10.Value = 5; + + List> zones = new List> + { + new List { cell, cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8, cell9, cell10 } + }; + + Assert.Equal(23, rules.FinalCalculusOfZones(zones)); } - */ + } \ No newline at end of file From be61f9dd7ef4ceb40deaf65b9eb3224acb6ad16d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi?= Date: Fri, 31 May 2024 09:53:17 +0200 Subject: [PATCH 4/4] =?UTF-8?q?Ajout=20d'=C3=A9bauches=20de=20tests=20pour?= =?UTF-8?q?=20GameTests=20mais=20non=20fonctionnelles=20(check=20pour=20ut?= =?UTF-8?q?iliser=20reflection)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Tests/GameTests.cs | 96 +++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 source/Trek-12/Tests/GameTests.cs diff --git a/source/Trek-12/Tests/GameTests.cs b/source/Trek-12/Tests/GameTests.cs new file mode 100644 index 0000000..7f0abee --- /dev/null +++ b/source/Trek-12/Tests/GameTests.cs @@ -0,0 +1,96 @@ +namespace Tests; +using Models.Game; +using System.Reflection; +using static System.Type; +public class GameTests +{ + [Fact] + public void Game_Initialization_SetsPlayer() + { + Player player = new Player("test_player"); + Map map = new Map("test_background"); + + var game = new Game(player, map); + + Assert.Equal(player, game.CurrentPlayer); + } + + [Fact] + public void Initialize_Turn_1() + { + Player player = new Player("test_player"); + Map map = new Map("test_background"); + + Game test = new Game(player, map); + + typeof(Game).GetProperty("Turn").SetValue(test, 1); + + + var result = test.GetResult(); + + Assert.Equal(typeof(Game).GetProperty("Turn").GetValue(test.Turn), 1); + } + /* + [Fact] + public void Game_Initialization_SetsMap() + { + Player player = new Player("test_player"); + Map map = new Map("test_background"); + + var game = new Game(player, map); + + Assert.Equal(map, game.UsedMap); + } + + [Fact] + public void Game_Initialization_SetsDice() + { + Player player = new Player("test_player"); + Map map = new Map("test_background"); + + var game = new Game(player, map); + + Assert.NotNull(game.Dice1); + Assert.NotNull(game.Dice2); + } + + [Fact] + public void Game_Initialization_SetsGameRules() + { + Player player = new Player("test_player"); + Map map = new Map("test_background"); + + var game = new Game(player, map); + + Assert.NotNull(game.GameRules); + } + + [Fact] + public void RollAllDice_RollsAllDice() + { + Player player = new Player("test_player"); + Map map = new Map("test_background"); + + var game = new Game(player, map); + + game.RollAllDice(); + + Assert.True(game.Dice1.Value >= 0 && game.Dice1.Value <= 5); + Assert.True(game.Dice2.Value >= 1 && game.Dice2.Value <= 6); + } + + [Fact] + public void MarkOperationAsChecked_Check_Well() + { + Player player = new Player("test_player"); + Map map = new Map("test_background"); + + var game = new Game(player, map); + + game.MarkOperationAsChecked(Operation.LOWER); + + Assert.True(game.UsedMap.OperationGrid[0].IsChecked); + } + + */ +}