|
|
|
@ -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<List<Cell>>()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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<List<Cell>>()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void IsValueInZones_ReturnsFalse_WhenNoZoneContainsCellWithSameValue()
|
|
|
|
|
{
|
|
|
|
|
Rules rules = new Rules();
|
|
|
|
|
Cell cell = new Cell(0, 0);
|
|
|
|
|
cell.Value = 1;
|
|
|
|
|
List<List<Cell>> zones = new List<List<Cell>>
|
|
|
|
|
{
|
|
|
|
|
new List<Cell> { new Cell(0, 1) { Value = 2 } },
|
|
|
|
|
new List<Cell> { 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<List<Cell>> zones = new List<List<Cell>>
|
|
|
|
|
{
|
|
|
|
|
new List<Cell> { new Cell(0, 1) { Value = 1 } },
|
|
|
|
|
new List<Cell> { 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<List<Cell>>()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void IsCellInZone_ReturnsFalse_WhenZonesAreEmpty()
|
|
|
|
|
{
|
|
|
|
|
Rules rules = new Rules();
|
|
|
|
|
Cell cell = new Cell(0, 0);
|
|
|
|
|
Assert.False(rules.IsCellInZone(cell, new List<List<Cell>>()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void IsCellInZone_ReturnsFalse_WhenNoZoneContainsCell()
|
|
|
|
|
{
|
|
|
|
|
Rules rules = new Rules();
|
|
|
|
|
Cell cell = new Cell(0, 0);
|
|
|
|
|
List<List<Cell>> zones = new List<List<Cell>>
|
|
|
|
|
{
|
|
|
|
|
new List<Cell> { new Cell(0, 1) },
|
|
|
|
|
new List<Cell> { 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<List<Cell>> zones = new List<List<Cell>>
|
|
|
|
|
{
|
|
|
|
|
new List<Cell> { new Cell(0, 1) },
|
|
|
|
|
new List<Cell> { cell }
|
|
|
|
|
};
|
|
|
|
|
Assert.True(rules.IsCellInZone(cell, zones));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AddToZone_DoesNothing_WhenCellIsNull()
|
|
|
|
|
{
|
|
|
|
|
Rules rules = new Rules();
|
|
|
|
|
List<List<Cell>> zones = new List<List<Cell>>();
|
|
|
|
|
rules.AddToZone(null, zones);
|
|
|
|
|
Assert.Empty(zones);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AddToZone_DoesNothing_WhenCellValueIsNull()
|
|
|
|
|
{
|
|
|
|
|
Rules rules = new Rules();
|
|
|
|
|
Cell cell = new Cell(0, 0);
|
|
|
|
|
List<List<Cell>> zones = new List<List<Cell>>();
|
|
|
|
|
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<List<Cell>> zones = new List<List<Cell>>
|
|
|
|
|
{
|
|
|
|
|
new List<Cell> { 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<List<Cell>> zones = new List<List<Cell>>
|
|
|
|
|
{
|
|
|
|
|
new List<Cell> { 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<Cell> cells = new List<Cell> { 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<Cell>()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void EveryAdjacentCells_ReturnsEmptyList_WhenNoAdjacentCells()
|
|
|
|
|
{
|
|
|
|
|
Rules rules = new Rules();
|
|
|
|
|
Cell cell = new Cell(0, 0);
|
|
|
|
|
List<Cell> cells = new List<Cell> { 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<Cell> cells = new List<Cell> { new Cell(0, 1), new Cell(1, 0), new Cell(2, 2) };
|
|
|
|
|
List<Cell> 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<List<Cell>>()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
[Fact]
|
|
|
|
|
public void FinalCalculusOfZones_ReturnsCorrectValue_WhenZonesAreNotEmpty()
|
|
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void FinalCalculusOfZones_ReturnsCorrectValue_WhenZoneCountIsGreaterThanNine()
|
|
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|