public async Task TestTreeAddWithSingleCharStringTerm() { // Arrange var items = new[] { "A" }; var tree = new PrefixTree(); var expected = items; // Act tree.Add(items); var actual = await tree.FindAsync(string.Empty); // Assert Assert.IsNotNull(actual); Assert.AreEqual(expected.Count(), expected.Where(actual.Contains).Count()); }
public async Task TestTreeAddWithMultipleItemsStartedWithSamePrefix() { // Arrange var items = new[] { "AbC", "ABcD" }; var tree = new PrefixTree(); var expected = items; // Act tree.Add(items); var actual =await tree.FindAsync(string.Empty); // Assert Assert.IsNotNull(actual); Assert.AreEqual(expected.Count(), expected.Count(x => actual.Contains(x.ToUpper()))); }
public async Task TestGetItemsWithFullTerm() { // Arrange var items = new[] { "ABC" }; var tree = new PrefixTree(); tree.Add(items); var expected = items; // Act var actual =await tree.FindAsync("ABC"); // Assert Assert.IsNotNull(actual); Assert.AreEqual(expected.Count(), expected.Where(actual.Contains).Count()); }
public async Task TestGetItemsWithSingleCharAndMultipleBranches() { // Arrange var items = new[] { "ABCD", "AdCE" }; var tree = new PrefixTree(); tree.Add(items); var expected = items; // Act var actual =await tree.FindAsync("A"); // Assert Assert.IsNotNull(actual); Assert.AreEqual(expected.Count(), expected.Count(x => actual.Contains(x.ToUpper()))); }
public async Task TestFindNullThrowsException() { // Arrange var items = new[] { "ABF", "ABE" }; var tree = new PrefixTree(); tree.Add(items); // Act await tree.FindAsync(null); }