Exemple #1
0
        public double DiceCoefficient(string compareTo)
        {
            Bigram compareBigram = new Bigram(compareTo);
            var intersection = this.BigramSet.Intersect(compareBigram.BigramSet);

            return CalculateDiceCoefficient(intersection.Count(), this.BigramSet.Count, compareBigram.BigramSet.Count);
        }
Exemple #2
0
        public double DiceCoefficient(Bigram compareTo)
        {
            if (compareTo == null) throw new ArgumentNullException("compareTo");

            var intersection = this.BigramSet.Intersect(compareTo.BigramSet);

            return CalculateDiceCoefficient(intersection.Count(), this.BigramSet.Count, compareTo.BigramSet.Count);
        }
        public void Constructor_Empty_String_Yields_Empty_Set()
        {
            string testValue = string.Empty;
            int expected = 0;

            var sut = new Bigram(testValue);
            var result = sut.BigramSet;

            Assert.That(result.Count, Is.EqualTo(expected));
        }
        public void Constructor_Two_Char_String_Yields_One_Item_Set()
        {
            string testValue = "hi";
            string expected = "hi";
            int expectedCount = 1;

            var sut = new Bigram(testValue);
            var result = sut.BigramSet;

            Assert.That(result.Count, Is.EqualTo(expectedCount));
            Assert.That(result.Contains(expected), Is.True);
        }
        public void DiceCoefficient_Completely_Different_Bigrams_Returns_0()
        {
            string testValue1 = "abcd";
            string testValue2 = "wxyz";
            double expected = 0.0;

            var sut = new Bigram(testValue1);
            var sutCompare = new Bigram(testValue2);

            var result = sut.DiceCoefficient(sutCompare);

            Assert.That(result, Is.EqualTo(expected));
        }
        public void Constructor_Multi_Char_String_Yields_Correct_Item_Set()
        {
            string testValue = "hello";
            int expectedCount = 4;

            var sut = new Bigram(testValue);
            var result = sut.BigramSet;

            Assert.That(result.Count, Is.EqualTo(expectedCount));
            Assert.That(result.Contains("he"), Is.True);
            Assert.That(result.Contains("el"), Is.True);
            Assert.That(result.Contains("ll"), Is.True);
            Assert.That(result.Contains("lo"), Is.True);
        }
        public void InitializeWithValue_Repeat_Pairs_Yields_One_Item_Set()
        {
            string testValue = "iiii";
            string expected = "ii";
            int expectedCount = 1;

            var sut = new Bigram();
            sut.InitializeForValue(testValue);
            var result = sut.BigramSet;

            Assert.That(result.Count, Is.EqualTo(expectedCount));
            Assert.That(result.Contains(expected), Is.True);
        }
        public void InitializeWithValue_Empty_String_Yields_Empty_Set()
        {
            string testValue = string.Empty;
            int expected = 0;

            var sut = new Bigram();
            sut.InitializeForValue(testValue);
            var result = sut.BigramSet;

            Assert.That(result.Count, Is.EqualTo(expected));
        }
        public void DiceCoefficient_Matching_Strings_Returns_1()
        {
            string testValue = "test";
            double expected = 1.0;

            var sut = new Bigram(testValue);
            var sutCompare = new Bigram(testValue);

            var result = sut.DiceCoefficient(testValue);

            Assert.That(result, Is.EqualTo(expected));
        }