Beispiel #1
0
        public void TestAddition()
        {
            GeneralizedSuffixTree @in = new GeneralizedSuffixTree();

            string[] words = new string[] { "cacaor", "caricato", "cacato", "cacata", "caricata", "cacao", "banana" };
            var      wLen  = words.Length;

            for (int i = 0; i < wLen; ++i)
            {
                @in.Put(words[i], i);

                foreach (string s in Utils.GetSubstrings(words[i]))
                {
                    var result = @in.Search(s);
                    Assert.IsNotNull(result, "result null for string " + s + " after adding " + words[i]);
                    Assert.IsTrue(result.Contains(i), "substring " + s + " not found after adding " + words[i]);
                }
            }
            // verify post-addition
            for (int i = 0; i < wLen; ++i)
            {
                foreach (string s in Utils.GetSubstrings(words[i]))
                {
                    var result = @in.Search(s);
                    Assert.IsNotNull(result, "result null for string " + s + " after adding " + words[i]);
                    Assert.IsTrue(result.Contains(i), "substring " + s + " not found after adding " + words[i]);
                }
            }

            // add again, to see if it's stable
            for (int i = 0; i < wLen; ++i)
            {
                @in.Put(words[i], i + wLen);

                foreach (string s in Utils.GetSubstrings(words[i]))
                {
                    Assert.IsTrue(@in.Search(s).Contains(i + wLen));
                }
            }

            @in.ComputeCount();
            TestResultsCount(@in.GetRoot());

            Assert.IsNull(@in.Search("aoca"));
        }
Beispiel #2
0
        public void TestSampleAddition()
        {
            GeneralizedSuffixTree @in = new GeneralizedSuffixTree();

            string[] words = new string[] { "libertypike",
                                            "franklintn",
                                            "carothersjohnhenryhouse",
                                            "carothersezealhouse",
                                            "acrossthetauntonriverfromdightonindightonrockstatepark",
                                            "dightonma",
                                            "dightonrock",
                                            "6mineoflowgaponlowgapfork",
                                            "lowgapky",
                                            "lemasterjohnjandellenhouse",
                                            "lemasterhouse",
                                            "70wilburblvd",
                                            "poughkeepsieny",
                                            "freerhouse",
                                            "701laurelst",
                                            "conwaysc",
                                            "hollidayjwjrhouse",
                                            "mainandappletonsts",
                                            "menomoneefallswi",
                                            "mainstreethistoricdistrict",
                                            "addressrestricted",
                                            "brownsmillsnj",
                                            "hanoverfurnace",
                                            "hanoverbogironfurnace",
                                            "sofsavannahatfergusonaveandbethesdard",
                                            "savannahga",
                                            "bethesdahomeforboys",
                                            "bethesda" };
            var wLen = words.Length;

            for (int i = 0; i < wLen; ++i)
            {
                @in.Put(words[i], i);

                foreach (string s in Utils.GetSubstrings(words[i]))
                {
                    var result = @in.Search(s);
                    Assert.IsNotNull(result, "result null for string " + s + " after adding " + words[i]);
                    Assert.IsTrue(result.Contains(i), "substring " + s + " not found after adding " + words[i]);
                }
            }
            // verify post-addition
            for (int i = 0; i < wLen; ++i)
            {
                foreach (string s in Utils.GetSubstrings(words[i]))
                {
                    Assert.IsTrue(@in.Search(s).Contains(i));
                }
            }

            // add again, to see if it's stable
            for (int i = 0; i < wLen; ++i)
            {
                @in.Put(words[i], i + wLen);

                foreach (string s in Utils.GetSubstrings(words[i]))
                {
                    Assert.IsTrue(@in.Search(s).Contains(i + wLen));
                }
            }

            @in.ComputeCount();
            TestResultsCount(@in.GetRoot());

            Assert.IsNull(@in.Search("aoca"));
        }