public void GetListOfClosestWordsFuncTest()
        {
            // arrange
            ILevenshteinDistance levDist = new WagnerFischer();
            List<string> origWords = new List<string>()
            {
                "First",
                "Second",
                "Third",
                "Fourth",
                "Fifth",
                "Sixth"
            };
            MockDictionaryFileFiller filler = new MockDictionaryFileFiller(origWords);
            WordsDictionary dic = new WordsDictionary(levDist, filler);
            List<string> resWords = new List<string>()
            {
                "First",
                "Fifth"
            };
            // act
            List<string> res = dic.GetClosestWords("Funci");

            // assert
            Assert.IsTrue(Enumerable.SequenceEqual(resWords, res));
        }
示例#2
0
        public void CalcLevenshteinDistanceBothNullArgumentsTest()
        {
            // arrange
            ILevenshteinDistance levDistance = new WagnerFischer();

            // act, assert
            int distance = levDistance.CalcLevenshteinDistance(null, null);
        }
示例#3
0
        public void CalcLevenshteinDistanceDeletionTest()
        {
            // arrange
            ILevenshteinDistance levDistance = new WagnerFischer();

            // act
            int distance = levDistance.CalcLevenshteinDistance("distance", "ditance");

            // assert
            Assert.AreEqual(levDistance.DeletionWeight, distance);
        }
示例#4
0
        public void CalcLevenshteinDistanceBothEmptyStringTest()
        {
            // arrange
            ILevenshteinDistance levDistance = new WagnerFischer();

            // act, assert
            int distance = levDistance.CalcLevenshteinDistance("", "");

            // assert
            Assert.AreEqual(0, distance);
        }
示例#5
0
        public void CalcLevenshteinDistanceDeletionReplacementTest()
        {
            // arrange
            ILevenshteinDistance levDistance = new WagnerFischer();
            string testString1 = "ghosts";
            string testString2 = "opera";

            // act
            int distance = levDistance.CalcLevenshteinDistance(testString1, testString2);

            // assert
            Assert.AreEqual(levDistance.ReplacementWeight * testString2.Length +
                    (testString1.Length - testString2.Length) * levDistance.DeletionWeight, distance);
        }
示例#6
0
        public void CalcLevenshteinDistanceEqualTest()
        {
            //arrange
            ILevenshteinDistance levDistance = new WagnerFischer();

            //act
            int distance = levDistance.CalcLevenshteinDistance("excellent", "excellent");

            //assert
            Assert.AreEqual(0, distance);
        }
示例#7
0
        public void CalcLevenshteinDistanceSecondNullArgumentTest()
        {
            // arrange
            ILevenshteinDistance levDistance = new WagnerFischer();

            // act, assert
            int distance = levDistance.CalcLevenshteinDistance("Stroka1", null);
        }
示例#8
0
        public void CalcLevenshteinDistanceSecondEmptyStringTest()
        {
            // arrange
            ILevenshteinDistance levDistance = new WagnerFischer();
            string testString = "Stroka2";

            // act
            int distance = levDistance.CalcLevenshteinDistance(testString, "");

            // assert
            Assert.AreEqual(testString.Length * levDistance.DeletionWeight, distance);
        }
示例#9
0
        public void CalcLevenshteinDistanceReplacementTest()
        {
            // arrange
            ILevenshteinDistance levDistance = new WagnerFischer();

            // act
            int distance = levDistance.CalcLevenshteinDistance("yandex", "yardex");

            // assert
            Assert.AreEqual(levDistance.ReplacementWeight, distance);
        }
示例#10
0
        public void CalcLevenshteinDistanceInsertionTest()
        {
            // arrange
            ILevenshteinDistance levDistance = new WagnerFischer();

            // act
            int distance = levDistance.CalcLevenshteinDistance("opera", "hopera");

            // assert
            Assert.AreEqual(levDistance.InsertionWeight, distance);
        }
示例#11
0
        public void CalcLevenshteinDistanceFirstNullArgumentTest()
        {
            // arrange
            ILevenshteinDistance levDistance = new WagnerFischer();

            // act, assert
            int distance = levDistance.CalcLevenshteinDistance(null, "Stroka2");
        }
示例#12
0
        public void CalcLevenshteinDistanceFirstEmptyStringTest()
        {
            // arrange
            ILevenshteinDistance levDistance = new WagnerFischer();
            string testString = "Stroka";

            // act
            int distance = levDistance.CalcLevenshteinDistance("", testString);

            // assert
            Assert.AreEqual(testString.Length * levDistance.InsertionWeight, distance);
        }