You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
2.9 KiB
138 lines
2.9 KiB
using QwirkleClassLibrary.Boards;
|
|
using QwirkleClassLibrary.Players;
|
|
using QwirkleClassLibrary.Tiles;
|
|
using System.Collections.ObjectModel;
|
|
namespace TestBase;
|
|
|
|
public class TestBoard
|
|
{
|
|
public static TheoryData<bool, int, int, Shape, Color> DataBoard()
|
|
{
|
|
var data = new TheoryData<bool, int, int, Shape, Color>
|
|
{
|
|
{
|
|
true,
|
|
1,
|
|
2,
|
|
Shape.Round,
|
|
Color.Red
|
|
},
|
|
{
|
|
false,
|
|
-5,
|
|
9999,
|
|
Shape.Round,
|
|
Color.Red
|
|
}
|
|
};
|
|
return data;
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(DataBoard))]
|
|
public void Test_BoardAddSolo(bool except, int x, int y, Shape shape, Color color)
|
|
{
|
|
|
|
Tile t = new Tile(shape, color);
|
|
Board b = new Board(12, 12);
|
|
|
|
if (!except)
|
|
{
|
|
Assert.False(b.AddTileInCell(x, y, t));
|
|
return;
|
|
|
|
}
|
|
Assert.True(b.AddTileInCell(x, y, t));
|
|
}
|
|
|
|
public static TheoryData<int, int, Shape, Color> Data_BoardDouble()
|
|
{
|
|
var data = new TheoryData<int, int, Shape, Color>
|
|
{
|
|
{
|
|
1,
|
|
2,
|
|
Shape.Round,
|
|
Color.Red
|
|
}
|
|
};
|
|
|
|
return data;
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(Data_BoardDouble))]
|
|
public void Test_BoardFree(int x, int y, Shape s, Color c)
|
|
{
|
|
Tile t = new(s, c);
|
|
Board board = new Board(12, 12);
|
|
board.AddTileInCell(x, y, t);
|
|
Assert.False(board.AddTileInCell(x, y, t));
|
|
}
|
|
|
|
[Fact]
|
|
public void Test_GetCells()
|
|
{
|
|
Board board = new Board(12, 12);
|
|
|
|
Assert.Equal((12 * 12), board.GetCells().Count);
|
|
}
|
|
|
|
|
|
[Theory]
|
|
[InlineData(true)]
|
|
[InlineData(false)]
|
|
public void Test_GetOccupiedCase(bool except)
|
|
{
|
|
Board board = new Board(12, 12);
|
|
Tile tile = new Tile(Shape.Club, Color.Blue);
|
|
|
|
if (except)
|
|
{
|
|
board.AddTileInCell(1, 1, tile);
|
|
Assert.True(board.HasOccupiedCase());
|
|
return;
|
|
}
|
|
|
|
Assert.False(board.HasOccupiedCase());
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(true)]
|
|
[InlineData(false)]
|
|
public void Test_GetCellPos(bool except)
|
|
{
|
|
Board board = new Board(12, 12);
|
|
|
|
if (except)
|
|
{
|
|
Cell? c = board.GetCell(1, 1);
|
|
Assert.Equal(board.GetCell(1,1), c);
|
|
return;
|
|
}
|
|
|
|
Assert.Null(board.GetCell(900, 900));
|
|
}
|
|
[Fact]
|
|
public void Test_EventBoard()
|
|
{
|
|
Board board = new(12, 12);
|
|
Tile tile = new(Shape.Club, Color.Red);
|
|
|
|
bool eventRaised = false;
|
|
|
|
board.PropertyChanged += (sender, args) =>
|
|
{
|
|
eventRaised = true;
|
|
};
|
|
|
|
board.AddTileInCell(1, 1, tile);
|
|
|
|
Assert.True(eventRaised);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|