예제 #1
0
            public void WHEN_ComputeSimilarityWhereString2Wrong1CharBefore_THEN_ComputedString2Shows1Gap()
            {
                testString1          = "ab";
                testString2          = "cb";
                expectedResultString = "cb";

                StringSimilarity.ComputeSimilarity(testString1, testString2);

                Assert.AreEqual(expectedResultString, StringSimilarity.GetComputedString2());
            }
예제 #2
0
            public void WHEN_ComputeSimilarityWhereString1Wrong1CharBetween_THEN_ComputedString2ShowsSame()
            {
                testString1          = "adc";
                testString2          = "abc";
                expectedResultString = "abc";

                StringSimilarity.ComputeSimilarity(testString1, testString2);

                Assert.AreEqual(expectedResultString, StringSimilarity.GetComputedString2());
            }
예제 #3
0
            public void WHEN_ComputeSimilarityWhereString2Wrong1CharAfter_THEN_ComputedString2Shows1Mismatch()
            {
                testString1          = "ab";
                testString2          = "ac";
                expectedResultString = "ac";

                StringSimilarity.ComputeSimilarity(testString1, testString2);

                Assert.AreEqual(expectedResultString, StringSimilarity.GetComputedString2());
            }
예제 #4
0
            public void WHEN_ComputeSimilarityWhereString2Missing2CharBetween_THEN_ComputedString2Shows1Gap1Mismatch()
            {
                testString1          = "abcd";
                testString2          = "ad";
                expectedResultString = "a--d";

                StringSimilarity.ComputeSimilarity(testString1, testString2);

                Assert.AreEqual(expectedResultString, StringSimilarity.GetComputedString2());
            }
예제 #5
0
            public void WHEN_ComputeSimilarityOfTwoEmptyStrings_THEN_ComputedString2IsEmpty()
            {
                testString1          = "";
                testString2          = "";
                expectedResultString = "";

                StringSimilarity.ComputeSimilarity(testString1, testString2);

                Assert.AreEqual(expectedResultString, StringSimilarity.GetComputedString2());
            }
예제 #6
0
            public void WHEN_ComputeSimilarityWhereString2Empty_THEN_ComputedString2ShowsGap()
            {
                testString1          = "1";
                testString2          = "";
                expectedResultString = "-";

                StringSimilarity.ComputeSimilarity(testString1, testString2);

                Assert.AreEqual(expectedResultString, StringSimilarity.GetComputedString2());
            }
예제 #7
0
            public void WHEN_ComputeSimilarityOfTwoIdenticalStrings_THEN_ComputedString2IsOriginal()
            {
                testString1          = "abc";
                testString2          = "abc";
                expectedResultString = "abc";

                StringSimilarity.ComputeSimilarity(testString1, testString2);

                Assert.AreEqual(expectedResultString, StringSimilarity.GetComputedString2());
            }
        /// <summary>
        /// CompareAnswerAndRecall iterates through HighlightedSquares and RecalledSquares sequences,
        /// computes the gaps and mismatches and does the mark cut down
        /// then, returns the new score
        /// </summary>
        /// <param name="oldScore">Old score</param>
        /// <param name="highlightedSquares">A sequence of index and positions of highlited squares.</param>
        /// <param name="recalledSquares">A sequence of index and positions of recalled squares.</param>
        /// <returns>New computed score.</returns>
        private static int CompareAnswerAndRecall(
            int oldScore,
            List <IndexAndPosition> highlightedSquares,
            List <IndexAndPosition> recalledSquares)
        {
            int numberOfHighlightedSquares = highlightedSquares.Count;

            string answer = "";
            string recall = "";

            // Create a string of the char indices of highlighted squares
            foreach (IndexAndPosition squareIndexAndPos in highlightedSquares)
            {
                int  intIndex  = squareIndexAndPos.Index;
                char charIndex = MatchIntIndexToCharIndex(intIndex);
                answer = answer + charIndex;
            }

            // Create a string of the indices of recalled squares
            foreach (IndexAndPosition squareIndexAndPos in recalledSquares)
            {
                int  intIndex  = squareIndexAndPos.Index;
                char charIndex = MatchIntIndexToCharIndex(intIndex);
                recall = recall + charIndex;
            }

            // Compute string similarity on the above two strings
            StringSimilarity.ComputeSimilarity(answer, recall);

            // Derive the computed strings
            // Computed strings are in char indices
            string computedAnswer = StringSimilarity.GetComputedString1();
            string computedRecall = StringSimilarity.GetComputedString2();

            int newScore = oldScore;

            // Boolean for recording if the player correctly recalls in the current round
            bool recallCorrect = true;

            // Iterate through computed strings and cut down marks:
            int lengthOfComputedAnswer = computedAnswer.Length;

            for (int i = 0; i < lengthOfComputedAnswer; i++)
            {
                // If there is a missing square in the player's answer
                if (computedAnswer[i] == '-' || computedRecall[i] == '-')
                {
                    newScore     -= MatchGapToMarkCutDown(numberOfHighlightedSquares);
                    recallCorrect = false;
                }
                // If there is an incorrect square in the player's answer
                else if (computedAnswer[i] != computedRecall[i])
                {
                    //get the int index based on the char index
                    int answerIntIndex = MatchCharIndexToIntIndex(computedAnswer[i]);
                    int recallIntIndex = MatchCharIndexToIntIndex(computedRecall[i]);

                    int markCutDown = MatchMismatchToMarkCutDown(
                        answerIntIndex, recallIntIndex,
                        highlightedSquares, recalledSquares);

                    newScore     -= markCutDown;
                    recallCorrect = false;
                }
            }

            // Check to see if player is eligible to get a bonus mark
            int bonusMark = GetBonusMark(numberOfHighlightedSquares, recallCorrect);

            newScore += bonusMark;

            return(newScore);
        }