/Source Code/UnitTests/Searching and Indexing/IndexerTest.vb
Visual Basic | 526 lines | 311 code | 112 blank | 103 comment | 22 complexity | 628308ebe866d9cb5b4693f76d5d22f0 MD5 | raw file
- Imports System.Collections.Generic
- Imports Microsoft.VisualStudio.TestTools.UnitTesting
- Imports PowerSong.FastSearching
-
- '''<summary>
- ''' This is a test class for IndexerTest and is intended
- ''' to contain all IndexerTest Unit Tests
- '''</summary>
- <TestClass()> _
- Public Class IndexerTest
- Inherits BaseSearchTester
-
- Private testContextInstance As TestContext
-
- '''<summary>
- ''' Gets or sets the test context which provides
- ''' information about and functionality for the current test run.
- '''</summary>
- Public Property TestContext() As TestContext
- Get
- Return testContextInstance
- End Get
- Set(ByVal value As TestContext)
- testContextInstance = Value
- End Set
- End Property
-
- <ClassCleanup()> _
- Public Shared Sub CleanUp()
- RemoveTemporaryFiles()
- End Sub
-
- ''' <summary>
- ''' Tests the number of documents in the index.
- ''' </summary>
- <TestMethod()> _
- Public Sub DocumentsIndexedTest()
-
- Dim Index As Indexer = New Indexer
- Assert.AreEqual(0, Index.DocumentCount, "Expected no documents in the index.")
-
- Index.AddFileContentsToIndex("A", "Contents of first file.")
- Index.AddFileContentsToIndex("B", "Contents of second file.")
- Index.AddFileContentsToIndex("C", "Contents of third file.")
- Assert.AreEqual(3, Index.DocumentCount, "Expected 3 documents in the index.")
-
- Index.AddFileContentsToIndex("D", "Contents of fourth file.")
- Assert.AreEqual(4, Index.DocumentCount, "Expected 4 documents in the index.")
-
- Index.RemoveDocumentFromIndex("A")
- Index.RemoveDocumentFromIndex("D")
- Assert.AreEqual(2, Index.DocumentCount, "Expected 2 documents in the index.")
-
- End Sub
-
- ''' <summary>
- ''' Tests document names in the index.
- ''' </summary>
- <TestMethod()> _
- Public Sub DocumentNameTest()
-
- Dim Index As Indexer = CreateBasicIndex()
-
- Assert.AreEqual("A", Index.DocumentName(0), "Document 1 has an invalid name.")
- Assert.AreEqual("B", Index.DocumentName(1), "Document 2 has an invalid name.")
- Assert.AreEqual("C", Index.DocumentName(2), "Document 3 has an invalid name.")
-
- End Sub
-
- ''' <summary>
- ''' Tests document names in the index, after removing a document.
- ''' </summary>
- <TestMethod()> _
- Public Sub DocumentNameAfterRemovalTest()
-
- Dim Index As Indexer = CreateBasicIndex
-
- Assert.AreEqual(3, Index.DocumentCount, "Incorrect number of documents indexed.")
- Assert.AreEqual("A", Index.DocumentName(0), "Document 1 has an invalid name.")
- Assert.AreEqual("B", Index.DocumentName(1), "Document 2 has an invalid name.")
- Assert.AreEqual("C", Index.DocumentName(2), "Document 3 has an invalid name.")
-
- Index.RemoveDocumentFromIndex("B")
- Assert.AreEqual(2, Index.DocumentCount, "Incorrect number of documents indexed.")
- Assert.AreEqual("A", Index.DocumentName(0), "Document 1 has an invalid name.")
- Assert.AreEqual("C", Index.DocumentName(2), "Document 3 has an invalid name.")
-
- Index.RemoveDocumentFromIndex("A")
- Assert.AreEqual(1, Index.DocumentCount, "Incorrect number of documents indexed.")
- Assert.AreEqual("C", Index.DocumentName(2), "Document 3 has an invalid name.")
-
- Index.RemoveDocumentFromIndex("C")
- Assert.AreEqual(0, Index.DocumentCount, "Expected no documents in index.")
-
- End Sub
-
- ''' <summary>
- ''' Tests document names accessed with an invalid index.
- ''' </summary>
- <TestMethod(), ExpectedException(GetType(ApplicationException))> _
- Public Sub DocumentNameInvalidIndexTest()
-
- Dim Index As Indexer = CreateBasicIndex()
- Dim Result As Integer = Index.DocumentName(3)
-
- End Sub
-
- ''' <summary>
- ''' Tests document numbers in the index.
- ''' </summary>
- <TestMethod()> _
- Public Sub DocumentNumbersTest()
-
- Dim Index As Indexer = CreateBasicIndex()
-
- Assert.AreEqual(0, Index.DocumentNumber("A"), "Document A has an invalid index.")
- Assert.AreEqual(1, Index.DocumentNumber("B"), "Document B has an invalid index.")
- Assert.AreEqual(2, Index.DocumentNumber("C"), "Document C has an invalid index.")
-
- End Sub
-
- ''' <summary>
- ''' Tests document numbers in the index, after removing a document.
- ''' </summary>
- <TestMethod()> _
- Public Sub DocumentNumbersAfterRemovalTest()
-
- Dim Index As Indexer = CreateBasicIndex()
-
- Assert.AreEqual(3, Index.DocumentCount, "Incorrect number of documents indexed.")
- Assert.AreEqual(0, Index.DocumentNumber("A"), "Document A has an invalid index.")
- Assert.AreEqual(1, Index.DocumentNumber("B"), "Document B has an invalid index.")
- Assert.AreEqual(2, Index.DocumentNumber("C"), "Document C has an invalid index.")
-
- Index.RemoveDocumentFromIndex("B")
- Assert.AreEqual(2, Index.DocumentCount, "Incorrect number of documents indexed.")
- Assert.AreEqual(0, Index.DocumentNumber("A"), "Document A has an invalid index.")
- Assert.AreEqual(2, Index.DocumentNumber("C"), "Document C has an invalid index.")
-
- Index.RemoveDocumentFromIndex("A")
- Assert.AreEqual(1, Index.DocumentCount, "Incorrect number of documents indexed.")
- Assert.AreEqual(2, Index.DocumentNumber("C"), "Document C has an invalid index.")
-
- Index.RemoveDocumentFromIndex("C")
- Assert.AreEqual(0, Index.DocumentCount, "Expected no documents in index.")
-
- End Sub
-
- ''' <summary>
- ''' Tests document numbers accessed with an invalid index.
- ''' </summary>
- <TestMethod(), ExpectedException(GetType(ApplicationException))> _
- Public Sub DocumentNumbersInvalidNameTest()
-
- Dim Index As Indexer = CreateBasicIndex()
- Dim Result As Integer = Index.DocumentNumber("Z")
-
- End Sub
-
- ''' <summary>
- ''' A test for ToString
- ''' </summary>
- <TestMethod()> _
- Public Sub ToStringTest()
-
- Dim Index As Indexer = CreateBasicIndex()
- Dim ActualString As String = "CONTENTS: 3 {A|1,B|1,C|1}" + Environment.NewLine + _
- "FILE: 3 {A|1,B|1,C|1}" + Environment.NewLine + _
- "FIRST: 1 {A|1}" + Environment.NewLine + _
- "OF: 3 {A|1,B|1,C|1}" + Environment.NewLine + _
- "SECOND: 1 {B|1}" + Environment.NewLine + _
- "THIRD: 1 {C|1}" + Environment.NewLine
- Assert.AreEqual(ActualString, Index.ToString, "Index cannot be rendered as a string.")
-
- End Sub
-
- ''' <summary>
- ''' Check that term frequencies can be determined.
- ''' </summary>
- <TestMethod()> _
- Public Sub TermFrequencyTest()
-
- ' Create a basic index
- Dim Index As New Indexer
- Index.AddFileContentsToIndex("A", "ALL TWO First First")
- Index.AddFileContentsToIndex("B", "ALL ONE Second Second")
- Index.AddFileContentsToIndex("C", "ALL TWO Third Third")
-
- ' Check first document
- Assert.AreEqual(1, Index.TermFrequency(0, "ALL"), "Incorrect term frequency.")
- Assert.AreEqual(1, Index.TermFrequency(0, "TWO"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(0, "ONE"), "Incorrect term frequency.")
- Assert.AreEqual(2, Index.TermFrequency(0, "First"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(0, "Second"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(0, "Third"), "Incorrect term frequency.")
-
- ' Check second document
- Assert.AreEqual(1, Index.TermFrequency(1, "ALL"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(1, "TWO"), "Incorrect term frequency.")
- Assert.AreEqual(1, Index.TermFrequency(1, "ONE"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(1, "First"), "Incorrect term frequency.")
- Assert.AreEqual(2, Index.TermFrequency(1, "Second"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(1, "Third"), "Incorrect term frequency.")
-
- ' Check third document
- Assert.AreEqual(1, Index.TermFrequency(2, "ALL"), "Incorrect term frequency.")
- Assert.AreEqual(1, Index.TermFrequency(2, "TWO"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(2, "ONE"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(2, "First"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(2, "Second"), "Incorrect term frequency.")
- Assert.AreEqual(2, Index.TermFrequency(2, "Third"), "Incorrect term frequency.")
-
- End Sub
-
- ''' <summary>
- ''' Check that term frequencies can be determined, even after removing documents.
- ''' </summary>
- <TestMethod()> _
- Public Sub TermFrequencyAfterDocumentRemovalTest()
-
- ' Create a basic index
- Dim Index As New Indexer
- Index.AddFileContentsToIndex("A", "ALL TWO First First")
- Index.AddFileContentsToIndex("B", "ALL ONE Second Second")
- Index.AddFileContentsToIndex("C", "ALL TWO Third Third")
-
- ' Remove a document
- Index.RemoveDocumentFromIndex("B")
-
- ' Check first document
- Assert.AreEqual(1, Index.TermFrequency(0, "ALL"), "Incorrect term frequency.")
- Assert.AreEqual(1, Index.TermFrequency(0, "TWO"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(0, "ONE"), "Incorrect term frequency.")
- Assert.AreEqual(2, Index.TermFrequency(0, "First"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(0, "Second"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(0, "Third"), "Incorrect term frequency.")
-
- ' Check third document
- Assert.AreEqual(1, Index.TermFrequency(2, "ALL"), "Incorrect term frequency.")
- Assert.AreEqual(1, Index.TermFrequency(2, "TWO"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(2, "ONE"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(2, "First"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(2, "Second"), "Incorrect term frequency.")
- Assert.AreEqual(2, Index.TermFrequency(2, "Third"), "Incorrect term frequency.")
-
- ' Remove a document
- Index.RemoveDocumentFromIndex("A")
-
- ' Check third document
- Assert.AreEqual(1, Index.TermFrequency(2, "ALL"), "Incorrect term frequency.")
- Assert.AreEqual(1, Index.TermFrequency(2, "TWO"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(2, "ONE"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(2, "First"), "Incorrect term frequency.")
- Assert.AreEqual(0, Index.TermFrequency(2, "Second"), "Incorrect term frequency.")
- Assert.AreEqual(2, Index.TermFrequency(2, "Third"), "Incorrect term frequency.")
-
- ' Remove a document
- Index.RemoveDocumentFromIndex("C")
-
- End Sub
-
- ''' <summary>
- ''' Prove an index can be saved and loaded, but don't do any advanced tests.
- ''' </summary>
- <TestMethod()> _
- Public Sub SaveLoadTest()
-
- ' Create the index
- Dim Index As Indexer = CreateBasicIndex()
-
- ' Save the index
- Dim FileName As String = GetTemporaryFileName()
- Index.Save(FileName)
- Assert.IsTrue(IO.File.Exists(FileName), "File does not exist.")
-
- ' Load the index
- Dim Result As Indexer = Indexer.LoadIndex(FileName)
- Assert.AreEqual(3, Result.DocumentCount, "Index not loaded.")
-
- End Sub
-
- ''' <summary>
- ''' Check that documents can be removed from the index.
- ''' </summary>
- <TestMethod()> _
- Public Sub RemoveFileFromIndexTest()
-
- Dim Index As Indexer = CreateBasicIndex()
- Assert.AreEqual(3, Index.DocumentCount, "Incorrect number of documents indexed.")
-
- Index.RemoveDocumentFromIndex("A")
- Assert.AreEqual(2, Index.DocumentCount, "Incorrect number of documents indexed.")
-
- Index.RemoveDocumentFromIndex("B")
- Assert.AreEqual(1, Index.DocumentCount, "Incorrect number of documents indexed.")
-
- Index.RemoveDocumentFromIndex("C")
- Assert.AreEqual(0, Index.DocumentCount, "Incorrect number of documents indexed.")
-
- End Sub
-
- ''' <summary>
- ''' Check that documents can be removed from the index, when it does not exist.
- ''' </summary>
- <TestMethod(), ExpectedException(GetType(ApplicationException))> _
- Public Sub RemoveNonExistingFileFromIndexTest()
-
- Dim Index As Indexer = CreateBasicIndex()
- Assert.AreEqual(3, Index.DocumentCount, "Incorrect number of documents indexed.")
-
- Index.RemoveDocumentFromIndex("Z")
-
- End Sub
-
- ''' <summary>
- ''' Test that the index can be cleared.
- ''' </summary>
- <TestMethod()> _
- Public Sub ClearTest()
-
- Dim Index As Indexer = CreateBasicIndex()
- Assert.AreEqual(3, Index.DocumentCount, "Incorrect number of documents in index.")
- Index.Clear()
- Assert.AreEqual(0, Index.DocumentCount, "Incorrect number of documents in index.")
-
- End Sub
-
- ''' <summary>
- ''' Tests that files can be added to the index.
- ''' </summary>
- <TestMethod()> _
- Public Sub AddFileToIndexTest()
-
- ' First create some temporary files
- Dim FileName1 As String = GetTemporaryFileName()
- Dim FileName2 As String = GetTemporaryFileName()
- IO.File.WriteAllLines(FileName1, New String() {"First line", "Second line"})
- IO.File.WriteAllLines(FileName2, New String() {"Third line", "Fourth line"})
-
- ' Check can add a file without virtual file name
- Dim Index As New Indexer
- Index.AddFileToIndex(FileName1)
- Assert.AreEqual(Index.DocumentCount, 1, "Incorrect number of documents indexed.")
- Assert.AreEqual(FileName1, Index.DocumentName(0), "Incorrect file name for document in index.")
-
- ' Check can add a file with virtual file name
- Index.AddFileToIndex("VIRTUAL", FileName2)
- Assert.AreEqual(Index.DocumentCount, 2, "Incorrect number of documents indexed.")
- Assert.AreEqual(FileName1, Index.DocumentName(0), "Incorrect file name for document in index.")
- Assert.AreEqual("VIRTUAL", Index.DocumentName(1), "Incorrect file name for document in index.")
-
- End Sub
-
- ''' <summary>
- ''' A test for AddFileContentsToIndex
- ''' </summary>
- <TestMethod()> _
- Public Sub AddFileContentsToIndexTest()
-
- Dim Index As New Indexer
- Assert.AreEqual(0, Index.DocumentCount, "Incorrect number of documents in the index.")
-
- Index.AddFileContentsToIndex("Filename1.txt", "This is the contents of the first file.")
- Assert.AreEqual(1, Index.DocumentCount, "Incorrect number of documents in the index.")
- Assert.AreEqual("Filename1.txt", Index.DocumentName(0), "Incorrect file name for file in index.")
-
- Index.AddFileContentsToIndex("Filename2.txt", "This is the contents of the second file.")
- Assert.AreEqual(2, Index.DocumentCount, "Incorrect number of documents in the index.")
- Assert.AreEqual("Filename1.txt", Index.DocumentName(0), "Incorrect file name for file in index.")
- Assert.AreEqual("Filename2.txt", Index.DocumentName(1), "Incorrect file name for file in index.")
-
- Index.AddFileContentsToIndex("Filename3.txt", "This is the contents of the third file.")
- Assert.AreEqual(3, Index.DocumentCount, "Incorrect number of documents in the index.")
- Assert.AreEqual("Filename1.txt", Index.DocumentName(0), "Incorrect file name for file in index.")
- Assert.AreEqual("Filename2.txt", Index.DocumentName(1), "Incorrect file name for file in index.")
- Assert.AreEqual("Filename3.txt", Index.DocumentName(2), "Incorrect file name for file in index.")
-
- End Sub
-
- ' TODO: Test adding duplicate files with same name
-
- ''' <summary>
- ''' A test for Indexer Constructor
- ''' </summary>
- <TestMethod()> _
- Public Sub IndexerConstructorTest()
-
- Dim Index As Indexer = New Indexer
- Assert.AreEqual(0, Index.DocumentCount, "There are documents in the index.")
-
- End Sub
-
- ''' <summary>
- ''' Tests the saving and loading of an empty index.
- ''' </summary>
- Public Sub SaveEmptyIndexTest()
-
- Dim Index As New Indexer
- Dim FileName As String = GetTemporaryFileName()
- Index.Save(FileName)
- Index = Indexer.LoadIndex(FileName)
- Assert.AreEqual(0, Index.DocumentCount, "Incorrect number of documents in index.")
-
- End Sub
-
- ''' <summary>
- ''' Tests that removing all but one document from the index, and then loading a saved version of
- ''' that index, works as expected.
- ''' </summary>
- Public Sub SaveAndLoadAfterDeletingAllButOneTest()
-
- Dim Index As Indexer = CreateBasicIndex()
- Index.RemoveDocumentFromIndex("A")
- Index.RemoveDocumentFromIndex("B")
- Dim FileName As String = GetTemporaryFileName()
- Index.Save(FileName)
- Index = Indexer.LoadIndex(FileName)
- Assert.AreEqual(1, Index.DocumentCount, "Incorrect number of documents in index.")
- Assert.AreEqual(2, Index.DocumentNumber("C"), "Incorrect document number for sole document in index.")
-
- End Sub
-
- ''' <summary>
- ''' Tests that files saved and subsequently loaded are identical to in-memory representation of index.
- ''' (Simple test)
- ''' </summary>
- <TestMethod()> _
- Public Sub SaveAndLoadTest1()
-
- ' Create a basic index, and remove the first document
- Dim Index1 As New Indexer
- Index1.AddFileContentsToIndex("A", "ALL TWO First First")
- Index1.AddFileContentsToIndex("B", "ALL ONE Second Second")
- Index1.RemoveDocumentFromIndex("A")
-
- ' Save the index
- Dim FileName As String = GetTemporaryFileName()
- Index1.Save(FileName)
-
- ' Load the index
- Dim Index2 As Indexer = Indexer.LoadIndex(FileName)
- Assert.AreEqual(1, Index1.DocumentCount, "Incorrect number of documents indexed.")
- Assert.AreEqual(1, Index2.DocumentCount, "Incorrect number of documents indexed.")
- Assert.AreEqual(Index1.DocumentCount, Index2.DocumentCount, "Incorrect number of documents in index.")
- Assert.AreEqual(Index1.DocumentName(1), Index2.DocumentName(1), "Mismatch in saved index.")
-
- ' Check the documents containing the word "ALL"
- Dim AllDocs1 As List(Of Integer) = Index1.DocumentsContainingWord("ALL")
- Dim AllDocs2 As List(Of Integer) = Index2.DocumentsContainingWord("ALL")
- Assert.AreEqual(AllDocs1.Count, AllDocs2.Count, "Invalid number of documents in loaded index.")
- Assert.AreEqual(AllDocs1(0), AllDocs2(0), "Incorrect document reference.")
-
- ' Test that the term frequency for each document had been recorded and loaded correctly
- Const I As Integer = 1
- Assert.AreEqual(Index1.TermFrequency(I, "ALL"), Index2.TermFrequency(I, "ALL"), "Incorrect term frequency for document " + I.ToString + ".")
- Assert.AreEqual(Index1.TermFrequency(I, "ONE"), Index2.TermFrequency(I, "ONE"), "Incorrect term frequency for document " + I.ToString + ".")
- Assert.AreEqual(Index1.TermFrequency(I, "TWO"), Index2.TermFrequency(I, "TWO"), "Incorrect term frequency for document " + I.ToString + ".")
- Assert.AreEqual(Index1.TermFrequency(I, "First"), Index2.TermFrequency(I, "First"), "Incorrect term frequency for document " + I.ToString + ".")
- Assert.AreEqual(Index1.TermFrequency(I, "Second"), Index2.TermFrequency(I, "Second"), "Incorrect term frequency for document " + I.ToString + ".")
- Assert.AreEqual(Index1.TermFrequency(I, "Third"), Index2.TermFrequency(I, "Third"), "Incorrect term frequency for document " + I.ToString + ".")
-
- End Sub
-
- ''' <summary>
- ''' Tests that files saved and subsequently loaded are identical to in-memory representation of index.
- ''' </summary>
- <TestMethod()> _
- Public Sub SaveAndLoadTest2()
-
- ' Create a basic index, and remove one document in the middle to make it interesting
- Dim Index1 As New Indexer
- Index1.AddFileContentsToIndex("A", "ALL TWO First First")
- Index1.AddFileContentsToIndex("REMOVE_ME", "First Second Third")
- Index1.AddFileContentsToIndex("B", "ALL ONE Second Second")
- Index1.AddFileContentsToIndex("C", "ALL TWO Third Third")
- Index1.RemoveDocumentFromIndex("REMOVE_ME")
-
- ' Save the index
- Dim FileName As String = GetTemporaryFileName()
- Index1.Save(FileName)
-
- ' Load the index
- Dim Index2 As Indexer = Indexer.LoadIndex(FileName)
- Assert.AreEqual(3, Index1.DocumentCount, "Incorrect number of documents indexed.")
- Assert.AreEqual(3, Index2.DocumentCount, "Incorrect number of documents indexed.")
- Assert.AreEqual(Index1.DocumentCount, Index2.DocumentCount, "Incorrect number of documents in index.")
- Assert.AreEqual(Index1.DocumentName(0), Index2.DocumentName(0), "Mismatch in saved index.")
- Assert.AreEqual(Index1.DocumentName(2), Index2.DocumentName(2), "Mismatch in saved index.")
- Assert.AreEqual(Index1.DocumentName(3), Index2.DocumentName(3), "Mismatch in saved index.")
-
- ' Check the documents containing the word "ALL"
- Dim AllDocs1 As List(Of Integer) = Index1.DocumentsContainingWord("ALL")
- Dim AllDocs2 As List(Of Integer) = Index2.DocumentsContainingWord("ALL")
- Assert.AreEqual(AllDocs1.Count, AllDocs2.Count, "Invalid number of documents in loaded index.")
- Assert.AreEqual(AllDocs1(0), AllDocs2(0), "Incorrect document reference.")
- Assert.AreEqual(AllDocs1(1), AllDocs2(1), "Incorrect document reference.")
- Assert.AreEqual(AllDocs1(2), AllDocs2(2), "Incorrect document reference.")
-
- ' Check the documents containing the word "TWO"
- Dim TwoDocs1 As List(Of Integer) = Index1.DocumentsContainingWord("TWO")
- Dim TwoDocs2 As List(Of Integer) = Index2.DocumentsContainingWord("TWO")
- Assert.AreEqual(TwoDocs1.Count, TwoDocs2.Count, "Invalid number of documents in loaded index.")
- Assert.AreEqual(TwoDocs1(0), TwoDocs2(0), "Incorrect document reference.")
- Assert.AreEqual(TwoDocs1(1), TwoDocs2(1), "Incorrect document reference.")
-
- ' Check the documents containing the word "ONE"
- Dim OneDocs1 As List(Of Integer) = Index1.DocumentsContainingWord("ONE")
- Dim OneDocs2 As List(Of Integer) = Index2.DocumentsContainingWord("ONE")
- Assert.AreEqual(OneDocs1.Count, OneDocs2.Count, "Invalid number of documents in loaded index.")
- Assert.AreEqual(OneDocs1(0), OneDocs2(0), "Incorrect document reference.")
-
- ' Test that the term frequency for each document had been recorded and loaded correctly
- For I As Integer = 0 To 3
- If I <> 1 Then
- Assert.AreEqual(Index1.TermFrequency(I, "ALL"), Index2.TermFrequency(I, "ALL"), "Incorrect term frequency for document " + I.ToString + ".")
- Assert.AreEqual(Index1.TermFrequency(I, "ONE"), Index2.TermFrequency(I, "ONE"), "Incorrect term frequency for document " + I.ToString + ".")
- Assert.AreEqual(Index1.TermFrequency(I, "TWO"), Index2.TermFrequency(I, "TWO"), "Incorrect term frequency for document " + I.ToString + ".")
- Assert.AreEqual(Index1.TermFrequency(I, "First"), Index2.TermFrequency(I, "First"), "Incorrect term frequency for document " + I.ToString + ".")
- Assert.AreEqual(Index1.TermFrequency(I, "Second"), Index2.TermFrequency(I, "Second"), "Incorrect term frequency for document " + I.ToString + ".")
- Assert.AreEqual(Index1.TermFrequency(I, "Third"), Index2.TermFrequency(I, "Third"), "Incorrect term frequency for document " + I.ToString + ".")
- End If
- Next
-
- End Sub
-
- End Class