[gbrainy] Fixes Two numbers answer checking, not allowing 'i' for example as correct answer



commit c22b18d95fe6cb46a37e3929763dbc96daea2e56
Author: Jordi Mas <jmas softcatala org>
Date:   Fri Jan 18 21:00:21 2013 +0100

    Fixes Two numbers answer checking, not allowing 'i' for example as correct answer

 src/Core/Main/GameAnswer.cs  |    9 +++++----
 tests/Core/GameAnswerTest.cs |    1 +
 2 files changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/src/Core/Main/GameAnswer.cs b/src/Core/Main/GameAnswer.cs
index 3055628..a5a718e 100644
--- a/src/Core/Main/GameAnswer.cs
+++ b/src/Core/Main/GameAnswer.cs
@@ -168,6 +168,7 @@ namespace gbrainy.Core.Main
 			Regex regex;
 			Match match;
 			bool ignore_case, ignore_spaces;
+			int matched_all_in_order = 0;
 
 			if (String.IsNullOrEmpty (answer))
 				return false;
@@ -221,14 +222,14 @@ namespace gbrainy.Core.Main
 					}
 					else //MatchAllInOrder
 					{
-						if (String.Compare (match.Value, right_answers[pos++], ignore_case) != 0)
-							return false;
-
+						if (String.Compare (match.Value, right_answers[pos++], ignore_case) == 0)
+							matched_all_in_order++;
 					}
 					match = match.NextMatch ();
 				}
 
-				if ((CheckAttributes & GameAnswerCheckAttributes.MatchAllInOrder) == GameAnswerCheckAttributes.MatchAllInOrder)
+				if ((CheckAttributes & GameAnswerCheckAttributes.MatchAllInOrder) == GameAnswerCheckAttributes.MatchAllInOrder &&
+					matched_all_in_order == right_answers.Length)
 					return true;
 
 				// Have all the expected answers been matched?
diff --git a/tests/Core/GameAnswerTest.cs b/tests/Core/GameAnswerTest.cs
index 3ae7b54..4771a09 100644
--- a/tests/Core/GameAnswerTest.cs
+++ b/tests/Core/GameAnswerTest.cs
@@ -113,6 +113,7 @@ namespace gbrainy.Test.Core
 
 			Assert.AreEqual (true, answer.CheckAnswer ("10 20 30"));
 			Assert.AreEqual (false, answer.CheckAnswer ("30 20 10"));
+			Assert.AreEqual (false, answer.CheckAnswer ("i"));
 		}
 
 		[Test]



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