Example #1
0
        public void BulkAddOccurrences_ExistingDocument()
        {
            Word word = new Word(1, "hello");
            IDocument doc0 = MockDocument("Doc0", "Doc0", "d", DateTime.Now);
            word.AddOccurrence(doc0, 10, 0, WordLocation.Content);
            Assert.AreEqual(10, word.Occurrences[doc0][0].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(0, word.Occurrences[doc0][0].WordIndex, "Wrong word index");

            IDocument doc = MockDocument("Doc", "Doc", "d", DateTime.Now);
            word.AddOccurrence(doc, 0, 0, WordLocation.Content);
            Assert.AreEqual(2, word.Occurrences.Count, "Wrong occurrences count");
            Assert.AreEqual(2, word.TotalOccurrences, "Wrong total occurrences count");

            SortedBasicWordInfoSet set = new SortedBasicWordInfoSet();
            set.Add(new BasicWordInfo(10, 0, WordLocation.Content));
            set.Add(new BasicWordInfo(25, 1, WordLocation.Content));
            set.Add(new BasicWordInfo(102, 2, WordLocation.Content));
            word.BulkAddOccurrences(doc, set);

            Assert.AreEqual(2, word.Occurrences.Count, "Wrong occurrences count");
            Assert.AreEqual(4, word.TotalOccurrences, "Wrong total occurrences count");
            Assert.AreEqual(10, word.Occurrences[doc0][0].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(0, word.Occurrences[doc0][0].WordIndex, "Wrong word index");
            Assert.AreEqual(10, word.Occurrences[doc][0].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(0, word.Occurrences[doc][0].WordIndex, "Wrong word index");
            Assert.AreEqual(25, word.Occurrences[doc][1].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(1, word.Occurrences[doc][1].WordIndex, "Wrong word index");
            Assert.AreEqual(102, word.Occurrences[doc][2].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(2, word.Occurrences[doc][2].WordIndex, "Wrong word index");
        }
Example #2
0
        public void BulkAddOccurrences_ExistingDocument()
        {
            Word      word = new Word(1, "hello");
            IDocument doc0 = MockDocument("Doc0", "Doc0", "d", DateTime.Now);

            word.AddOccurrence(doc0, 10, 0, WordLocation.Content);
            Assert.AreEqual(10, word.Occurrences[doc0][0].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(0, word.Occurrences[doc0][0].WordIndex, "Wrong word index");

            IDocument doc = MockDocument("Doc", "Doc", "d", DateTime.Now);

            word.AddOccurrence(doc, 0, 0, WordLocation.Content);
            Assert.AreEqual(2, word.Occurrences.Count, "Wrong occurrences count");
            Assert.AreEqual(2, word.TotalOccurrences, "Wrong total occurrences count");

            SortedBasicWordInfoSet set = new SortedBasicWordInfoSet();

            set.Add(new BasicWordInfo(10, 0, WordLocation.Content));
            set.Add(new BasicWordInfo(25, 1, WordLocation.Content));
            set.Add(new BasicWordInfo(102, 2, WordLocation.Content));
            word.BulkAddOccurrences(doc, set);

            Assert.AreEqual(2, word.Occurrences.Count, "Wrong occurrences count");
            Assert.AreEqual(4, word.TotalOccurrences, "Wrong total occurrences count");
            Assert.AreEqual(10, word.Occurrences[doc0][0].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(0, word.Occurrences[doc0][0].WordIndex, "Wrong word index");
            Assert.AreEqual(10, word.Occurrences[doc][0].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(0, word.Occurrences[doc][0].WordIndex, "Wrong word index");
            Assert.AreEqual(25, word.Occurrences[doc][1].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(1, word.Occurrences[doc][1].WordIndex, "Wrong word index");
            Assert.AreEqual(102, word.Occurrences[doc][2].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(2, word.Occurrences[doc][2].WordIndex, "Wrong word index");
        }
Example #3
0
        public void BulkAddOccurrences_ExistingDocument()
        {
            Word      sut  = new Word(1, "hello");
            IDocument doc0 = MockDocument("Doc0", "Doc0", "d", DateTime.Now);

            sut.AddOccurrence(doc0, 10, 0, WordLocation.Content);
            Assert.Equal(10, sut.Occurrences[doc0][0].FirstCharIndex);
            Assert.Equal(0, sut.Occurrences[doc0][0].WordIndex);

            IDocument doc = MockDocument("Doc", "Doc", "d", DateTime.Now);

            sut.AddOccurrence(doc, 0, 0, WordLocation.Content);
            Assert.Equal(2, sut.Occurrences.Count);
            Assert.Equal(2, sut.TotalOccurrences);

            SortedBasicWordInfoSet set = new SortedBasicWordInfoSet();

            set.Add(new BasicWordInfo(10, 0, WordLocation.Content));
            set.Add(new BasicWordInfo(25, 1, WordLocation.Content));
            set.Add(new BasicWordInfo(102, 2, WordLocation.Content));
            sut.BulkAddOccurrences(doc, set);

            Assert.Equal(2, sut.Occurrences.Count);
            Assert.Equal(4, sut.TotalOccurrences);
            Assert.Equal(10, sut.Occurrences[doc0][0].FirstCharIndex);
            Assert.Equal(0, sut.Occurrences[doc0][0].WordIndex);
            Assert.Equal(10, sut.Occurrences[doc][0].FirstCharIndex);
            Assert.Equal(0, sut.Occurrences[doc][0].WordIndex);
            Assert.Equal(25, sut.Occurrences[doc][1].FirstCharIndex);
            Assert.Equal(1, sut.Occurrences[doc][1].WordIndex);
            Assert.Equal(102, sut.Occurrences[doc][2].FirstCharIndex);
            Assert.Equal(2, sut.Occurrences[doc][2].WordIndex);
        }
Example #4
0
        public void Add2Occurrences_SameDocument()
        {
            Word word = new Word(1, "hello");

            IDocument doc = MockDocument("Doc", "Doc", "d", DateTime.Now);
            word.AddOccurrence(doc, 0, 0, WordLocation.Content);
            word.AddOccurrence(doc, 10, 1, WordLocation.Content);
            Assert.AreEqual(1, word.Occurrences.Count, "Wrong occurrences count");
            Assert.AreEqual(2, word.TotalOccurrences, "Wrong total occurences count");
            Assert.AreEqual(0, word.Occurrences[doc][0].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(0, word.Occurrences[doc][0].WordIndex, "Wrong word index");
            Assert.AreEqual(10, word.Occurrences[doc][1].FirstCharIndex, "Wrong occurrence");
            Assert.AreEqual(1, word.Occurrences[doc][1].WordIndex, "Wrong word index");
        }
Example #5
0
        public void Add2Occurrences_SameDocument()
        {
            Word word = new Word(1, "hello");

            IDocument doc = MockDocument("Doc", "Doc", "d", DateTime.Now);

            word.AddOccurrence(doc, 0, 0, WordLocation.Content);
            word.AddOccurrence(doc, 10, 1, WordLocation.Content);
            Assert.AreEqual(1, word.Occurrences.Count, "Wrong occurrences count");
            Assert.AreEqual(2, word.TotalOccurrences, "Wrong total occurences count");
            Assert.AreEqual(0, word.Occurrences[doc][0].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(0, word.Occurrences[doc][0].WordIndex, "Wrong word index");
            Assert.AreEqual(10, word.Occurrences[doc][1].FirstCharIndex, "Wrong occurrence");
            Assert.AreEqual(1, word.Occurrences[doc][1].WordIndex, "Wrong word index");
        }
Example #6
0
        public void Add2Occurrences_SameDocument()
        {
            Word sut = new Word(1, "hello");

            IDocument doc = MockDocument("Doc", "Doc", "d", DateTime.Now);

            sut.AddOccurrence(doc, 0, 0, WordLocation.Content);
            sut.AddOccurrence(doc, 10, 1, WordLocation.Content);
            Assert.Single(sut.Occurrences);
            Assert.Equal(2, sut.TotalOccurrences);
            Assert.Equal(0, sut.Occurrences[doc][0].FirstCharIndex);
            Assert.Equal(0, sut.Occurrences[doc][0].WordIndex);
            Assert.Equal(10, sut.Occurrences[doc][1].FirstCharIndex);
            Assert.Equal(1, sut.Occurrences[doc][1].WordIndex);
        }
Example #7
0
        public void Add2Occurrences_DifferentDocuments()
        {
            var word = new Word(1, "hello");

            var doc1 = MockDocument("Doc1", "Doc1", "d", DateTime.Now);
            var doc2 = MockDocument("Doc2", "Doc2", "d", DateTime.Now);

            word.AddOccurrence(doc1, 0, 0, WordLocation.Content);
            word.AddOccurrence(doc2, 10, 1, WordLocation.Content);
            Assert.AreEqual(2, word.Occurrences.Count, "Wrong occurrences count");
            Assert.AreEqual(2, word.TotalOccurrences, "Wrong total occurences count");
            Assert.AreEqual(0, word.Occurrences[doc1][0].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(0, word.Occurrences[doc1][0].WordIndex, "Wrong word index");
            Assert.AreEqual(10, word.Occurrences[doc2][0].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(1, word.Occurrences[doc2][0].WordIndex, "Wrong word index");
        }
Example #8
0
        public void Add2Occurrences_DifferentDocuments()
        {
            Word sut = new Word(1, "hello");

            IDocument doc1 = MockDocument("Doc1", "Doc1", "d", DateTime.Now);
            IDocument doc2 = MockDocument("Doc2", "Doc2", "d", DateTime.Now);

            sut.AddOccurrence(doc1, 0, 0, WordLocation.Content);
            sut.AddOccurrence(doc2, 10, 1, WordLocation.Content);
            Assert.Equal(2, sut.Occurrences.Count);
            Assert.Equal(2, sut.TotalOccurrences);
            Assert.Equal(0, sut.Occurrences[doc1][0].FirstCharIndex);
            Assert.Equal(0, sut.Occurrences[doc1][0].WordIndex);
            Assert.Equal(10, sut.Occurrences[doc2][0].FirstCharIndex);
            Assert.Equal(1, sut.Occurrences[doc2][0].WordIndex);
        }
Example #9
0
        public void AddOccurrence_Document_Null()
        {
            Word sut = new Word(1, "dummy");
            var  ex  = Assert.Throws <ArgumentNullException>(() => sut.AddOccurrence(null, 0, 0, WordLocation.Content));

            Assert.Equal("Value cannot be null.\r\nParameter name: document", ex.Message);
        }
Example #10
0
        public void RemoveOccurrences()
        {
            Word word = new Word(1, "hello");

            IDocument doc1 = MockDocument("Doc1", "Doc1", "d", DateTime.Now);
            IDocument doc2 = MockDocument("Doc2", "Doc2", "d", DateTime.Now);

            word.AddOccurrence(doc1, 0, 0, WordLocation.Content);
            word.AddOccurrence(doc1, 10, 1, WordLocation.Content);
            word.AddOccurrence(doc2, 5, 0, WordLocation.Content);
            Assert.AreEqual(2, word.Occurrences.Count, "Wrong occurrences count");
            Assert.AreEqual(3, word.TotalOccurrences, "Wrong total occurrences count");

            word.RemoveOccurrences(doc1);

            Assert.AreEqual(1, word.Occurrences.Count, "Wrong occurrences count");
            Assert.AreEqual(1, word.TotalOccurrences, "Wrong total occurrences count");
            Assert.AreEqual(5, word.Occurrences[doc2][0].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(0, word.Occurrences[doc2][0].WordIndex, "Wrong word index");
        }
Example #11
0
        public void RemoveOccurrences()
        {
            Word sut = new Word(1, "hello");

            IDocument doc1 = MockDocument("Doc1", "Doc1", "d", DateTime.Now);
            IDocument doc2 = MockDocument("Doc2", "Doc2", "d", DateTime.Now);

            sut.AddOccurrence(doc1, 0, 0, WordLocation.Content);
            sut.AddOccurrence(doc1, 10, 1, WordLocation.Content);
            sut.AddOccurrence(doc2, 5, 0, WordLocation.Content);
            Assert.Equal(2, sut.Occurrences.Count);
            Assert.Equal(3, sut.TotalOccurrences);

            sut.RemoveOccurrences(doc1);

            Assert.Single(sut.Occurrences);
            Assert.Equal(1, sut.TotalOccurrences);
            Assert.Equal(5, sut.Occurrences[doc2][0].FirstCharIndex);
            Assert.Equal(0, sut.Occurrences[doc2][0].WordIndex);
        }
Example #12
0
        public void BulkAddOccurrences_ExistingDocument_EmptyPositionsSet()
        {
            var word = new Word(1, "hello");
            var doc0 = MockDocument("Doc0", "Doc0", "d", DateTime.Now);

            word.AddOccurrence(doc0, 10, 0, WordLocation.Content);
            Assert.AreEqual(10, word.Occurrences[doc0][0].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(0, word.Occurrences[doc0][0].WordIndex, "Wrong word index");

            var doc = MockDocument("Doc", "Doc", "d", DateTime.Now);

            word.AddOccurrence(doc, 0, 0, WordLocation.Content);
            Assert.AreEqual(2, word.Occurrences.Count, "Wrong occurrences count");
            Assert.AreEqual(2, word.TotalOccurrences, "Wrong total occurrences count");

            var set = new SortedBasicWordInfoSet();

            word.BulkAddOccurrences(doc, set);

            Assert.AreEqual(1, word.Occurrences.Count, "Wrong occurrences count");
            Assert.AreEqual(1, word.TotalOccurrences, "Wrong total occurrences count");
            Assert.AreEqual(10, word.Occurrences[doc0][0].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(0, word.Occurrences[doc0][0].WordIndex, "Wrong word index");
        }
Example #13
0
        public void AddOccurrence_NullDocument()
        {
            Word word = new Word(1, "dummy");

            Assert.That(() => word.AddOccurrence(null, 0, 0, WordLocation.Content), Throws.ArgumentNullException);
        }
Example #14
0
 public void AddOccurrence_NullDocument()
 {
     Word word = new Word(1, "dummy");
     word.AddOccurrence(null, 0, 0, WordLocation.Content);
 }
Example #15
0
        public void RemoveOccurrences()
        {
            Word word = new Word(1, "hello");

            IDocument doc1 = MockDocument("Doc1", "Doc1", "d", DateTime.Now);
            IDocument doc2 = MockDocument("Doc2", "Doc2", "d", DateTime.Now);
            word.AddOccurrence(doc1, 0, 0, WordLocation.Content);
            word.AddOccurrence(doc1, 10, 1, WordLocation.Content);
            word.AddOccurrence(doc2, 5, 0, WordLocation.Content);
            Assert.AreEqual(2, word.Occurrences.Count, "Wrong occurrences count");
            Assert.AreEqual(3, word.TotalOccurrences, "Wrong total occurrences count");

            word.RemoveOccurrences(doc1);

            Assert.AreEqual(1, word.Occurrences.Count, "Wrong occurrences count");
            Assert.AreEqual(1, word.TotalOccurrences, "Wrong total occurrences count");
            Assert.AreEqual(5, word.Occurrences[doc2][0].FirstCharIndex, "Wrong start index");
            Assert.AreEqual(0, word.Occurrences[doc2][0].WordIndex, "Wrong word index");
        }
Example #16
0
        public void AddOccurrence_NullDocument()
        {
            Word word = new Word(1, "dummy");

            word.AddOccurrence(null, 0, 0, WordLocation.Content);
        }