CheckAnswer() 공개 메소드

public CheckAnswer ( string answer ) : bool
answer string
리턴 bool
예제 #1
0
        public void CheckCalculationOperator()
        {
            GameAnswer answer = new GameAnswer ();
            answer.Correct = "+ | -";
            answer.CheckExpression = "[+*-/]";
            answer.CheckAttributes = GameAnswerCheckAttributes.Trim | GameAnswerCheckAttributes.MatchAllInOrder;

            Assert.AreEqual (true, answer.CheckAnswer ("+ i -"));
            Assert.AreEqual (true, answer.CheckAnswer ("+ and -"));
            Assert.AreEqual (true, answer.CheckAnswer ("+ -"));
            Assert.AreEqual (true, answer.CheckAnswer ("+-"));

            Assert.AreEqual (false, answer.CheckAnswer ("- +"));
        }
예제 #2
0
        public void CheckPuzzlePercentage()
        {
            GameAnswer answer = new GameAnswer ();

            answer.Correct = "10";
            answer.CheckExpression = "[0-9]+";

            Assert.AreEqual (true, answer.CheckAnswer ("10%"));
            Assert.AreEqual (true, answer.CheckAnswer ("10 %"));
            Assert.AreEqual (true, answer.CheckAnswer ("10"));

            answer.Correct = "9";
            Assert.AreEqual (true, answer.CheckAnswer ("9%"));
            Assert.AreEqual (true, answer.CheckAnswer ("9 %"));
            Assert.AreEqual (true, answer.CheckAnswer ("9"));
        }
예제 #3
0
        public void CheckPuzzleBuildTriangle()
        {
            GameAnswer answer = new GameAnswer ();

            answer.Correct = "A | B | C";
            answer.CheckExpression = "[ABCDF]";
            answer.CheckAttributes = GameAnswerCheckAttributes.Trim | GameAnswerCheckAttributes.IgnoreCase | GameAnswerCheckAttributes.MatchAll;

            Assert.AreEqual (true, answer.CheckAnswer ("A B C"));
            Assert.AreEqual (true, answer.CheckAnswer ("C B A"));
            Assert.AreEqual (true, answer.CheckAnswer ("B C A"));
            Assert.AreEqual (true, answer.CheckAnswer ("A B C"));
            Assert.AreEqual (true, answer.CheckAnswer ("C A B"));
            Assert.AreEqual (true, answer.CheckAnswer ("a b c"));

            Assert.AreEqual (false, answer.CheckAnswer ("B C C"));
            Assert.AreEqual (false, answer.CheckAnswer ("B C"));
            Assert.AreEqual (false, answer.CheckAnswer ("BC"));
        }
예제 #4
0
        public void CheckPuzzleTimeNowAnswer()
        {
            GameAnswer answer = new GameAnswer ();
            answer.Correct = "10 PM";
            answer.CheckAttributes = GameAnswerCheckAttributes.Trim | GameAnswerCheckAttributes.IgnoreCase | GameAnswerCheckAttributes.IgnoreSpaces;

            Assert.AreEqual (true, answer.CheckAnswer ("10 PM"));
            Assert.AreEqual (true, answer.CheckAnswer ("10 pm"));
            Assert.AreEqual (true, answer.CheckAnswer ("10pm"));
            Assert.AreEqual (true, answer.CheckAnswer ("10Pm"));
            Assert.AreEqual (true, answer.CheckAnswer (" 10Pm "));

            Assert.AreEqual (false, answer.CheckAnswer ("10 P"));
            Assert.AreEqual (false, answer.CheckAnswer ("10"));
        }
예제 #5
0
        public void Trim()
        {
            GameAnswer answer = new GameAnswer ();

            answer.CheckAttributes = GameAnswerCheckAttributes.None;
            answer.Correct = "icon";
            Assert.AreEqual (true, answer.CheckAnswer ("icon"));
            Assert.AreEqual (false, answer.CheckAnswer (" icon "));

            answer.CheckAttributes = GameAnswerCheckAttributes.Trim;
            Assert.AreEqual (true, answer.CheckAnswer ("icon"));
            Assert.AreEqual (true, answer.CheckAnswer (" icon "));

            answer.CheckAttributes = GameAnswerCheckAttributes.MatchAll;
            Assert.AreEqual (true, answer.CheckAnswer ("icon"));
            Assert.AreEqual (false, answer.CheckAnswer (" icon "));

            answer.CheckAttributes = GameAnswerCheckAttributes.Trim | GameAnswerCheckAttributes.MatchAll;
            Assert.AreEqual (true, answer.CheckAnswer ("icon"));
            Assert.AreEqual (true, answer.CheckAnswer (" icon "));
        }
