Пример #1
0
 public void TestCannotGetNullKey()
 {
     TST<int> tst = new TST<int>();
     tst.Put("bla", 1);
     Assert.IsTrue(tst.Contains("bla"));
     tst.Get(null);
 }
Пример #2
0
 public void TestCannotGetEmptyStringKey()
 {
     TST<int> tst = new TST<int>();
     tst.Put("bla", 1);
     Assert.IsTrue(tst.Contains("bla"));
     tst.Get("");
 }
Пример #3
0
 public void TestCannotPutNull()
 {
     TST<int> tst = new TST<int>();
     tst.Put("bla", 1);
     Assert.IsTrue(tst.Contains("bla"));
     tst.Put(null, 0);
 }
Пример #4
0
 public void TestReadKeys()
 {
     TST<int> tst = new TST<int>();
     string[] keys = testKeys.Split(' ');
     for (int i = 0; i < keys.Length; i++)
     {
         tst.Put(keys[i], i);
     }
     for (int i = 0; i < keys.Length; i++)
     {
         Assert.IsTrue(tst.Contains(keys[i]));
         Assert.IsTrue(tst.Get(keys[i]) == i);
     }
 }
Пример #5
0
 public void TestKeyHasToHaveValue()
 {
     TST<int> tst = new TST<int>();
     tst.Put("seashells", 1);
     Assert.IsTrue(tst.Contains("seashells"));
     // "sea" is only a prefix of the key
     tst.Get("sea");
 }
Пример #6
0
        static void Main(string[] args)
        {
            // TESTING search tree Insertion
            // 2643 adds
            Console.WriteLine(" Ternary Search Tree Add ");
            Stopwatch myStopWatch = new Stopwatch();
            myData    data        = new myData();
            TST <int> myTry       = new TST <int>();

            myStopWatch.Start();
            for (int i = 0; i < 3; i++)
            {
                myTry.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("3 Insertions: " + myStopWatch.Elapsed);

            // 1000 adds

            myStopWatch = new Stopwatch();
            data        = new myData();
            myTry       = new TST <int>();
            myStopWatch.Start();
            for (int i = 0; i < 9; i++)
            {
                myTry.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("9 Insertions: " + myStopWatch.Elapsed);
            // 100 adds

            myStopWatch = new Stopwatch();
            data        = new myData();
            myTry       = new TST <int>();
            myStopWatch.Start();
            for (int i = 0; i < 27; i++)
            {
                myTry.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("27 Insertions: " + myStopWatch.Elapsed);

            myStopWatch = new Stopwatch();
            data        = new myData();
            myTry       = new TST <int>();
            myStopWatch.Start();
            for (int i = 0; i < 81; i++)
            {
                myTry.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("81 Insertions: " + myStopWatch.Elapsed);
            // 100 adds

            myStopWatch = new Stopwatch();
            data        = new myData();
            myTry       = new TST <int>();
            myStopWatch.Start();
            for (int i = 0; i < 243; i++)
            {
                myTry.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("243 Insertions: " + myStopWatch.Elapsed);
            // 10 adds
            myStopWatch = new Stopwatch();
            data        = new myData();
            myTry       = new TST <int>();
            myStopWatch.Start();
            for (int i = 0; i < 729; i++)
            {
                myTry.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("729 Insertions: " + myStopWatch.Elapsed);
            // Testing Dictionary search tree Insertions
            // 977 adds
            Console.WriteLine(" Testing the Dictionary");
            myStopWatch = new Stopwatch();
            data        = new myData();
            Dictionary <string, int> myDictionary = new Dictionary <string, int>();

            myStopWatch.Start();
            for (int i = 0; i < 3; i++)
            {
                myDictionary.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("3 Insertions: " + myStopWatch.Elapsed);


            myStopWatch  = new Stopwatch();
            data         = new myData();
            myDictionary = new Dictionary <string, int>();
            myStopWatch.Start();
            for (int i = 0; i < 27; i++)
            {
                myDictionary.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("27 Insertions: " + myStopWatch.Elapsed);

            myStopWatch  = new Stopwatch();
            data         = new myData();
            myDictionary = new Dictionary <string, int>();
            myStopWatch.Start();
            for (int i = 0; i < 81; i++)
            {
                myDictionary.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("81 Insertions: " + myStopWatch.Elapsed);

            myStopWatch  = new Stopwatch();
            data         = new myData();
            myDictionary = new Dictionary <string, int>();
            myStopWatch.Start();
            for (int i = 0; i < 243; i++)
            {
                myDictionary.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("243 Insertions: " + myStopWatch.Elapsed);

            myStopWatch  = new Stopwatch();
            data         = new myData();
            myDictionary = new Dictionary <string, int>();
            myStopWatch.Start();
            for (int i = 0; i < 729; i++)
            {
                myDictionary.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("729 Insertions: " + myStopWatch.Elapsed);

            // TESTING // Contains// Partial Match // Autocomplete

            Console.WriteLine(" Ternary Search Tree Add ");

            data  = new myData();
            myTry = new TST <int>();
            myStopWatch.Start();
            for (int i = 0; i < 1000; i++)
            {
                myTry.Add(data.words[i], i);
            }

            Boolean       value = myTry.Contains("chaos");
            List <string> list  = myTry.Autocomplete("ch");
            List <string> list2 = myTry.PartialMatch("ch***");
            List <string> list3 = myTry.PartialMatch("***b**");

            Console.WriteLine("List: AutoComplete ch ");
            foreach (string element in list)
            {
                Console.Write(element + " ");
            }
            Console.WriteLine();
            Console.WriteLine("List2: PartialMatch ch*** ");
            foreach (string element in list2)
            {
                Console.Write(element + " ");
            }
            Console.WriteLine();
            Console.WriteLine("List3: PartialMatch ***b** ");
            foreach (string element in list3)
            {
                Console.Write(element + " ");
            }


            Console.ReadLine();
        }