public void WHEN_ComputeSimilarityWhereString2Wrong1CharBefore_THEN_ComputedString1ShowsSame() { testString1 = "ab"; testString2 = "cb"; expectedResultString = "ab"; StringSimilarity.ComputeSimilarity(testString1, testString2); Assert.AreEqual(expectedResultString, StringSimilarity.GetComputedString1()); }
public void WHEN_ComputeSimilarityWhereString1Wrong1CharAfter_THEN_ComputedString1ShowsGap() { testString1 = "ac"; testString2 = "ab"; expectedResultString = "ac"; StringSimilarity.ComputeSimilarity(testString1, testString2); Assert.AreEqual(expectedResultString, StringSimilarity.GetComputedString1()); }
public void WHEN_ComputeSimilarityWhereString2Missing2CharBetween_THEN_ComputedString1ShowsSame() { testString1 = "abcd"; testString2 = "ad"; expectedResultString = "abcd"; StringSimilarity.ComputeSimilarity(testString1, testString2); Assert.AreEqual(expectedResultString, StringSimilarity.GetComputedString1()); }
public void WHEN_ComputeSimilarityOfTwoEmptyStrings_THEN_ComputedString1IsEmpty() { testString1 = ""; testString2 = ""; expectedResultString = ""; StringSimilarity.ComputeSimilarity(testString1, testString2); Assert.AreEqual(expectedResultString, StringSimilarity.GetComputedString1()); }
public void WHEN_ComputeSimilarityWhereString2Empty_THEN_ComputedString1ShowsOriginal() { testString1 = "a"; testString2 = ""; expectedResultString = "a"; StringSimilarity.ComputeSimilarity(testString1, testString2); Assert.AreEqual(expectedResultString, StringSimilarity.GetComputedString1()); }
public void WHEN_ComputeSimilarityOfTwoIdenticalStrings_THEN_ComputedString1IsOriginal() { testString1 = "abc"; testString2 = "abc"; expectedResultString = "abc"; StringSimilarity.ComputeSimilarity(testString1, testString2); Assert.AreEqual(expectedResultString, StringSimilarity.GetComputedString1()); }
/// <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); }