diff --git a/Memory.Gui/MainWindow.xaml b/Memory.Gui/MainWindow.xaml
index 26473de..c0b9df9 100644
--- a/Memory.Gui/MainWindow.xaml
+++ b/Memory.Gui/MainWindow.xaml
@@ -18,7 +18,7 @@
-
+
diff --git a/Memory.Gui/MainWindow.xaml.cs b/Memory.Gui/MainWindow.xaml.cs
index 35742cb..e9faba0 100644
--- a/Memory.Gui/MainWindow.xaml.cs
+++ b/Memory.Gui/MainWindow.xaml.cs
@@ -12,6 +12,8 @@ namespace Memory.Gui
{
public const int SCOREPADDING = 160;
public const int SCOREMARGIN = 30;
+ public const int GRIDWIDTH = 700;
+ public const int GRIDHEIGHT = 500;
private Game? game;
private int deckSize = 5;
@@ -104,11 +106,11 @@ namespace Memory.Gui
}
if (rows > columns)
{
- Cards.Width /= (double)rows / columns;
+ Cards.Width = GRIDWIDTH * (double)columns / rows;
}
else if (columns > rows)
{
- Cards.Height /= (double)columns / rows;
+ Cards.Height = GRIDHEIGHT * (double)rows / columns;
}
}
diff --git a/Memory.Test/CardTest.cs b/Memory.Test/CardTest.cs
new file mode 100644
index 0000000..d5a5811
--- /dev/null
+++ b/Memory.Test/CardTest.cs
@@ -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());
+ }
+ }
+}
diff --git a/Memory.Test/GameTest.cs b/Memory.Test/GameTest.cs
index 64a8d87..be0634c 100644
--- a/Memory.Test/GameTest.cs
+++ b/Memory.Test/GameTest.cs
@@ -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());
}
}
}
\ No newline at end of file