Add tests and squish last bugs
This commit is contained in:
@ -18,7 +18,7 @@
|
||||
<Button Content="←" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="30px" Margin="470,300,0,0" Click="Decrease"></Button>
|
||||
<Label Content="5" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="535,300,0,0" FontSize="30px" Name="DeckSize"></Label>
|
||||
<Button Content="→" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="30px" Margin="600,300,0,0" Click="Increase"></Button>
|
||||
<Label Content="Name must be between 2 and 32 characters." HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,320,0,0" FontSize="20" Foreground="Red" Name="ErrorLabel" Visibility="Hidden"></Label>
|
||||
<Label Content="Name must be between 2 and 32 characters." HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,335,0,0" FontSize="16" Foreground="Red" Name="ErrorLabel" Visibility="Hidden"></Label>
|
||||
<Button Content="Start" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="50px" Margin="0,360,0,0" Width="240" Height="80" Click="StartGame"></Button>
|
||||
</Grid>
|
||||
<Grid Name="GameScreen" Visibility="Visible">
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
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