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.
sae201_qwirkle/Qwirkle/TestBase/TestCell.cs

104 lines
2.1 KiB

using QwirkleClassLibrary.Boards;
using QwirkleClassLibrary.Tiles;
namespace TestBase;
public class TestCell
{
[Theory]
[InlineData(true, 10, 20)]
[InlineData(false, -10, -10)]
[InlineData(false, 10, -10)]
[InlineData(false, -10, 10)]
public void Test_CellConstructor(bool isValid, int x, int y)
{
if (!isValid)
{
Assert.Throws<ArgumentException>(() => new Cell(x, y));
return;
}
Cell c = new Cell(x, y);
Assert.Equal(x, c.GetX);
Assert.Equal(y, c.GetY);
}
public static TheoryData<bool, int, int, Shape, Color> Data_Cell()
{
var data = new TheoryData<bool, int, int, Shape, Color>
{
{
true,
0,
0,
Shape.Round,
Color.Red
},
{
false,
0,
0,
Shape.Round,
Color.Red
}
};
return data;
}
[Theory]
[MemberData(nameof(Data_Cell))]
public void Test_CellSetTile(bool except, int x, int y, Shape shape, Color color)
{
Tile t = new(shape, color);
Cell c = new(x, y);
if (!except)
{
c.SetTile(t);
Assert.False(c.SetTile(t));
return;
}
Assert.True(c.SetTile(t));
}
[Theory]
[MemberData(nameof(Data_Cell))]
public void Test_IsFree(bool except, int x, int y, Shape shape, Color color)
{
Tile t = new(shape, color);
Cell c = new(x, y);
if (!except)
{
c.SetTile(t);
Assert.False(c.IsFree);
return;
}
Assert.True(c.IsFree);
}
[Fact]
public void Test_EventCell()
{
Cell c = new(1,1);
Tile tile = new(Shape.Club, Color.Red);
bool eventRaised = false;
c.PropertyChanged += (sender, args) =>
{
eventRaised = true;
};
c.SetTile(tile);
Assert.True(eventRaised);
}
}