Exemple #1
0
        public void Will_Calculate_Difference_Between_Two_Word_Same_Length_Correctly()
        {
            var word1 = "span";
            var word2 = "spin";

            var result = StringUtilityMethods.CalculateLevenshteinDistance(word1, word2);

            var expectedResult = 1;

            Assert.Equal(expectedResult, result);
        }
Exemple #2
0
        /// <summary>
        /// Uses Levenshtein Distance to calculate the mutations between 2 words and adds to a list if they are only different by 1 char
        /// </summary>
        /// <param name="dictionaryOfWords"></param>
        /// <param name="currentWord"></param>
        /// <returns></returns>
        private List <string> FindNeighbours(List <string> dictionaryOfWords, string currentWord)
        {
            var neighbours = new List <string>();

            for (int i = 0; i < dictionaryOfWords.Count; i++)
            {
                var wordInDictionary = dictionaryOfWords[i];

                //If Word is one character difference from
                if (StringUtilityMethods.CalculateLevenshteinDistance(currentWord, wordInDictionary) == 1)
                {
                    neighbours.Add(wordInDictionary);
                }
            }

            return(neighbours);
        }