public void AddressSearch_Speed() { List <Location> listLocations = Utils.ReadCSVFile(); #region Exact Search LocationCache cache = new LocationCache(listLocations); Stopwatch firstHit = new Stopwatch(); firstHit.Start(); _ = cache.GetAddressMatches("ab"); firstHit.Stop(); Stopwatch secondHit = new Stopwatch(); secondHit.Start(); _ = cache.GetAddressMatches("ab"); secondHit.Stop(); Assert.IsTrue(firstHit.ElapsedTicks > secondHit.ElapsedTicks); Console.WriteLine($"First Hit: {firstHit.ElapsedTicks} ticks\nSecond Hit: {secondHit.ElapsedTicks} ticks\n"); #endregion #region Partial Search LocationCache cachePartial = new LocationCache(listLocations); cachePartial.GetAddressMatches("a"); Stopwatch partial = new Stopwatch(); partial.Start(); _ = cachePartial.GetAddressMatches("ab"); partial.Stop(); LocationCache cacheNoPartial = new LocationCache(listLocations); Stopwatch noPartial = new Stopwatch(); noPartial.Start(); _ = cacheNoPartial.GetAddressMatches("ab"); noPartial.Stop(); Assert.IsTrue(noPartial.ElapsedTicks > partial.ElapsedTicks); Console.WriteLine($"Partial: {partial.ElapsedTicks} ticks\nNo Partial: {noPartial.ElapsedTicks} ticks\n"); #endregion }
public void AddressSearch_Accuracy() { List <Location> listInitialLocations = new List <Location> { new Location(1, "Test1", "", "", "", 0, 0), new Location(2, "Te3", "", "", "", 0, 0), new Location(3, "abc4ewq", "", "", "", 0, 0), }; LocationCache cache = new LocationCache(listInitialLocations); List <Location> results = cache.GetAddressMatches("TE"); Assert.AreEqual(2, results.Count); Assert.IsTrue(results.Any(x => x.Id == 1)); Assert.IsTrue(results.Any(x => x.Id == 2)); results = cache.GetAddressMatches("e3"); Assert.AreEqual(1, results.Count); Assert.IsTrue(results.Any(x => x.Id == 2)); results = cache.GetAddressMatches("ET"); Assert.AreEqual(0, results.Count); results = cache.GetAddressMatches(""); Assert.AreEqual(0, results.Count); }