public void LevenshteinDistance_StringsAreEqualExceptForCase_ReturnZero()
        {
            //Arrange

            //Act
            var result = LevenshteinProcessor.LevenshteinDistance("test", "TEST");

            //Assert
            Assert.AreEqual(0, result);
        }
        public void LevenshteinDistance_StringsDiffer_ReturnGreaterThanZero()
        {
            //Arrange

            //Act
            var result = LevenshteinProcessor.LevenshteinDistance("Ninja", "Nye");

            //Assert
            Assert.Greater(result, 0);
        }
        public void LevenshteinDistance_DefaultBehaviour_DoesNotThrowAnException()
        {
            //Arrange

            //Act
            LevenshteinProcessor.LevenshteinDistance("", "");

            //Assert
            Assert.Pass("No exception thrown");
        }
        public void LevenshteinDistance_SecondStringIsEmpty_ReturnLengthOfFirstString()
        {
            //Arrange

            //Act
            var result = LevenshteinProcessor.LevenshteinDistance("test", string.Empty);

            //Assert
            Assert.AreEqual(4, result);
        }
        public void LevenshteinDistance_BothStringsNull_ReturnZero()
        {
            //Arrange

            //Act
            var result = LevenshteinProcessor.LevenshteinDistance(null, null);

            //Assert
            Assert.AreEqual(0, result);
        }
        public void LevenshteinDistance_AcceptsTwoStrings_ReturnsUnsignedInteger()
        {
            //Arrange

            //Act
            var result = LevenshteinProcessor.LevenshteinDistance("string", "string");

            //Assert
            Assert.IsInstanceOf <int>(result);
        }
        public void LevenshteinDistance_FirstStringIsEmpty_ReturnLengthOfSecondString()
        {
            //Arrange

            //Act
            var result = LevenshteinProcessor.LevenshteinDistance(string.Empty, "string");

            //Assert
            Assert.AreEqual(6, result);
        }
        public void LevenshteinDistance_StringsDifferByTwoCharactersAndCasing_ReturnTwo()
        {
            //Arrange

            //Act
            var result = LevenshteinProcessor.LevenshteinDistance("Barry", "LORRY");

            //Assert
            Assert.AreEqual(2, result);
        }
        public void LevenshteinDistance_StringsDifferByNonLinearChanges_ReturnTwo()
        {
            //Arrange

            //Act
            var result = LevenshteinProcessor.LevenshteinDistance("house", "use");

            //Assert
            Assert.AreEqual(2, result);
        }
Ejemplo n.º 10
0
        public void LevenshteinDistanceOf_GetDistanceToProperty_DistancesAreCorrect()
        {
            //Arrange

            //Act
            var result = _context.TestModels.LevenshteinDistanceOf(x => x.StringOne).ComparedTo(x => x.StringTwo);

            //Assert
            Assert.True(result.All(x => x.Distance == LevenshteinProcessor.LevenshteinDistance(x.Item.StringOne, x.Item.StringTwo)));
        }
Ejemplo n.º 11
0
        public void LevenshteinDistanceOf_GetDistanceToString_DistancesAreCorrect()
        {
            //Arrange

            //Act
            var result = this._context.TestModels.LevenshteinDistanceOf(x => x.StringOne).ComparedTo("test");

            //Assert
            Assert.IsTrue(result.All(x => x.Distance == LevenshteinProcessor.LevenshteinDistance(x.Item.StringOne, "test")));
        }
Ejemplo n.º 12
0
        public void Levenshtein_GetLevenshteinDistanceAgainstMultipleDefinedProperties_DistanceIsLevenshteinDistance()
        {
            //Arrange

            //Act
            var result = _testData.LevenshteinDistanceOf(x => x.Name)
                         .ComparedTo(x => x.Description)
                         .ToList();

            //Assert
            Assert.IsTrue(result.All(x => x.Distance == LevenshteinProcessor.LevenshteinDistance(x.Item.Name, x.Item.Description)));
        }
Ejemplo n.º 13
0
        public void Levenshtein_GetLevenshteinDistanceAgainstDefinedString_DistanceIsLevenshteinDistance()
        {
            //Arrange
            const string compareTo = "choose";

            //Act
            var result = _testData.LevenshteinDistanceOf(x => x.Name)
                         .ComparedTo(compareTo)
                         .ToList();

            //Assert
            Assert.IsTrue(result.All(x => x.Distance == LevenshteinProcessor.LevenshteinDistance(x.Item.Name, compareTo)));
        }
