Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        public void CalcLevenshteinDistanceBothNullArgumentsTest()
        {
            // arrange
            ILevenshteinDistance levDistance = new WagnerFischer();

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

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

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

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

            // assert
            Assert.AreEqual(0, distance);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
0
        public void CalcLevenshteinDistanceEqualTest()
        {
            //arrange
            ILevenshteinDistance levDistance = new WagnerFischer();

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

            //assert
            Assert.AreEqual(0, distance);
        }
Ejemplo n.º 7
0
        public void CalcLevenshteinDistanceSecondNullArgumentTest()
        {
            // arrange
            ILevenshteinDistance levDistance = new WagnerFischer();

            // act, assert
            int distance = levDistance.CalcLevenshteinDistance("Stroka1", null);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 9
0
        public void CalcLevenshteinDistanceReplacementTest()
        {
            // arrange
            ILevenshteinDistance levDistance = new WagnerFischer();

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

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

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

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

            // act, assert
            int distance = levDistance.CalcLevenshteinDistance(null, "Stroka2");
        }
Ejemplo n.º 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);
        }