[gbrainy] Personal record only if previous > 0 and improve ut coverage
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gbrainy] Personal record only if previous > 0 and improve ut coverage
- Date: Sat, 19 Jan 2013 09:18:01 +0000 (UTC)
commit f5a801c067411a6782a22641ef4ab691abd7b488
Author: Jordi Mas <jmas softcatala org>
Date: Sat Jan 19 10:20:26 2013 +0100
Personal record only if previous > 0 and improve ut coverage
src/Core/Main/PlayerPersonalRecord.cs | 10 ++--
tests/Core/PlayerPersonalRecordTest.cs | 71 +++++++++++++++++++++++++------
2 files changed, 62 insertions(+), 19 deletions(-)
---
diff --git a/src/Core/Main/PlayerPersonalRecord.cs b/src/Core/Main/PlayerPersonalRecord.cs
index 3b59edc..1f59e43 100644
--- a/src/Core/Main/PlayerPersonalRecord.cs
+++ b/src/Core/Main/PlayerPersonalRecord.cs
@@ -42,7 +42,7 @@ namespace gbrainy.Core.Main
List <PlayerPersonalRecord> records = new List <PlayerPersonalRecord> ();
GameSessionHistory higher;
- // We can start to talk about personal records after 5 plays
+ // We can start to talk about personal records after MIN_GAMES_RECORD games played
if (last_game == -1 || games.Count < MIN_GAMES_RECORD)
return records;
@@ -65,16 +65,16 @@ namespace gbrainy.Core.Main
}
// It is a record?
- if (games[last_game].LogicScore > higher.LogicScore)
+ if (higher.LogicScore > 0 && games[last_game].LogicScore > higher.LogicScore)
records.Add (new PlayerPersonalRecord (GameTypes.LogicPuzzle, higher.LogicScore, games[last_game].LogicScore));
- if (games[last_game].MathScore > higher.MathScore)
+ if (higher.MathScore > 0 && games[last_game].MathScore > higher.MathScore)
records.Add (new PlayerPersonalRecord (GameTypes.Calculation, higher.MathScore, games[last_game].MathScore));
- if (games[last_game].MemoryScore > higher.MemoryScore)
+ if (higher.MemoryScore > 0 && games[last_game].MemoryScore > higher.MemoryScore)
records.Add (new PlayerPersonalRecord (GameTypes.Memory, higher.MemoryScore, games[last_game].MemoryScore));
- if (games[last_game].VerbalScore > higher.VerbalScore)
+ if (higher.VerbalScore > 0 && games[last_game].VerbalScore > higher.VerbalScore)
records.Add (new PlayerPersonalRecord (GameTypes.VerbalAnalogy, higher.VerbalScore, games[last_game].VerbalScore));
return records;
diff --git a/tests/Core/PlayerPersonalRecordTest.cs b/tests/Core/PlayerPersonalRecordTest.cs
index 138d36d..a1ae0de 100644
--- a/tests/Core/PlayerPersonalRecordTest.cs
+++ b/tests/Core/PlayerPersonalRecordTest.cs
@@ -36,17 +36,12 @@ namespace gbrainy.Test.Core
}
[Test]
- public void MinGamesRecord ()
+ public void MinGamesNotReached ()
{
- PlayerHistory history;
+ PlayerHistory history = new PlayerHistory () { ConfigPath = "." };
+ GameSessionHistory game = new GameSessionHistory () { GamesPlayed = Preferences.Get <int> (Preferences.MinPlayedGamesKey) };
- GameSessionHistory game = new GameSessionHistory ();
- game.GamesPlayed = Preferences.Get <int> (Preferences.MinPlayedGamesKey);
-
- history = new PlayerHistory ();
- history.ConfigPath = ".";
history.Clean ();
-
for (int i = 0; i < PlayerPersonalRecord.MIN_GAMES_RECORD - 2; i++)
{
history.SaveGameSession (game);
@@ -55,20 +50,68 @@ namespace gbrainy.Test.Core
game.LogicScore = 10;
history.SaveGameSession (game);
- Assert.AreEqual (0, history.GetLastGameRecords ().Count,
- "Did not reach MinPlayedGamesKey, the game should not be a person record yet");
+ Assert.AreEqual (0, history.GetLastGameRecords ().Count,
+ "Did not reach MinPlayedGamesKey, the game should not be a personal record yet");
+ }
+
+ [Test]
+ public void PersonalRecordDone ()
+ {
+ PlayerHistory history = new PlayerHistory () { ConfigPath = "." };
+ GameSessionHistory game = new GameSessionHistory () { GamesPlayed = Preferences.Get <int> (Preferences.MinPlayedGamesKey) };
+
+ history.Clean ();
+ for (int i = 0; i < PlayerPersonalRecord.MIN_GAMES_RECORD - 1; i++)
+ {
+ history.SaveGameSession (game);
+ }
+
+ game.LogicScore = 20;
+ history.SaveGameSession (game);
game.LogicScore = 30;
history.SaveGameSession (game);
- Assert.AreEqual (1, history.GetLastGameRecords ().Count,
- "We have just recorded a personal record");
+ Assert.AreEqual (1, history.GetLastGameRecords ().Count, "We have just recorded a personal record");
+ }
+
+ [Test]
+ public void PersonalRecordDoneButPreviousWas0 ()
+ {
+ PlayerHistory history = new PlayerHistory () { ConfigPath = "." };
+ GameSessionHistory game = new GameSessionHistory () { GamesPlayed = Preferences.Get <int> (Preferences.MinPlayedGamesKey) };
+
+ history.Clean ();
+ for (int i = 0; i < PlayerPersonalRecord.MIN_GAMES_RECORD; i++)
+ {
+ history.SaveGameSession (game);
+ }
+
+ game.LogicScore = 30;
+ history.SaveGameSession (game);
+
+ Assert.AreEqual (0, history.GetLastGameRecords ().Count, "No record since previous was 0");
+ }
+
+ [Test]
+ public void ScoreLowerThanPrevious ()
+ {
+ PlayerHistory history = new PlayerHistory () { ConfigPath = "." };
+ GameSessionHistory game = new GameSessionHistory () { GamesPlayed = Preferences.Get <int> (Preferences.MinPlayedGamesKey) };
+
+ history.Clean ();
+ for (int i = 0; i < PlayerPersonalRecord.MIN_GAMES_RECORD - 1; i++)
+ {
+ history.SaveGameSession (game);
+ }
+
+ game.LogicScore = 30;
+ history.SaveGameSession (game);
game.LogicScore = 20;
history.SaveGameSession (game);
- Assert.AreEqual (0, history.GetLastGameRecords ().Count,
- "Score saved was lower than previous, no record");
+ Assert.AreEqual (0, history.GetLastGameRecords ().Count, "Score saved was lower than previous, no record");
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]