コード例 #1
0
ファイル: FinderTests.cs プロジェクト: sdether/LinFu
        public void ShouldNotBeAbleToIgnoreFailedCriticalCriteria()
        {
            var fuzzyList = new List<IFuzzyItem<object>>();
            var fuzzyItem = new FuzzyItem<object>(new object());

            fuzzyList.Add(fuzzyItem);

            var trueCriteria = GetMockCriteria(true, CriteriaType.Standard, 2);
            var failedCriteria = GetMockCriteria(false, CriteriaType.Critical, 1);

            // Boost the first item results so that the best match
            // should be biased towards the first item
            fuzzyItem.Test(trueCriteria.Object);

            // Make both items pass the first test
            var secondItem = new FuzzyItem<object>(new object());
            fuzzyList.Add(secondItem);

            fuzzyList.AddCriteria(trueCriteria.Object);

            // The first item should be the best match at this point
            var bestMatch = fuzzyList.BestMatch();
            Assert.AreSame(bestMatch, fuzzyItem);

            // Remove the second item from the list to avoid the
            // failed critical match
            fuzzyList.Remove(secondItem);

            // The failed critical criteria should eliminate
            // the first match as the best possible match
            fuzzyList.AddCriteria(failedCriteria.Object);

            // Reinsert the second value into the list
            // so that it can be chosen as the best match
            fuzzyList.Add(secondItem);

            // Run the test again
            bestMatch = fuzzyList.BestMatch();

            // The second item should be the best possible match,
            // and the first item should be ignored
            // because of the failed criteria
            Assert.AreSame(bestMatch, secondItem);
        }