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"); }
public void TryGetValue_NullKey() { OccurrenceDictionary dic = new OccurrenceDictionary(); SortedBasicWordInfoSet set = null; dic.TryGetValue(null, out set); }
public void Values() { OccurrenceDictionary dic = new OccurrenceDictionary(); IDocument doc1 = MockDocument("Doc1", "Doc1", "d", DateTime.Now); IDocument doc2 = MockDocument("Doc2", "Doc2", "d", DateTime.Now); SortedBasicWordInfoSet set1 = new SortedBasicWordInfoSet(); set1.Add(new BasicWordInfo(0, 0, WordLocation.Content)); SortedBasicWordInfoSet set2 = new SortedBasicWordInfoSet(); set2.Add(new BasicWordInfo(1, 1, WordLocation.Title)); dic.Add(doc1, set1); dic.Add(doc2, set2); Assert.AreEqual(2, dic.Values.Count, "Wrong value count"); bool set1Found = false, set2Found = false; foreach (SortedBasicWordInfoSet set in dic.Values) { if (set[0].FirstCharIndex == 0) { set1Found = true; } if (set[0].FirstCharIndex == 1) { set2Found = true; } } Assert.IsTrue(set1Found, "Set1 not found"); Assert.IsTrue(set2Found, "Set2 not found"); }
public void RemoveExtended() { OccurrenceDictionary dic = new OccurrenceDictionary(); SortedBasicWordInfoSet set1 = new SortedBasicWordInfoSet(); set1.Add(new BasicWordInfo(5, 0, WordLocation.Content)); set1.Add(new BasicWordInfo(12, 1, WordLocation.Keywords)); SortedBasicWordInfoSet set2 = new SortedBasicWordInfoSet(); set2.Add(new BasicWordInfo(1, 0, WordLocation.Content)); set2.Add(new BasicWordInfo(4, 1, WordLocation.Title)); dic.Add(MockDocument("Doc1", "Doc", "doc", DateTime.Now), set1); dic.Add(MockDocument("Doc2", "Doc", "doc", DateTime.Now), set2); List <DumpedWordMapping> dm = dic.RemoveExtended(MockDocument("Doc1", "Doc", "doc", DateTime.Now), 1); Assert.AreEqual(2, dm.Count, "Wrong count"); Assert.IsTrue(dm.Find(delegate(DumpedWordMapping m) { return(m.WordID == 1 && m.DocumentID == 1 && m.FirstCharIndex == 5 && m.WordIndex == 0 && m.Location == WordLocation.Content.Location); }) != null, "Mapping not found"); Assert.IsTrue(dm.Find(delegate(DumpedWordMapping m) { return(m.WordID == 1 && m.DocumentID == 1 && m.FirstCharIndex == 12 && m.WordIndex == 1 && m.Location == WordLocation.Keywords.Location); }) != null, "Mapping not found"); }
public void GetEnumerator() { SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); Assert.IsTrue(set.Add(new BasicWordInfo(1, 0, WordLocation.Content)), "Add should return true (adding new item)"); Assert.IsTrue(set.Add(new BasicWordInfo(3, 1, WordLocation.Content)), "Add should return true (adding new item)"); Assert.AreEqual(2, set.Count); int count = 0; foreach (BasicWordInfo item in set) { if (count == 0) { Assert.AreEqual(1, item.FirstCharIndex, "Wrong start index for current item"); } if (count == 0) { Assert.AreEqual(0, item.WordIndex, "Wrong word index for current item"); } if (count == 1) { Assert.AreEqual(3, item.FirstCharIndex, "Wrong start index for current item"); } if (count == 1) { Assert.AreEqual(1, item.WordIndex, "Wrong word index for current item"); } count++; } Assert.AreEqual(2, count); }
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); }
public void Constructor_WithCapacity() { SortedBasicWordInfoSet sut = new SortedBasicWordInfoSet(10); Assert.Equal(0, sut.Count); Assert.Equal(10, sut.Capacity); }
public void Add_NewItem() { SortedBasicWordInfoSet sut = new SortedBasicWordInfoSet(); Assert.True(sut.Add(new BasicWordInfo(10, 1, WordLocation.Content)), "Add should return true (adding new item)"); Assert.Equal(1, sut.Count); }
public void GetEnumerator() { SortedBasicWordInfoSet sut = new SortedBasicWordInfoSet(); Assert.True(sut.Add(new BasicWordInfo(1, 0, WordLocation.Content)), "Add should return true (adding new item)"); Assert.True(sut.Add(new BasicWordInfo(3, 1, WordLocation.Content)), "Add should return true (adding new item)"); Assert.Equal(2, sut.Count); int count = 0; foreach (BasicWordInfo item in sut) { if (count == 0) { Assert.Equal(1, item.FirstCharIndex); } if (count == 0) { Assert.Equal(0, item.WordIndex); } if (count == 1) { Assert.Equal(3, item.FirstCharIndex); } if (count == 1) { Assert.Equal(1, item.WordIndex); } count++; } Assert.Equal(2, count); }
public void Indexer_Index_TooBig() { SortedBasicWordInfoSet sut = new SortedBasicWordInfoSet(); var ex = Assert.Throws <IndexOutOfRangeException>(() => sut[1]); Assert.Equal("Index should be greater than or equal to zero and less than the number of items in the set.", ex.Message); }
public void Constructor_WithCapacity() { SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(10); Assert.AreEqual(0, set.Count, "Wrong count (set should be empty)"); Assert.AreEqual(10, set.Capacity, "Wrong capacity (capacity should be ensured)"); }
public void TryGetValue_NullKey() { OccurrenceDictionary dic = new OccurrenceDictionary(); SortedBasicWordInfoSet set = null; Assert.That(() => dic.TryGetValue(null, out set), Throws.ArgumentNullException); }
public void Add_NewItem() { SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); Assert.IsTrue(set.Add(new BasicWordInfo(10, 1, WordLocation.Content)), "Add should return true (adding new item)"); Assert.AreEqual(1, set.Count, "Wrong count (set should contain 1 item)"); }
public void Add_ExistingItem() { SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); Assert.IsTrue(set.Add(new BasicWordInfo(2, 0, WordLocation.Content)), "Add should return true (adding new item)"); Assert.AreEqual(1, set.Count, "Wrong count (set should contain 1 item)"); Assert.IsFalse(set.Add(new BasicWordInfo(2, 0, WordLocation.Content)), "Add should return false (adding existing item)"); Assert.AreEqual(1, set.Count, "Wrong count (set should contain 1 item)"); }
public void Add_ExistingItem() { SortedBasicWordInfoSet sut = new SortedBasicWordInfoSet(); Assert.True(sut.Add(new BasicWordInfo(2, 0, WordLocation.Content)), "Add should return true (adding new item)"); Assert.Equal(1, sut.Count); Assert.False(sut.Add(new BasicWordInfo(2, 0, WordLocation.Content)), "Add should return false (adding existing item)"); Assert.Equal(1, sut.Count); }
public void Contains() { SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); Assert.IsFalse(set.Contains(new BasicWordInfo(1, 0, WordLocation.Content)), "Contains should return false (inexistent item)"); Assert.IsTrue(set.Add(new BasicWordInfo(1, 0, WordLocation.Content)), "Add should return true (adding new item)"); Assert.IsTrue(set.Contains(new BasicWordInfo(1, 0, WordLocation.Content)), "Contains should return true (item exists)"); Assert.AreEqual(1, set.Count, "Wrong count (set should contain 1 item"); Assert.IsFalse(set.Contains(new BasicWordInfo(10, 2, WordLocation.Content)), "Contains should return false (inexistent item)"); }
public void Contains() { SortedBasicWordInfoSet sut = new SortedBasicWordInfoSet(); Assert.False(sut.Contains(new BasicWordInfo(1, 0, WordLocation.Content)), "Contains should return false (inexistent item)"); Assert.True(sut.Add(new BasicWordInfo(1, 0, WordLocation.Content)), "Add should return true (adding new item)"); Assert.True(sut.Contains(new BasicWordInfo(1, 0, WordLocation.Content)), "Contains should return true (item exists)"); Assert.Equal(1, sut.Count); Assert.False(sut.Contains(new BasicWordInfo(10, 2, WordLocation.Content)), "Contains should return false (inexistent item)"); }
public void Add_ExistingItem() { var set = new SortedBasicWordInfoSet(); Assert.IsTrue(set.Add(new BasicWordInfo(2, 0, WordLocation.Content)), "Add should return true (adding new item)"); Assert.AreEqual(1, set.Count, "Wrong count (set should contain 1 item)"); Assert.IsFalse(set.Add(new BasicWordInfo(2, 0, WordLocation.Content)), "Add should return false (adding existing item)"); Assert.AreEqual(1, set.Count, "Wrong count (set should contain 1 item)"); }
public void Clear() { SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); Assert.IsTrue(set.Add(new BasicWordInfo(10, 2, WordLocation.Content)), "Add should return true (adding new item)"); Assert.IsTrue(set.Add(new BasicWordInfo(2, 1, WordLocation.Content)), "Add should return true (adding new item)"); Assert.AreEqual(2, set.Count, "Wrong count (set should contain 2 items)"); set.Clear(); Assert.AreEqual(0, set.Count, "Wrong count (set should be empty)"); Assert.IsFalse(set.Contains(new BasicWordInfo(10, 2, WordLocation.Content)), "Contains should return false (empty set)"); Assert.IsFalse(set.Contains(new BasicWordInfo(2, 1, WordLocation.Content)), "Contains should return false (empty set)"); }
public void Clear() { SortedBasicWordInfoSet sut = new SortedBasicWordInfoSet(); Assert.True(sut.Add(new BasicWordInfo(10, 2, WordLocation.Content)), "Add should return true (adding new item)"); Assert.True(sut.Add(new BasicWordInfo(2, 1, WordLocation.Content)), "Add should return true (adding new item)"); Assert.Equal(2, sut.Count); sut.Clear(); Assert.Equal(0, sut.Count); Assert.False(sut.Contains(new BasicWordInfo(10, 2, WordLocation.Content)), "Contains should return false (empty set)"); Assert.False(sut.Contains(new BasicWordInfo(2, 1, WordLocation.Content)), "Contains should return false (empty set)"); }
public void CopyTo() { OccurrenceDictionary dic = new OccurrenceDictionary(); SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); set.Add(new BasicWordInfo(1, 1, WordLocation.Title)); dic.Add(MockDocument("Doc", "Doc", "d", DateTime.Now), set); KeyValuePair <IDocument, SortedBasicWordInfoSet>[] array = new KeyValuePair <IDocument, SortedBasicWordInfoSet> [1]; dic.CopyTo(array, 0); Assert.Equal("Doc", array[0].Key.Name); Assert.Equal(1, array[0].Value.Count); Assert.Equal(1, array[0].Value[0].FirstCharIndex); }
public void Remove_KV() { OccurrenceDictionary dic = new OccurrenceDictionary(); SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); set.Add(new BasicWordInfo(5, 0, WordLocation.Content)); dic.Add(MockDocument("Doc1", "Doc1", "d", DateTime.Now), set); dic.Add(MockDocument("Doc2", "Doc2", "d", DateTime.Now), new SortedBasicWordInfoSet()); Assert.AreEqual(2, dic.Count, "Wrong initial count"); Assert.IsFalse(dic.Remove(MockDocument("Doc3", "Doc3", "d", DateTime.Now)), "Remove should return false"); Assert.IsTrue(dic.Remove(MockDocument("Doc1", "Doc1", "d", DateTime.Now)), "Remove should return true"); Assert.AreEqual(1, dic.Count, "Wrong count"); }
public void CopyTo() { OccurrenceDictionary dic = new OccurrenceDictionary(); SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); set.Add(new BasicWordInfo(1, 1, WordLocation.Title)); dic.Add(MockDocument("Doc", "Doc", "d", DateTime.Now), set); KeyValuePair <IDocument, SortedBasicWordInfoSet>[] array = new KeyValuePair <IDocument, SortedBasicWordInfoSet> [1]; dic.CopyTo(array, 0); Assert.IsNotNull(array[0], "Array[0] should not be null"); Assert.AreEqual("Doc", array[0].Key.Name, "Wrong array item"); Assert.AreEqual(1, array[0].Value.Count, "Wrong count"); Assert.AreEqual(1, array[0].Value[0].FirstCharIndex, "Wrong first char index"); }
public void Indexer() { SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); Assert.IsTrue(set.Add(new BasicWordInfo(1, 0, WordLocation.Content)), "Add should return true (adding new item)"); Assert.IsTrue(set.Add(new BasicWordInfo(10, 1, WordLocation.Content)), "Add should return true (adding new item)"); Assert.IsTrue(set.Add(new BasicWordInfo(3, 2, WordLocation.Content)), "Add should return true (adding new item)"); Assert.AreEqual(3, set.Count); Assert.AreEqual(1, set[0].FirstCharIndex, "Wrong start index at index 0"); Assert.AreEqual(0, set[0].WordIndex, "Wrong word index at index 0"); Assert.AreEqual(10, set[1].FirstCharIndex, "Wrong start index at index 1"); Assert.AreEqual(1, set[1].WordIndex, "Wrong word index at index 1"); Assert.AreEqual(3, set[2].FirstCharIndex, "Wrong start index at index 2"); Assert.AreEqual(2, set[2].WordIndex, "Wrong word index at index 2"); }
public void Indexer() { SortedBasicWordInfoSet sut = new SortedBasicWordInfoSet(); Assert.True(sut.Add(new BasicWordInfo(1, 0, WordLocation.Content)), "Add should return true (adding new item)"); Assert.True(sut.Add(new BasicWordInfo(10, 1, WordLocation.Content)), "Add should return true (adding new item)"); Assert.True(sut.Add(new BasicWordInfo(3, 2, WordLocation.Content)), "Add should return true (adding new item)"); Assert.Equal(3, sut.Count); Assert.Equal(1, sut[0].FirstCharIndex); Assert.Equal(0, sut[0].WordIndex); Assert.Equal(10, sut[1].FirstCharIndex); Assert.Equal(1, sut[1].WordIndex); Assert.Equal(3, sut[2].FirstCharIndex); Assert.Equal(2, sut[2].WordIndex); }
public void GetEnumerator() { SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); Assert.IsTrue(set.Add(new BasicWordInfo(1, 0, WordLocation.Content)), "Add should return true (adding new item)"); Assert.IsTrue(set.Add(new BasicWordInfo(3, 1, WordLocation.Content)), "Add should return true (adding new item)"); Assert.AreEqual(2, set.Count); int count = 0; foreach(BasicWordInfo item in set) { if(count == 0) Assert.AreEqual(1, item.FirstCharIndex, "Wrong start index for current item"); if(count == 0) Assert.AreEqual(0, item.WordIndex, "Wrong word index for current item"); if(count == 1) Assert.AreEqual(3, item.FirstCharIndex, "Wrong start index for current item"); if(count == 1) Assert.AreEqual(1, item.WordIndex, "Wrong word index for current item"); count++; } Assert.AreEqual(2, count); }
public void Indexer_Get() { OccurrenceDictionary dic = new OccurrenceDictionary(); IDocument doc1 = MockDocument("Doc1", "Doc1", "d", DateTime.Now); SortedBasicWordInfoSet set1 = new SortedBasicWordInfoSet(); set1.Add(new BasicWordInfo(1, 1, WordLocation.Content)); dic.Add(doc1, set1); SortedBasicWordInfoSet output = dic[MockDocument("Doc1", "Doc1", "d", DateTime.Now)]; Assert.IsNotNull(output, "Output should not be null"); Assert.AreEqual(1, set1.Count, "Wrong count"); Assert.AreEqual(1, set1[0].FirstCharIndex, "Wrong first char index"); }
public void Indexer_Get() { OccurrenceDictionary dic = new OccurrenceDictionary(); IDocument doc1 = MockDocument("Doc1", "Doc1", "d", DateTime.Now); SortedBasicWordInfoSet set1 = new SortedBasicWordInfoSet(); set1.Add(new BasicWordInfo(1, 1, WordLocation.Content)); dic.Add(doc1, set1); SortedBasicWordInfoSet output = dic[MockDocument("Doc1", "Doc1", "d", DateTime.Now)]; Assert.NotNull(output); Assert.Equal(1, set1.Count); Assert.Equal(1, set1[0].FirstCharIndex); }
public void Constructor_3Params_1Occurrence() { OccurrenceDictionary occ = new OccurrenceDictionary(); IDocument doc = MockDocument("Doc", "Doc", "d", DateTime.Now); SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); set.Add(new BasicWordInfo(0, 0, WordLocation.Content)); occ.Add(doc, set); Word sut = new Word(12, "Hello", occ); Assert.Equal("hello", sut.Text); Assert.Single(sut.Occurrences); Assert.Equal(1, sut.TotalOccurrences); }
public void Remove() { var set = new SortedBasicWordInfoSet(); Assert.IsFalse(set.Remove(new BasicWordInfo(1, 0, WordLocation.Content)), "Remove should return false (removing inexistent item"); Assert.IsTrue(set.Add(new BasicWordInfo(1, 0, WordLocation.Content)), "Add should return true (adding new item)"); Assert.AreEqual(1, set.Count, "Wrong count (set should contain 1 item)"); Assert.IsTrue(set.Contains(new BasicWordInfo(1, 0, WordLocation.Content)), "Contains should return true (item exists)"); Assert.IsTrue(set.Remove(new BasicWordInfo(1, 0, WordLocation.Content)), "Remove should return true (removing existing item)"); Assert.IsFalse(set.Contains(new BasicWordInfo(1, 0, WordLocation.Content)), "Contains should return false (inexistent item)"); Assert.AreEqual(0, set.Count, "Wrong count (set should be empty)"); }
public void Constructor_3Params_1Occurrence() { OccurrenceDictionary occ = new OccurrenceDictionary(); IDocument doc = MockDocument("Doc", "Doc", "d", DateTime.Now); SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); set.Add(new BasicWordInfo(0, 0, WordLocation.Content)); occ.Add(doc, set); Word word = new Word(12, "Hello", occ); Assert.AreEqual("hello", word.Text, "Wrong word text"); Assert.AreEqual(1, word.Occurrences.Count, "Wrong occurrences count"); Assert.AreEqual(1, word.TotalOccurrences, "Wrong total occurrences count"); }
public void Indexer_Set() { OccurrenceDictionary dic = new OccurrenceDictionary(); dic.Add(MockDocument("Doc1", "Doc1", "d", DateTime.Now), new SortedBasicWordInfoSet()); SortedBasicWordInfoSet set1 = new SortedBasicWordInfoSet(); set1.Add(new BasicWordInfo(1, 1, WordLocation.Content)); dic[MockDocument("Doc1", "Doc1", "d", DateTime.Now)] = set1; SortedBasicWordInfoSet output = dic[MockDocument("Doc1", "Doc1", "d", DateTime.Now)]; Assert.AreEqual(1, output.Count, "Wrong count"); Assert.AreEqual(1, output[0].FirstCharIndex, "Wrong first char index"); }
public void Values() { OccurrenceDictionary dic = new OccurrenceDictionary(); IDocument doc1 = MockDocument("Doc1", "Doc1", "d", DateTime.Now); IDocument doc2 = MockDocument("Doc2", "Doc2", "d", DateTime.Now); SortedBasicWordInfoSet set1 = new SortedBasicWordInfoSet(); set1.Add(new BasicWordInfo(0, 0, WordLocation.Content)); SortedBasicWordInfoSet set2 = new SortedBasicWordInfoSet(); set2.Add(new BasicWordInfo(1, 1, WordLocation.Title)); dic.Add(doc1, set1); dic.Add(doc2, set2); Assert.AreEqual(2, dic.Values.Count, "Wrong value count"); bool set1Found = false, set2Found = false; foreach(SortedBasicWordInfoSet set in dic.Values) { if(set[0].FirstCharIndex == 0) set1Found = true; if(set[0].FirstCharIndex == 1) set2Found = true; } Assert.IsTrue(set1Found, "Set1 not found"); Assert.IsTrue(set2Found, "Set2 not found"); }
/// <summary> /// Adds a bulk of occurrences of the word in a document, <b>removing all the old positions</b>, if any. /// </summary> /// <param name="document">The document.</param> /// <param name="positions">The positions.</param> /// <remarks>If <b>positions</b> is empty, the effect of the invocation of the method is equal to /// that of <see cref="RemoveOccurrences" /> with the same <b>document</b>. /// Bulk-adding the occurrences is <b>O(1)</b>.</remarks> /// <exception cref="ArgumentNullException">If <paramref name="document"/> or <paramref name="positions"/> are <c>null</c>.</exception> public void BulkAddOccurrences(IDocument document, SortedBasicWordInfoSet positions) { if(document == null) throw new ArgumentNullException("document"); if(positions == null) throw new ArgumentNullException("positions"); lock(occurrences) { if(occurrences.ContainsKey(document)) { if(positions.Count == 0) RemoveOccurrences(document); else occurrences[document] = positions; } else occurrences.Add(document, positions); } }
public void CopyTo() { OccurrenceDictionary dic = new OccurrenceDictionary(); SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); set.Add(new BasicWordInfo(1, 1, WordLocation.Title)); dic.Add(MockDocument("Doc", "Doc", "d", DateTime.Now), set); KeyValuePair<IDocument, SortedBasicWordInfoSet>[] array = new KeyValuePair<IDocument, SortedBasicWordInfoSet>[1]; dic.CopyTo(array, 0); Assert.IsNotNull(array[0], "Array[0] should not be null"); Assert.AreEqual("Doc", array[0].Key.Name, "Wrong array item"); Assert.AreEqual(1, array[0].Value.Count, "Wrong count"); Assert.AreEqual(1, array[0].Value[0].FirstCharIndex, "Wrong first char index"); }
public void Indexer_InvalidIndex_TooBig() { SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); BasicWordInfo i = set[1]; }
public void Indexer_Set_NullIndex() { OccurrenceDictionary dic = new OccurrenceDictionary(); dic[null] = new SortedBasicWordInfoSet(); }
public void Constructor_InvalidCapacity() { SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(0); }
public void Indexer_InvalidIndex_Negative() { SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); BasicWordInfo i = set[-1]; }
/// <summary> /// Stores an occurrence. /// </summary> /// <param name="document">The document the occurrence is referred to.</param> /// <param name="firstCharIndex">The index of the first character of the word in the document.</param> /// <param name="wordIndex">The index of the word in the document.</param> /// <param name="location">The location of the word.</param> /// <remarks>Adding an occurrence is <b>O(n)</b>, where <b>n</b> is the number of occurrences /// of the word already stored for the same document. If there were no occurrences previously stored, /// the operation is <b>O(1)</b>.</remarks> /// <exception cref="ArgumentNullException">If <paramref name="document"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="firstCharIndex"/> or <paramref name="wordIndex"/> are less than zero.</exception> public void AddOccurrence(IDocument document, ushort firstCharIndex, ushort wordIndex, WordLocation location) { if(document == null) throw new ArgumentNullException("document"); if(firstCharIndex < 0) throw new ArgumentOutOfRangeException("firstCharIndex", "Invalid first char index: must be greater than or equal to zero"); if(wordIndex < 0) throw new ArgumentOutOfRangeException("wordIndex", "Invalid word index: must be greater than or equal to zero"); lock(occurrences) { if(occurrences.ContainsKey(document)) { // Existing document occurrences[document].Add(new BasicWordInfo(firstCharIndex, wordIndex, location)); } else { // New document SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); set.Add(new BasicWordInfo(firstCharIndex, wordIndex, location)); occurrences.Add(document, set); } } }
public void RemoveExtended() { OccurrenceDictionary dic = new OccurrenceDictionary(); SortedBasicWordInfoSet set1 = new SortedBasicWordInfoSet(); set1.Add(new BasicWordInfo(5, 0, WordLocation.Content)); set1.Add(new BasicWordInfo(12, 1, WordLocation.Keywords)); SortedBasicWordInfoSet set2 = new SortedBasicWordInfoSet(); set2.Add(new BasicWordInfo(1, 0, WordLocation.Content)); set2.Add(new BasicWordInfo(4, 1, WordLocation.Title)); dic.Add(MockDocument("Doc1", "Doc", "doc", DateTime.Now), set1); dic.Add(MockDocument("Doc2", "Doc", "doc", DateTime.Now), set2); List<DumpedWordMapping> dm = dic.RemoveExtended(MockDocument("Doc1", "Doc", "doc", DateTime.Now), 1); Assert.AreEqual(2, dm.Count, "Wrong count"); Assert.IsTrue(dm.Find(delegate(DumpedWordMapping m) { return m.WordID == 1 && m.DocumentID == 1 && m.FirstCharIndex == 5 && m.WordIndex == 0 && m.Location == WordLocation.Content.Location; }) != null, "Mapping not found"); Assert.IsTrue(dm.Find(delegate(DumpedWordMapping m) { return m.WordID == 1 && m.DocumentID == 1 && m.FirstCharIndex == 12 && m.WordIndex == 1 && m.Location == WordLocation.Keywords.Location; }) != null, "Mapping not found"); }
public void Constructor_Default() { SortedBasicWordInfoSet set = new SortedBasicWordInfoSet(); Assert.AreEqual(0, set.Count, "Wrong count (set should be empty)"); }