[gbrainy/gbrainy_15x] GameSession fixes + unit test



commit 7c968c64f692bcdadd8e186571050d3302147018
Author: Jordi Mas <jmas softcatala org>
Date:   Mon May 10 22:25:46 2010 +0200

    GameSession fixes + unit test

 src/Clients/Classical/gbrainy.cs   |    4 +-
 src/Core/Main/GameSession.cs       |    9 +++-
 tests/Core/AnalogiesFactoryTest.cs |   19 ++++++++
 tests/Core/GameSessionTest.cs      |   82 ++++++++++++++++++++++++++++++++++++
 tests/Makefile.am                  |    3 +-
 5 files changed, 111 insertions(+), 6 deletions(-)
---
diff --git a/src/Clients/Classical/gbrainy.cs b/src/Clients/Classical/gbrainy.cs
index 5ba245c..c457f31 100644
--- a/src/Clients/Classical/gbrainy.cs
+++ b/src/Clients/Classical/gbrainy.cs
@@ -476,7 +476,7 @@ namespace gbrainy.Clients.Classical
 		void OnNewGame (GameSession.Types type)
 		{
 			session.Type = type;
-			session.NewSession ();
+			session.New ();
 			GetNextGame ();
 			GameSensitiveUI ();
 			UpdateSolution (Catalog.GetString ("Once you have an answer type it in the \"Answer:\" entry box and press the \"OK\" button."));
@@ -542,7 +542,7 @@ namespace gbrainy.Clients.Classical
 
 		void OnEndGame (object sender, EventArgs args)
 		{
-			session.EndSession ();
+			session.End ();
 	
 			UpdateSolution (String.Empty);
 			UpdateQuestion (String.Empty);
diff --git a/src/Core/Main/GameSession.cs b/src/Core/Main/GameSession.cs
index 61fa3da..a3fd368 100644
--- a/src/Core/Main/GameSession.cs
+++ b/src/Core/Main/GameSession.cs
@@ -205,11 +205,14 @@ namespace gbrainy.Core.Main
 			}
 		}
 	
-		public void NewSession ()
+		public void New ()
 		{
+			if (Type == Types.None)
+				throw new InvalidOperationException ("You have to setup the GameSession type");
+
 			id++;
 			if (Status != SessionStatus.NotPlaying)
-				EndSession ();
+				End ();
 
 			current_time = TimeSpanToStr (game_time);
 
@@ -219,7 +222,7 @@ namespace gbrainy.Core.Main
 			EnableTimer = true;
 		}
 
-		public void EndSession ()
+		public void End ()
 		{
 			// Making a deep copy of GameSessionHistory type (base class) for serialization
 			player_history.SaveGameSession (history.Copy ());
diff --git a/tests/Core/AnalogiesFactoryTest.cs b/tests/Core/AnalogiesFactoryTest.cs
index b25cfa1..41f5787 100644
--- a/tests/Core/AnalogiesFactoryTest.cs
+++ b/tests/Core/AnalogiesFactoryTest.cs
@@ -1,3 +1,22 @@
+/*
+ * Copyright (C) 2010 Jordi Mas i Hernàndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
 using System;
 using System.Collections.Generic;
 using NUnit.Framework;
diff --git a/tests/Core/GameSessionTest.cs b/tests/Core/GameSessionTest.cs
new file mode 100644
index 0000000..bc210a3
--- /dev/null
+++ b/tests/Core/GameSessionTest.cs
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2010 Jordi Mas i Hernàndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+using System.Collections.Generic;
+using NUnit.Framework;
+
+using gbrainy.Core.Main;
+
+namespace gbrainyTest
+{
+	[TestFixture]
+	public class GameSessionTest
+	{
+		[TestFixtureSetUp]
+		public void Construct ()
+		{
+
+		}
+
+		[Test]
+		public void Status ()
+		{
+			GameSession session = new GameSession ();
+			Assert.AreEqual (GameSession.SessionStatus.NotPlaying, session.Status);
+
+			session.Type = GameSession.Types.LogicPuzzles;
+			session.New ();
+			Assert.AreEqual (GameSession.SessionStatus.NotPlaying, session.Status);
+
+			session.NextGame ();
+			Assert.AreEqual (GameSession.SessionStatus.Playing, session.Status);
+
+			session.End ();
+			Assert.AreEqual (GameSession.SessionStatus.Finished, session.Status);
+		}
+
+		[Test]
+		public void Paused ()
+		{
+			GameSession session = new GameSession ();
+			session.Type = GameSession.Types.LogicPuzzles;
+			session.New ();
+			Assert.AreEqual (GameSession.SessionStatus.NotPlaying, session.Status);
+
+			session.Pause ();
+			Assert.AreEqual (true, session.Paused);
+
+			session.Resume ();
+			Assert.AreEqual (false, session.Paused);
+		}
+
+		[Test]
+		public void ID ()
+		{
+			GameSession session = new GameSession ();
+			session.Type = GameSession.Types.LogicPuzzles;
+			session.New ();
+			Assert.AreEqual (1, session.ID);
+			session.End ();
+
+			session.New ();
+			Assert.AreEqual (2, session.ID);
+		}
+	}
+}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7d6bea7..7eb57c3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -8,7 +8,8 @@ CSFLAGS =				\
 CSFILES =					\
 	$(srcdir)/Core/AnalogiesFactoryTest.cs	\
 	$(srcdir)/Core/PlayerHistoryTest.cs	\
-	$(srcdir)/Core/PlayerPersonalRecordTest.cs
+	$(srcdir)/Core/PlayerPersonalRecordTest.cs \
+	$(srcdir)/Core/GameSessionTest.cs
 
 ASSEMBLIES = \
 	$(NUNIT_LIBS)			\



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]