public void Search_FilteringBySiteRankingSearchTopDomainByComOrgNet_ShouldBeEquivalentToLinq() { var topLevelDomains = new[] { "com", "net", "org " }; const int topLevelDomainRank = 1000; var expected = _rows.Where(x => topLevelDomains.Contains(x.TopLevelDomain) && x.TopLevelDomainRank <= topLevelDomainRank).ToList(); var search = new SiteRankingSearch { TopLevelDomain = topLevelDomains, TopLevelDomainRank = SearchCriteria.ByRange(1, topLevelDomainRank) }; var actual = _table.Search(search); var indexScores = _table.EvaluateIndexes(search); CollectionAssert.AreEquivalent(expected, actual); var searchWithPredicate = new SiteRankingSearch { TopLevelDomain = topLevelDomains, TopLevelDomainRank = SearchCriteria.ByPredicate((int x) => x <= topLevelDomainRank) }; var actualWithPredicate = _table.Search(searchWithPredicate); var indexScoreWithPredicate = _table.EvaluateIndexes(searchWithPredicate); CollectionAssert.AreEquivalent(expected, actualWithPredicate); Assert.IsTrue(indexScores[0].Score < indexScoreWithPredicate[0].Score, "Search without predicate should have a better score"); }
public void GetScore_CriteriaByPredicate_ShouldReturnScoreOf_1() { var rows = SiteRankingCollections.First10000Rows; var search = new SiteRankingSearch { TopLevelDomain = SearchCriteria.ByPredicate((string x) => x.StartsWith("c")) }; var expectedScore = new TableCriteriaScore(1, false); TestGetScores(rows, search, expectedScore); }
public void Reduce_CriteriaByPredicate_ShouldReturnNull() { var rows = SiteRankingCollections.First10000Rows; var search = new SiteRankingSearch { TopLevelDomain = SearchCriteria.ByPredicate((string x) => x == "ca") }; var criteria = BuildCriteria(rows, search); var actual = criteria.Reduce(new BinarySearchTable <SiteRanking>(rows)); Assert.IsNull(actual); }