127 lines
3.9 KiB
C#
127 lines
3.9 KiB
C#
using Memory.Logic;
|
|
using Memory.Data;
|
|
|
|
namespace Memory.Test
|
|
{
|
|
[TestClass]
|
|
public class GameTest
|
|
{
|
|
[TestMethod]
|
|
public void CalculateScore_4Cards10Seconds2Attempts_ShouldEqual800()
|
|
{
|
|
Game game = new(new ScoreHandler(), "test", 2)
|
|
{
|
|
Attempts = 2
|
|
};
|
|
game.CalculateScore(game.StartTime + 10000);
|
|
Assert.AreEqual(800, game.Scoring.Points);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CalculateScore_10Cards20Seconds5Attempts_ShouldEqual1000()
|
|
{
|
|
Game game = new(new ScoreHandler(), "test", 5)
|
|
{
|
|
Attempts = 5
|
|
};
|
|
game.CalculateScore(game.StartTime + 20000);
|
|
Assert.AreEqual(1000, game.Scoring.Points);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CalculateScore_4Cards20Seconds2Attempts_ShouldEqual400()
|
|
{
|
|
Game game = new(new ScoreHandler(), "test", 2)
|
|
{
|
|
Attempts = 2
|
|
};
|
|
game.CalculateScore(game.StartTime + 20000);
|
|
Assert.AreEqual(400, game.Scoring.Points);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CalculateScore_4Cards10Seconds3Attempts_ShouldEqual533()
|
|
{
|
|
Game game = new(new ScoreHandler(), "test", 2)
|
|
{
|
|
Attempts = 3
|
|
};
|
|
game.CalculateScore(game.StartTime + 10000);
|
|
Assert.AreEqual(533, game.Scoring.Points);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void GetGridSize_20Cards_ShouldEqual4By5()
|
|
{
|
|
Deck grid = Game.GetGridSize(10);
|
|
Assert.IsTrue(grid.Columns == 4 && grid.Rows == 5);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void GetGridSize_10Cards_ShouldEqual2By5()
|
|
{
|
|
Deck grid = Game.GetGridSize(5);
|
|
Assert.IsTrue(grid.Columns == 2 && grid.Rows == 5);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void GetGridSize_4Cards_ShouldEqual2By2()
|
|
{
|
|
Deck grid = Game.GetGridSize(2);
|
|
Assert.IsTrue(grid.Columns == 2 && grid.Rows == 2);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CreateDeck_20pairs_ShouldEqual40RandomCards()
|
|
{
|
|
List<Card> deck1 = Game.CreateDeck(20);
|
|
List<Card> deck2 = Game.CreateDeck(20);
|
|
Assert.IsTrue(deck1.Count == 40 && deck2.Count == 40 && !deck1.SequenceEqual(deck2));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void GetChoice1ClickCard_ShouldEqualToCard()
|
|
{
|
|
Game game = new(new ScoreHandler(), "test", 10);
|
|
game.ClickCard(game.Cards[0]);
|
|
Assert.AreEqual(game.Cards[0], game.GetChoice1());
|
|
}
|
|
|
|
[TestMethod]
|
|
public void GetChoice2ClickCard_ShouldEqualToCard()
|
|
{
|
|
Game game = new(new ScoreHandler(), "test", 10);
|
|
game.ClickCard(game.Cards[0]);
|
|
game.ClickCard(game.Cards[1]);
|
|
Assert.AreEqual(game.Cards[1], game.GetChoice2());
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ClickCard_DuplicateCard_Card2ShouldBeNull()
|
|
{
|
|
Game game = new(new ScoreHandler(), "test", 10);
|
|
game.ClickCard(game.Cards[0]);
|
|
game.ClickCard(game.Cards[0]);
|
|
Assert.IsNull(game.GetChoice2());
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ClickCard_CompletedCard1_CardShouldBeNull()
|
|
{
|
|
Game game = new(new ScoreHandler(), "test", 10);
|
|
game.Cards[0].Completed = true;
|
|
game.ClickCard(game.Cards[0]);
|
|
Assert.IsNull(game.GetChoice1());
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ClickCard_CompletedCard2_CardShouldBeNull()
|
|
{
|
|
Game game = new(new ScoreHandler(), "test", 10);
|
|
game.Cards[1].Completed = true;
|
|
game.ClickCard(game.Cards[0]);
|
|
game.ClickCard(game.Cards[1]);
|
|
Assert.IsNull(game.GetChoice2());
|
|
}
|
|
}
|
|
} |