コード例 #1
0
ファイル: GlobalIndexTest.cs プロジェクト: jonesm7/mtel
        public void TestIndexTermCanonicalInDoc()
        {
            GlobalIndex globalIndex = new GlobalIndex();
            Document    document    = new FileDocument("myFile");

            globalIndex.IndexCanonicalTermInDoc("string", document);

            IDictionary <string, int> expectedTermIdMap = new Dictionary <string, int>();

            expectedTermIdMap.Add("string", 0);
            Assert.IsTrue(Comparators.DictionariesAreEqual(expectedTermIdMap, globalIndex.GetTermIdMap()));

            Assert.AreEqual(0, globalIndex.RetrieveCanonicalTerm("string"));

            ISet <string> actualTermsCanonical = new HashSet <string>();

            actualTermsCanonical.UnionWith(globalIndex.GetCanonicalTerms());
            ISet <string> expectedTermsCanonical = new HashSet <string>();

            expectedTermsCanonical.Add("string");
            Assert.IsTrue(Comparators.SetsAreEqual(expectedTermsCanonical, actualTermsCanonical));

            ISet <string> expectedVariants = new HashSet <string>();

            Assert.IsTrue(Comparators.SetsAreEqual(expectedVariants, globalIndex.RetrieveVariantsOfCanonicalTerm("string")));

            Assert.AreEqual("string", globalIndex.RetrieveCanonicalTerm(0));

            IDictionary <Document, int> expectedDocMap = new Dictionary <Document, int>();

            expectedDocMap.Add(document, 0);
            Assert.IsTrue(Comparators.DictionariesAreEqual(expectedDocMap, globalIndex.GetDocMap()));

            ISet <Document> expectedDocuments = new HashSet <Document>();

            expectedDocuments.Add(document);
            Assert.IsTrue(Comparators.SetsAreEqual(expectedDocuments, globalIndex.GetDocuments()));

            IDictionary <int, ISet <int> > expectedTermsToDocs = new Dictionary <int, ISet <int> >();
            ISet <int> expectedDocIds = new HashSet <int>();

            expectedDocIds.Add(0);
            expectedTermsToDocs.Add(0, expectedDocIds);
            Assert.IsTrue(Comparators.DictionariesOfSetsAreEqual(expectedTermsToDocs, globalIndex.GetTermToDocs()));
        }