Add tests and squish last bugs
This commit is contained in:
41
Memory.Test/CardTest.cs
Normal file
41
Memory.Test/CardTest.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using Memory.Logic;
|
||||
|
||||
namespace Memory.Test
|
||||
{
|
||||
[TestClass]
|
||||
public class CardTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void Matches_SameCards_ShouldEqualTrue()
|
||||
{
|
||||
Card card1 = new(0);
|
||||
Card card2 = new(0);
|
||||
Assert.IsTrue(card1.Matches(card2));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Matches_DifferentCard_ShouldEqualFalse()
|
||||
{
|
||||
Card card1 = new(0);
|
||||
Card card2 = new(1);
|
||||
Assert.IsFalse(card1.Matches(card2));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Selected_IsSelected_ShouldEqualTrue()
|
||||
{
|
||||
Card card = new(0)
|
||||
{
|
||||
IsChoice1 = true
|
||||
};
|
||||
Assert.IsTrue(card.Selected());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Selected_NotSelected_ShouldEqualFalse()
|
||||
{
|
||||
Card card = new(0);
|
||||
Assert.IsFalse(card.Selected());
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,71 @@ 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()
|
||||
{
|
||||
@ -15,30 +80,48 @@ namespace Memory.Test
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IncreaseScore_QuarterTime_ShouldEqual75PercentOfPoints()
|
||||
public void GetChoice1ClickCard_ShouldEqualToCard()
|
||||
{
|
||||
int score = (int)(Game.MAXPOINTS * 0.75);
|
||||
Game game = new(new ScoreHandler(), "test");
|
||||
Thread.Sleep(Game.MAXTIME / 4);
|
||||
game.IncreaseScore();
|
||||
Assert.IsTrue(score - 1 <= game.Scoring.Points && score + 1 >= game.Scoring.Points);
|
||||
Game game = new(new ScoreHandler(), "test", 10);
|
||||
game.ClickCard(game.Cards[0]);
|
||||
Assert.AreEqual(game.Cards[0], game.GetChoice1());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IncreaseScore_TooLong_ShouldEqualLowerBoundOfPoints()
|
||||
public void GetChoice2ClickCard_ShouldEqualToCard()
|
||||
{
|
||||
Game game = new(new ScoreHandler(), "test");
|
||||
Thread.Sleep(Game.MAXTIME);
|
||||
game.IncreaseScore();
|
||||
Assert.AreEqual(Game.MINPOINTS, game.Scoring.Points);
|
||||
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 IncreaseScore_Instant_ShouldEqualUpperBoundOfPoints()
|
||||
public void ClickCard_DuplicateCard_Card2ShouldBeNull()
|
||||
{
|
||||
Game game = new(new ScoreHandler(), "test");
|
||||
game.IncreaseScore();
|
||||
Assert.AreEqual(Game.MAXPOINTS, game.Scoring.Points);
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user