コード例 #1
0
        public void ShouldReturnNullIfAllMatchScoresAreZero()
        {
            var fuzzyItem = new FuzzyItem <object>(new object());
            var fuzzyList = new List <IFuzzyItem <object> > {
                fuzzyItem
            };

            var bestMatch = fuzzyList.BestMatch();

            Assert.Null(bestMatch);
        }
コード例 #2
0
        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.Same(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.Same(bestMatch, secondItem);
        }
コード例 #3
0
        public void ShouldBeAbleToIgnoreFailedOptionalCriteria()
        {
            // The criteria will be set up to fail by default
            var falseCriteria = GetMockCriteria(false, CriteriaType.Optional, 1);

            // Use the true criteria as the control result
            var trueCriteria = GetMockCriteria(true, CriteriaType.Optional, 1);

            var fuzzyList = new List <IFuzzyItem <object> >();
            var fuzzyItem = new FuzzyItem <object>(new object());

            fuzzyList.Add(fuzzyItem);

            // Apply the criteria
            fuzzyList.AddCriteria(trueCriteria.Object);
            fuzzyList.AddCriteria(falseCriteria.Object);

            // The score must be left unchanged
            // since the criteria is optional and
            // the failed predicate does not count
            // against the current fuzzy item.
            Assert.Equal(1.0, fuzzyItem.Confidence);
        }
コード例 #4
0
        public void ShouldBeAbleToIgnoreFailedOptionalCriteria()
        {
            // The criteria will be set up to fail by default
            Mock<ICriteria<object>> falseCriteria = GetMockCriteria(false, CriteriaType.Optional, 1);

            // Use the true criteria as the control result
            Mock<ICriteria<object>> trueCriteria = GetMockCriteria(true, CriteriaType.Optional, 1);

            var fuzzyList = new List<IFuzzyItem<object>>();
            var fuzzyItem = new FuzzyItem<object>(new object());

            fuzzyList.Add(fuzzyItem);

            // Apply the criteria
            fuzzyList.AddCriteria(trueCriteria.Object);
            fuzzyList.AddCriteria(falseCriteria.Object);

            // The score must be left unchanged
            // since the criteria is optional and
            // the failed predicate does not count
            // against the current fuzzy item.
            Assert.AreEqual(fuzzyItem.Confidence, 1);
        }
コード例 #5
0
ファイル: FinderTests.cs プロジェクト: sdether/LinFu
        public void ShouldReturnNullIfAllMatchScoresAreZero()
        {
            var fuzzyItem = new FuzzyItem<object>(new object());
            var fuzzyList = new List<IFuzzyItem<object>> { fuzzyItem };

            var bestMatch = fuzzyList.BestMatch();

            Assert.IsNull(bestMatch);
        }
コード例 #6
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);
        }