Commit pour garder mais un test ne fonctionne pas du tout

pull/111/head
Remi NEVEU 11 months ago
parent 49ee464ed2
commit fb1676b335

@ -459,5 +459,41 @@ namespace Models.Game
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public int CalculusOfPenalty(ReadOnlyCollection<Cell> Boards)
{
int result = 0;
foreach (var cells in Boards)
if (cells.Penalty)
{
if (cells.Valid == false || cells.Value == null)
continue;
result += 3;
}
return result;
}
public void PutPenaltyForLostCells(ReadOnlyCollection<Cell> Boards)
{
foreach (var cells in Boards)
{
if (cells == null || cells.Value == null || cells.Valid == false)
continue;
if (!UsedMap.IsCellInZones(cells) || !UsedMap.IsCellInRopePath(cells))
cells.SetPenalty();
}
}
public int FinalCalculusOfPoints()
{
int? points = GameRules.FinalCalculusOfZones(UsedMap.Zones);
for (int i = 0; i < UsedMap.RopePaths.Count; i++)
{
points += GameRules.ScoreRopePaths(UsedMap.RopePaths[i]);
}
points += CalculusOfPenalty(UsedMap.Boards);
return points ?? 0;
}
}
}

@ -118,5 +118,29 @@ namespace Models.Game
{
return OperationGrid[x * 4 + 3].IsChecked;
}
public bool IsCellInZones(Cell cell)
{
foreach (var zone in Zones)
{
if (zone.Contains(cell))
{
return true;
}
}
return false;
}
public bool IsCellInRopePath(Cell cell)
{
foreach (var path in RopePaths)
{
if (path.Contains(cell))
{
return true;
}
}
return false;
}
}
}

@ -397,4 +397,110 @@ public class GameTests
Assert.True(_game.UsedMap.Boards[2].Penalty);
}
[Fact]
public void PutPenaltyForLostCells_ReallyPutPenalty_ForZones()
{
var player = new Player("test_player", "DefaultProfilePicture");
var map = new Map("test_name", "test_background.png");
_game.InitializeGame(map, player);
_game.UsedMap.Boards[1].Value = 5;
_game.UsedMap.Boards[2].Value = 5;
_game.UsedMap.Boards[3].Value = 5;
_game.UsedMap.Boards[0].Value = 0;
foreach (var cells in _game.UsedMap.Boards.ToList())
{
_game.GameRules.IsZoneValidAndAddToZones(cells, _game.UsedMap);
}
_game.PutPenaltyForLostCells(_game.UsedMap.Boards);
Assert.True(_game.UsedMap.Boards[0].Penalty);
}
[Fact]
public void PutPenaltyForLostCells_ReallyPutPenalty_ForRopePathes()
{
var player = new Player("test_player", "DefaultProfilePicture");
var map = new Map("test_name", "test_background.png");
_game.InitializeGame(map, player);
_game.UsedMap.Boards[1].Value = 1;
_game.UsedMap.Boards[2].Value = 2;
_game.UsedMap.Boards[3].Value = 5;
_game.UsedMap.Boards[0].Value = 0;
var methodInfo = typeof(Game).GetMethod("AddToRopePath", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(methodInfo);
foreach (var cells in _game.UsedMap.Boards.ToList())
{
methodInfo.Invoke(_game, new object[] { cells, _game.UsedMap.Boards.ToList() });
}
_game.PutPenaltyForLostCells(_game.UsedMap.Boards);
Assert.True(_game.UsedMap.Boards[3].Penalty);
}
[Fact]
public void CalculusOfPenalty_ReallyCalculusPenalty()
{
var player = new Player("test_player", "DefaultProfilePicture");
var map = new Map("test_name", "test_background.png");
_game.InitializeGame(map, player);
_game.UsedMap.Boards[0].Valid = true;
_game.UsedMap.Boards[1].Valid = true;
_game.UsedMap.Boards[2].Valid = true;
_game.UsedMap.Boards[7].Valid = true;
_game.UsedMap.Boards[8].Valid = true;
_game.UsedMap.Boards[9].Valid = true;
_game.UsedMap.Boards[10].Valid = true;
_game.UsedMap.Boards[11].Valid = true;
_game.UsedMap.Boards[12].Valid = true;
_game.UsedMap.Boards[13].Valid = true;
_game.UsedMap.Boards[0].Value = 0;
_game.UsedMap.Boards[1].Value = 1;
_game.UsedMap.Boards[2].Value = 2;
_game.UsedMap.Boards[8].Value = 5;
_game.UsedMap.Boards[7].Value = 5;
_game.UsedMap.Boards[9].Value = 5;
_game.UsedMap.Boards[10].Value = 6;
_game.UsedMap.Boards[11].IsDangerous = true;
_game.UsedMap.Boards[12].Value = 13; //One penalty because it is over 12
_game.UsedMap.Boards[13].Value = 9; //One penalty because it is lost
var place = typeof(Game).GetMethod("PlaceResult", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(place);
var cell = new Cell(1, 4);
cell.Value = 7;
cell.Valid = true;
cell.IsDangerous = true;
place.Invoke(_game, new object[] { cell, 7 }); //One penalty
var methodInfo = typeof(Game).GetMethod("AddToRopePath", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(methodInfo);
foreach (var cells in _game.UsedMap.Boards.ToList())
{
_game.GameRules.IsZoneValidAndAddToZones(cells, _game.UsedMap);
methodInfo.Invoke(_game, new object[] { cells, _game.GameRules.EveryAdjacentCells(cells, _game.UsedMap.Boards.ToList()) });
}
_game.PutPenaltyForLostCells(_game.UsedMap.Boards);
Assert.True(_game.UsedMap.Boards[10].Penalty);
Assert.True(_game.UsedMap.Boards[11].Penalty);
Assert.True(_game.UsedMap.Boards[12].Penalty);
Assert.Equal(9, _game.CalculusOfPenalty(_game.UsedMap.Boards));
}
}

@ -44,4 +44,54 @@ public class MapTests
Assert.Empty(map.RopePaths);
Assert.Empty(map.Zones);
}
[Fact]
public void IsCellInZones_FoundTheCell()
{
var map = new Map("test_name", "test_background.png");
var cell = new Cell(0, 0);
var zone = new List<Cell> { cell };
map.Zones.Add(zone);
Assert.True(map.IsCellInZones(cell));
}
[Fact]
public void IsCellInZones_DoNotFoundTheCell()
{
var map = new Map("test_name", "test_background.png");
var cell = new Cell(0, 0);
var othercell = new Cell(1, 1);
var zone = new List<Cell> { cell };
map.Zones.Add(zone);
Assert.False(map.IsCellInZones(othercell));
}
[Fact]
public void IsCellInRopePath_FoundTheCell()
{
var map = new Map("test_name", "test_background.png");
var cell = new Cell(0, 0);
var paths = new List<Cell> { cell };
map.RopePaths.Add(paths);
Assert.True(map.IsCellInRopePath(cell));
}
[Fact]
public void IsCellInRopePath_DoNotFoundTheCell()
{
var map = new Map("test_name", "test_background.png");
var cell = new Cell(0, 0);
var othercell = new Cell(1, 1);
var paths = new List<Cell> { cell };
map.RopePaths.Add(paths);
Assert.False(map.IsCellInRopePath(othercell));
}
}

Loading…
Cancel
Save