Ejemplo n.º 14
0
 public static int GetMatchScore(IImportingPerson source, Person match)
 {
     if (string.IsNullOrWhiteSpace(source.Address))
     {
         return(String.Equals(source.LastName, match.LastName, StringComparison.CurrentCultureIgnoreCase) &&
                String.Equals(source.FirstName, match.HisName, StringComparison.CurrentCultureIgnoreCase)
                                  ? 1 : 2);
     }
     if (!string.IsNullOrWhiteSpace(source.City) && !string.IsNullOrWhiteSpace(match.City) &&
         !source.City.Equals(match.City, StringComparison.CurrentCultureIgnoreCase))
     {
         return(2);
     }
     if (AddressInfo.Parse(source.Address) != AddressInfo.Parse(match.Address) ||
         LevenshteinProcessor.LevenshteinDistance(source.LastName, match.LastName) > 1)
     {
         return(2);
     }
     return(0);
 }
        public void ToLevenshteinDistance_CompareOneMillionStringsOfLengthX_ExecutesInLessThanOneSecond(int length)
        {
            //Arrange
            var words      = BuildWords(1000000, length, length);
            var randomWord = BuildRandomWord(length, length);
            var stopwatch  = new Stopwatch();

            //Act
            stopwatch.Start();
            var result = words.Select(w => LevenshteinProcessor.LevenshteinDistance(w, randomWord)).ToList();

            stopwatch.Stop();

            //Assert
            Console.WriteLine("Elapsed Time: {0}", stopwatch.Elapsed);
            Console.WriteLine("Total matching words: {0}", result.Count(i => i == 0));
            Console.WriteLine("Total words with distance of 1: {0}", result.Count(i => i == 1));
            Console.WriteLine("Total words with distance of 2: {0}", result.Count(i => i == 2));
            Console.WriteLine("Total words with distance of 3: {0}", result.Count(i => i == 3));
            Assert.True(stopwatch.Elapsed.TotalMilliseconds < 1000);
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            var words = new[] { "twitter", "nitter", "flitter", "critter" };

            //Console.WriteLine("Processing {0} words", words.Length);
            //var stopwatch = new Stopwatch();
            //Console.WriteLine("Begin soundex...");
            //stopwatch.Start();
            //var soundexCodes = words.Select(SoundexProcessor.ToSoundex);
            //var reverseSoundexCodes = words.Select(SoundexProcessor.ToReverseSoundex);
            //stopwatch.Stop();
            //Console.WriteLine("Time taken: {0}", stopwatch.Elapsed);
            //foreach (var code in soundexCodes)
            //{
            //    Console.WriteLine(code);
            //}
            //foreach (var code in reverseSoundexCodes)
            //{
            //    Console.WriteLine(code);
            //}
            //Console.WriteLine("Soundex complete...");


            const int recordCount = 10000;
            const StringComparison stringComparison = StringComparison.CurrentCulture;

            Console.WriteLine("Building {0} records...", recordCount);
            var    enumerableData = BuildData(recordCount);
            string searchString   = "teststring";
            var    results        = new List <int>();

            for (int i = 0; i < enumerableData.Count; i++)
            {
                results.Add(LevenshteinProcessor.LevenshteinDistance(enumerableData[i], searchString));
            }

            //Console.WriteLine("====================================");
            //Console.WriteLine(" SearchExtensions performance tests ");
            //Console.WriteLine("====================================");

            //const int recordCount = 1000000;
            //const StringComparison stringComparison = StringComparison.CurrentCulture;
            ////            var stopwatch = new Stopwatch();

            //Console.WriteLine("Building {0} records...", recordCount);
            //var enumerableData = BuildData(recordCount);
            //var searchTerms = new[] { "abc", "def", "ghi", "JKL", "mno", "pqr", "stu", "vwx" };

            //Console.WriteLine("Begin search...");
            ////stopwatch.Start();
            //var result = enumerableData.Search(s => s)
            //                           .Containing(searchTerms)
            //                           .ToList();

//            stopwatch.Stop();
//            Console.WriteLine("Record count: {0}", recordCount);
//            Console.WriteLine("Results found: {0}", result.Count);
//            Console.WriteLine("Time taken: {0}", stopwatch.Elapsed);
//            Console.WriteLine("Search complete...");
//            Console.WriteLine();
//            Console.WriteLine("==================================");
//            Console.WriteLine();
//            Console.WriteLine("Begin lamda...");
//            Console.WriteLine("Building {0} records...", recordCount);
//            enumerableData = BuildData(recordCount);
//            stopwatch.Reset();
//            stopwatch.Start();
//            var lamdaResult = enumerableData.Where(s => s.IndexOf("abc", stringComparison) > -1
//                                                     || s.IndexOf("def", stringComparison) > -1
//                                                     || s.IndexOf("ghi", stringComparison) > -1
//                                                     || s.IndexOf("jkl", stringComparison) > -1
//                                                     || s.IndexOf("mno", stringComparison) > -1
//                                                     || s.IndexOf("pqr", stringComparison) > -1
//                                                     || s.IndexOf("stu", stringComparison) > -1
//                                                     || s.IndexOf("vwx", stringComparison) > -1).ToList();

//            stopwatch.Stop();
//            Console.WriteLine("Results found: {0}", lamdaResult.Count);
//            Console.WriteLine("Time taken: {0}", stopwatch.Elapsed);
//            Console.WriteLine("Lamda complete...");
//            Console.WriteLine();
//            Console.WriteLine("==================================");
//            Console.WriteLine();

//            Console.WriteLine("Begin .Any() search...");
//            Console.WriteLine("Building {0} records...", recordCount);
//            enumerableData = BuildData(recordCount);
//            stopwatch.Reset();
//            stopwatch.Start();
//            var containsResult = enumerableData.Where(s => searchTerms.Any(st => s.IndexOf(st) > -1)).ToList();
//            stopwatch.Stop();
//            Console.WriteLine("Results found: {0}", containsResult.Count);
//            Console.WriteLine("Time taken: {0}", stopwatch.Elapsed);
//            Console.WriteLine("Any() search complete...");
//            Console.WriteLine();
//            Console.WriteLine("==================================");
//            Console.WriteLine();

//            Console.WriteLine("Begin fluent search...");
//            Console.WriteLine("Building {0} records...", recordCount);
//            enumerableData = BuildData(recordCount);
//            stopwatch.Reset();
//            stopwatch.Start();
//            var fluentResult = enumerableData.Search(s => s)
//                                             .Containing(searchTerms)
//                                             .ToList();
//            stopwatch.Stop();
//            Console.WriteLine("Record count: {0}", recordCount);
//            Console.WriteLine("Results found: {0}", fluentResult.Count);
//            Console.WriteLine("Time taken: {0}", stopwatch.Elapsed);
//            Console.WriteLine("Fluent search complete...");
//            Console.WriteLine();
//            Console.WriteLine("==================================");
//            Console.ReadLine();
        }