예제 #6
0
        public void TwoNumbersAnswer()
        {
            GameAnswer answer = new GameAnswer ();
            answer.Correct = "10 | 20";
            answer.CheckExpression = "[0-9]+";
            answer.CheckAttributes = GameAnswerCheckAttributes.Trim | GameAnswerCheckAttributes.MatchAll;

            // Right answers
            Assert.AreEqual (true, answer.CheckAnswer ("10 and 20"));
            Assert.AreEqual (true, answer.CheckAnswer ("10 i 20"));
            Assert.AreEqual (true, answer.CheckAnswer ("10 y 20"));
            Assert.AreEqual (true, answer.CheckAnswer ("10 20"));
            Assert.AreEqual (true, answer.CheckAnswer (" 10 20 "));

            Assert.AreEqual (true, answer.CheckAnswer ("20 and 10"));
            Assert.AreEqual (true, answer.CheckAnswer ("20 i 10"));
            Assert.AreEqual (true, answer.CheckAnswer ("20 y 10"));
            Assert.AreEqual (true, answer.CheckAnswer ("20 10"));
            Assert.AreEqual (true, answer.CheckAnswer (" 20 10 "));

            // Invalid answers
            Assert.AreEqual (false, answer.CheckAnswer (" 10 30 "));
            Assert.AreEqual (false, answer.CheckAnswer ("10"));
            Assert.AreEqual (false, answer.CheckAnswer ("20"));
            Assert.AreEqual (false, answer.CheckAnswer ("10 2"));
        }
예제 #7
0
        public void MatchAllCheatNumbers()
        {
            GameAnswer answer = new GameAnswer ();

            answer.CheckAttributes = GameAnswerCheckAttributes.MatchAll;
            answer.CheckExpression = "[0-9]+";
            answer.Correct = "10 | 20 | 30";
            Assert.AreEqual (false, answer.CheckAnswer ("10 20 30 40 50"));
        }
예제 #8
0
        public void MatchAllInOder()
        {
            GameAnswer answer = new GameAnswer ();

            answer.CheckAttributes = GameAnswerCheckAttributes.MatchAllInOrder;
            answer.CheckExpression = "[0-9]+";
            answer.Correct = "10 | 20 | 30";

            Assert.AreEqual (true, answer.CheckAnswer ("10 20 30"));
            Assert.AreEqual (false, answer.CheckAnswer ("30 20 10"));
            Assert.AreEqual (false, answer.CheckAnswer ("i"));
        }
예제 #9
0
        public void MatchAllCheatMultiOption()
        {
            GameAnswer answer = new GameAnswer ();

            answer.CheckAttributes |= GameAnswerCheckAttributes.MatchAll | GameAnswerCheckAttributes.MultiOption | GameAnswerCheckAttributes.IgnoreSpaces;
            answer.CheckExpression = "[ABCDEFGH]";
            answer.Correct = "A | B | C";
            Assert.AreEqual (false, answer.CheckAnswer ("A B C D"));
        }
예제 #10
0
        public void IgnoreSpaces()
        {
            GameAnswer answer = new GameAnswer ();

            answer.CheckAttributes = GameAnswerCheckAttributes.None;
            answer.Correct = "10 pm";
            Assert.AreEqual (true, answer.CheckAnswer ("10 pm"));
            Assert.AreEqual (false, answer.CheckAnswer ("10pm"));

            answer.CheckAttributes = GameAnswerCheckAttributes.IgnoreSpaces;
            Assert.AreEqual (true, answer.CheckAnswer ("10 pm"));
            Assert.AreEqual (true, answer.CheckAnswer ("10pm"));

            answer.CheckAttributes = GameAnswerCheckAttributes.MatchAll;
            Assert.AreEqual (true, answer.CheckAnswer ("10 pm"));
            Assert.AreEqual (false, answer.CheckAnswer ("10pm"));

            answer.CheckAttributes = GameAnswerCheckAttributes.IgnoreSpaces | GameAnswerCheckAttributes.MatchAll;
            Assert.AreEqual (true, answer.CheckAnswer ("10 pm"));
            Assert.AreEqual (true, answer.CheckAnswer ("10pm"));
        }
예제 #11
0
        public void IgnoreCase()
        {
            GameAnswer answer = new GameAnswer ();

            answer.CheckAttributes = GameAnswerCheckAttributes.None;
            answer.Correct = "icon";
            Assert.AreEqual (true, answer.CheckAnswer ("icon"));
            Assert.AreEqual (false, answer.CheckAnswer ("ICON"));

            answer.CheckAttributes = GameAnswerCheckAttributes.IgnoreCase;
            Assert.AreEqual (true, answer.CheckAnswer ("icon"));
            Assert.AreEqual (true, answer.CheckAnswer ("ICON"));

            answer.CheckAttributes = GameAnswerCheckAttributes.MatchAll;
            Assert.AreEqual (true, answer.CheckAnswer ("icon"));
            Assert.AreEqual (false, answer.CheckAnswer ("ICON"));

            answer.CheckAttributes = GameAnswerCheckAttributes.IgnoreCase | GameAnswerCheckAttributes.MatchAll;
            Assert.AreEqual (true, answer.CheckAnswer ("icon"));
            Assert.AreEqual (true, answer.CheckAnswer ("ICON"));
        }
예제 #12
0
        public void DefaultAnswerOptions()
        {
            GameAnswer answer = new GameAnswer ();

            answer.Correct = "option1 | option2";
            Assert.AreEqual (true, answer.CheckAnswer ("option1"));
            Assert.AreEqual (true, answer.CheckAnswer ("option2"));
            Assert.AreEqual (true, answer.CheckAnswer (" option2 "));

            Assert.AreEqual (false, answer.CheckAnswer ("option3"));
        }
예제 #13
0
        public void DefaultAnswer()
        {
            GameAnswer answer = new GameAnswer ();

            answer.Correct = "icon";
            Assert.AreEqual (true, answer.CheckAnswer ("icon"));

            answer.Correct = "icona";
            Assert.AreEqual (true, answer.CheckAnswer ("icona"));
        }