|
|
@ -0,0 +1,305 @@ |
|
|
|
using MiniGames.Shared.Models; |
|
|
|
using Xunit; |
|
|
|
|
|
|
|
namespace MiniGamesTests |
|
|
|
{ |
|
|
|
public class TicTacToeBrettTest |
|
|
|
{ |
|
|
|
public TicTacToeBrett TestBrett( |
|
|
|
int a = TicTacToeBrett.LEER, int b = TicTacToeBrett.LEER, int c = TicTacToeBrett.LEER, |
|
|
|
int d = TicTacToeBrett.LEER, int e = TicTacToeBrett.LEER, int f = TicTacToeBrett.LEER, |
|
|
|
int g = TicTacToeBrett.LEER, int h = TicTacToeBrett.LEER, int i = TicTacToeBrett.LEER |
|
|
|
) |
|
|
|
{ |
|
|
|
return new( |
|
|
|
new int[,] |
|
|
|
{ |
|
|
|
{ a, b, c, }, |
|
|
|
{ d, e, f, }, |
|
|
|
{ g, h, i, }, |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Set_FreiesFeldBelegenTest() |
|
|
|
{ |
|
|
|
// arrange
|
|
|
|
TicTacToeBrett brett = new(); |
|
|
|
TicTacToeBrett erwartetesBrett = TestBrett( |
|
|
|
TicTacToeBrett.LEER, |
|
|
|
TicTacToeBrett.LEER, |
|
|
|
TicTacToeBrett.LEER, |
|
|
|
TicTacToeBrett.LEER, |
|
|
|
0 |
|
|
|
); |
|
|
|
int pos = 4; |
|
|
|
int wert = 0; |
|
|
|
bool erwartetGesetzt = true; |
|
|
|
|
|
|
|
// act
|
|
|
|
bool erhaltenGesetzt = brett.Set(pos, wert); |
|
|
|
|
|
|
|
// assert
|
|
|
|
Assert.Equal(erwartetGesetzt, erhaltenGesetzt); |
|
|
|
Assert.True(brett.Gleich(erwartetesBrett)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Set_BelegtesFeldBelegenTest() |
|
|
|
{ |
|
|
|
// arrange
|
|
|
|
TicTacToeBrett brett = TestBrett(1); |
|
|
|
TicTacToeBrett erwartetesBrett = TestBrett(1); |
|
|
|
int pos = 0; |
|
|
|
int wert = 1; |
|
|
|
bool erwartetGesetzt = false; |
|
|
|
|
|
|
|
// act
|
|
|
|
bool erhaltenGesetzt = brett.Set(pos, wert); |
|
|
|
|
|
|
|
// assert
|
|
|
|
Assert.Equal(erwartetGesetzt, erhaltenGesetzt); |
|
|
|
Assert.True(brett.Gleich(erwartetesBrett)); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData(-1)] |
|
|
|
[InlineData(9)] |
|
|
|
public void Set_OutOfBoundsTest(int pos) |
|
|
|
{ |
|
|
|
// arrange
|
|
|
|
TicTacToeBrett brett = new(); |
|
|
|
TicTacToeBrett erwartetesBrett = new(); |
|
|
|
int wert = 0; |
|
|
|
bool erwartetGesetzt = false; |
|
|
|
|
|
|
|
// act
|
|
|
|
bool erhaltenGesetzt = brett.Set(pos, wert); |
|
|
|
|
|
|
|
// assert
|
|
|
|
Assert.Equal(erwartetGesetzt, erhaltenGesetzt); |
|
|
|
Assert.True(brett.Gleich(erwartetesBrett)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Gleich_LeereBretterGleichTest() |
|
|
|
{ |
|
|
|
// arrange
|
|
|
|
TicTacToeBrett b1 = new(); |
|
|
|
TicTacToeBrett b2 = new(); |
|
|
|
bool erwartetGleich = true; |
|
|
|
|
|
|
|
// act
|
|
|
|
bool erhaltenGleich = b1.Gleich(b2); |
|
|
|
|
|
|
|
// assert
|
|
|
|
Assert.Equal(erwartetGleich, erhaltenGleich); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Gleich_NichtLeereBretterGleichTest() |
|
|
|
{ |
|
|
|
// arrange
|
|
|
|
TicTacToeBrett b1 = TestBrett(1, 2, 3, 4, 5, 6, 7, 8, 9); |
|
|
|
TicTacToeBrett b2 = TestBrett(1, 2, 3, 4, 5, 6, 7, 8, 9); |
|
|
|
bool erwartetGleich = true; |
|
|
|
|
|
|
|
// act
|
|
|
|
bool erhaltenGleich = b1.Gleich(b2); |
|
|
|
|
|
|
|
// assert
|
|
|
|
Assert.Equal(erwartetGleich, erhaltenGleich); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Gleich_ErsteUngleichTest() |
|
|
|
{ |
|
|
|
// arrange
|
|
|
|
TicTacToeBrett b1 = TestBrett(1); |
|
|
|
TicTacToeBrett b2 = TestBrett(2); |
|
|
|
bool erwartetGleich = false; |
|
|
|
|
|
|
|
// act
|
|
|
|
bool erhaltenGleich = b1.Gleich(b2); |
|
|
|
|
|
|
|
// assert
|
|
|
|
Assert.Equal(erwartetGleich, erhaltenGleich); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Gleich_LetzteUngleichTest() |
|
|
|
{ |
|
|
|
// arrange
|
|
|
|
TicTacToeBrett b1 = TestBrett(1, 2, 3, 4, 5, 6, 7, 8, 9); |
|
|
|
TicTacToeBrett b2 = TestBrett(1, 2, 3, 4, 5, 6, 7, 8, 10); |
|
|
|
bool erwartetGleich = false; |
|
|
|
|
|
|
|
// act
|
|
|
|
bool erhaltenGleich = b1.Gleich(b2); |
|
|
|
|
|
|
|
// assert
|
|
|
|
Assert.Equal(erwartetGleich, erhaltenGleich); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Voll_LeeresBrettTest() |
|
|
|
{ |
|
|
|
// arrange
|
|
|
|
TicTacToeBrett brett = TestBrett(); |
|
|
|
bool erwartetVoll = false; |
|
|
|
|
|
|
|
// act
|
|
|
|
bool erhaltenVoll = brett.Voll(); |
|
|
|
|
|
|
|
// assert
|
|
|
|
Assert.Equal(erwartetVoll, erhaltenVoll); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Voll_VollesBrettTest() |
|
|
|
{ |
|
|
|
// arrange
|
|
|
|
TicTacToeBrett brett = TestBrett(1, 2, 3, 4, 5, 6, 7, 8, 9); |
|
|
|
bool erwartetVoll = true; |
|
|
|
|
|
|
|
// act
|
|
|
|
bool erhaltenVoll = brett.Voll(); |
|
|
|
|
|
|
|
// assert
|
|
|
|
Assert.Equal(erwartetVoll, erhaltenVoll); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Voll_FastVollesBrettTest() |
|
|
|
{ |
|
|
|
// arrange
|
|
|
|
TicTacToeBrett brett = TestBrett(1, 2, 3, 4, 5, 6, 7, 8); |
|
|
|
bool erwartetVoll = false; |
|
|
|
|
|
|
|
// act
|
|
|
|
bool erhaltenVoll = brett.Voll(); |
|
|
|
|
|
|
|
// assert
|
|
|
|
Assert.Equal(erwartetVoll, erhaltenVoll); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Gewinner_LeeresFeldTest() |
|
|
|
{ |
|
|
|
// arrange
|
|
|
|
TicTacToeBrett brett = TestBrett(); |
|
|
|
int erwarteterGewinner = TicTacToeBrett.LEER; |
|
|
|
|
|
|
|
// act
|
|
|
|
int erhaltenerGewinner = brett.Gewinner(); |
|
|
|
|
|
|
|
// assert
|
|
|
|
Assert.Equal(erwarteterGewinner, erhaltenerGewinner); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
// Vertikale Reihe 1
|
|
|
|
[InlineData(0, |
|
|
|
0, 0, 0, |
|
|
|
TicTacToeBrett.LEER, TicTacToeBrett.LEER, TicTacToeBrett.LEER, |
|
|
|
TicTacToeBrett.LEER, TicTacToeBrett.LEER, TicTacToeBrett.LEER |
|
|
|
)] |
|
|
|
// Vertikale Reihe 2
|
|
|
|
[InlineData(1, |
|
|
|
TicTacToeBrett.LEER, TicTacToeBrett.LEER, TicTacToeBrett.LEER, |
|
|
|
1, 1, 1, |
|
|
|
TicTacToeBrett.LEER, TicTacToeBrett.LEER, TicTacToeBrett.LEER |
|
|
|
)] |
|
|
|
// Vertikale Reihe 3
|
|
|
|
[InlineData(2, |
|
|
|
TicTacToeBrett.LEER, TicTacToeBrett.LEER, TicTacToeBrett.LEER, |
|
|
|
TicTacToeBrett.LEER, TicTacToeBrett.LEER, TicTacToeBrett.LEER, |
|
|
|
2, 2, 2 |
|
|
|
)] |
|
|
|
// Horizontale Reihe 1
|
|
|
|
[InlineData(3, |
|
|
|
3, TicTacToeBrett.LEER, TicTacToeBrett.LEER, |
|
|
|
3, TicTacToeBrett.LEER, TicTacToeBrett.LEER, |
|
|
|
3, TicTacToeBrett.LEER, TicTacToeBrett.LEER |
|
|
|
)] |
|
|
|
// Horizontale Reihe 2
|
|
|
|
[InlineData(4, |
|
|
|
TicTacToeBrett.LEER, 4, TicTacToeBrett.LEER, |
|
|
|
TicTacToeBrett.LEER, 4, TicTacToeBrett.LEER, |
|
|
|
TicTacToeBrett.LEER, 4, TicTacToeBrett.LEER |
|
|
|
)] |
|
|
|
// Horizontale Reihe 3
|
|
|
|
[InlineData(5, |
|
|
|
TicTacToeBrett.LEER, TicTacToeBrett.LEER, 5, |
|
|
|
TicTacToeBrett.LEER, TicTacToeBrett.LEER, 5, |
|
|
|
TicTacToeBrett.LEER, TicTacToeBrett.LEER, 5 |
|
|
|
)] |
|
|
|
// Diagonale Reihe links oben nach rechts unten
|
|
|
|
[InlineData(6, |
|
|
|
6, TicTacToeBrett.LEER, TicTacToeBrett.LEER, |
|
|
|
TicTacToeBrett.LEER, 6, TicTacToeBrett.LEER, |
|
|
|
TicTacToeBrett.LEER, TicTacToeBrett.LEER, 6 |
|
|
|
)] |
|
|
|
// Diagonale Reihe rechts oben nach links unten
|
|
|
|
[InlineData(7, |
|
|
|
TicTacToeBrett.LEER, TicTacToeBrett.LEER, 7, |
|
|
|
TicTacToeBrett.LEER, 7, TicTacToeBrett.LEER, |
|
|
|
7, TicTacToeBrett.LEER, TicTacToeBrett.LEER |
|
|
|
)] |
|
|
|
public void Gewinner_VolleReihenTest(int gewinner, |
|
|
|
int a = TicTacToeBrett.LEER, int b = TicTacToeBrett.LEER, int c = TicTacToeBrett.LEER, |
|
|
|
int d = TicTacToeBrett.LEER, int e = TicTacToeBrett.LEER, int f = TicTacToeBrett.LEER, |
|
|
|
int g = TicTacToeBrett.LEER, int h = TicTacToeBrett.LEER, int i = TicTacToeBrett.LEER |
|
|
|
) |
|
|
|
{ |
|
|
|
// arrange
|
|
|
|
TicTacToeBrett brett = TestBrett(a, b, c, d, e, f, g, h, i); |
|
|
|
int erwarteterGewinner = gewinner; |
|
|
|
|
|
|
|
// act
|
|
|
|
int erhaltenerGewinner = brett.Gewinner(); |
|
|
|
|
|
|
|
// assert
|
|
|
|
Assert.Equal(erwarteterGewinner, erhaltenerGewinner); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData( |
|
|
|
0, TicTacToeBrett.LEER, 0, |
|
|
|
TicTacToeBrett.LEER, TicTacToeBrett.LEER, TicTacToeBrett.LEER, |
|
|
|
0, TicTacToeBrett.LEER, 0 |
|
|
|
)] |
|
|
|
[InlineData( |
|
|
|
1, 1, TicTacToeBrett.LEER, |
|
|
|
1, 1, TicTacToeBrett.LEER, |
|
|
|
TicTacToeBrett.LEER, TicTacToeBrett.LEER, TicTacToeBrett.LEER |
|
|
|
)] |
|
|
|
[InlineData( |
|
|
|
2, TicTacToeBrett.LEER, TicTacToeBrett.LEER, |
|
|
|
2, TicTacToeBrett.LEER, 2, |
|
|
|
TicTacToeBrett.LEER, 2, 2 |
|
|
|
)] |
|
|
|
[InlineData( |
|
|
|
1, 1, 2, |
|
|
|
1, 3, 2, |
|
|
|
2, 3, 3 |
|
|
|
)] |
|
|
|
public void Gewinner_NichtVolleReihenTest( |
|
|
|
int a = TicTacToeBrett.LEER, int b = TicTacToeBrett.LEER, int c = TicTacToeBrett.LEER, |
|
|
|
int d = TicTacToeBrett.LEER, int e = TicTacToeBrett.LEER, int f = TicTacToeBrett.LEER, |
|
|
|
int g = TicTacToeBrett.LEER, int h = TicTacToeBrett.LEER, int i = TicTacToeBrett.LEER |
|
|
|
) |
|
|
|
{ |
|
|
|
// arrange
|
|
|
|
TicTacToeBrett brett = TestBrett(a, b, c, d, e, f, g, h, i); |
|
|
|
int erwarteterGewinner = TicTacToeBrett.LEER; |
|
|
|
|
|
|
|
// act
|
|
|
|
int erhaltenerGewinner = brett.Gewinner(); |
|
|
|
|
|
|
|
// assert
|
|
|
|
Assert.Equal(erwarteterGewinner, erhaltenerGewinner); |
|
|
|
} |
|
|
|
} |
|
|
|
} |