コード例 #1
0
        private void test2()
        {
            Table <int, String> ht = TableFactory.Make <int, String>(4, 0.5);

            ht.Put(1, "Eat");
            ht.Put(2, "Play");
            ht.Put(3, "Sleep");
            Console.WriteLine("This test case is to check if the developed data structure supports generics");
            Console.WriteLine("and if diferent value is passed with same key, value should be overwrritten");
            try
            {
                foreach (int first in ht)
                {
                    Console.WriteLine(first + " -> " + ht.Get(first));
                }
                Console.WriteLine("=========================");

                ht.Put(2, "Study");
                ht.Put(4, "Work");
                foreach (int first in ht)
                {
                    Console.WriteLine(first + " -> " + ht.Get(first));
                }
                Console.WriteLine("=========================");
            }
            catch (NonExistentKey <String> nek)
            {
                Console.WriteLine(nek.Message);
                Console.WriteLine(nek.StackTrace);
            }
        }
コード例 #2
0
        private void test1()
        {
            Table <String, String> ht = TableFactory.Make <String, String>(4, 0.5);

            ht.Put("Joe", "Doe");
            ht.Put("Jane", "Brain");
            ht.Put("Chris", "Swiss");
            try
            {
                foreach (String first in ht)
                {
                    Console.WriteLine(first + " -> " + ht.Get(first));
                }
                Console.WriteLine("=========================");

                ht.Put("Wavy", "Gravy");
                ht.Put("Chris", "Bliss");
                foreach (String first in ht)
                {
                    Console.WriteLine(first + " -> " + ht.Get(first));
                }
                Console.WriteLine("=========================");

                Console.Write("Jane -> ");
                Console.WriteLine(ht.Get("Jane"));
                Console.Write("John -> ");
                Console.WriteLine(ht.Get("John"));
            }
            catch (NonExistentKey <String> nek)
            {
                Console.WriteLine(nek.Message);
                Console.WriteLine(nek.StackTrace);
            }
        }
コード例 #3
0
        /// <summary>
        /// The below test case was taken from Ashwani Kumar(ak8647)
        /// </summary>
        private void test7()
        {
            Console.WriteLine("This test case checkes performance of my hashtable. " +
                              "It also feeds hashtable with size having negative values and loadThreshold ");
            DateTime start = DateTime.Now;

            Console.WriteLine("Testing hashTable with threshold of 0.633 and start capacity" +
                              " of 10");
            Table <int, int> myHashTable1 = TableFactory.Make <int, int>(10, 0.633);

            Console.WriteLine("Inserting 10 million entries into hashtable");
            for (int i = 0; i < 10000000; i++)
            {
                myHashTable1.Put(i, i);
            }
            Console.WriteLine("Enumerating throught each entries in HashTable");
            foreach (int x in myHashTable1)
            {
                myHashTable1.Get(x);
            }
            DateTime end = DateTime.Now;

            Console.WriteLine("Time taken for execution: " + (end - start) + "\n");



            Console.WriteLine("Test case 3");
            start = DateTime.Now;

            Console.WriteLine("Testing hashTable with threshold of -10 and start capacity " +
                              " of -0.43333");

            myHashTable1 = TableFactory.Make <int, int>(-10, -0.43333);
            Console.WriteLine("Inserting 10 million entries into hashtable");
            for (int i = 0; i < 10000000; i++)
            {
                myHashTable1.Put(i, i);
            }

            Console.WriteLine("Enumerating throught each entries in HashTable");
            foreach (int x in myHashTable1)
            {
                myHashTable1.Get(x);
            }
            end = DateTime.Now;
            Console.WriteLine("Time taken for execution: " + (end - start) + "\n");

            Console.WriteLine("TestCase successfully completed.\n");
        }
コード例 #4
0
        private void test6()
        {
            Table <String, String> ht = TableFactory.Make <String, String>(10, -2);

            Console.WriteLine("In case of Incorrect threshold, value it asks user to enter value between 0 and 1");
            ht.Put("Test", "Incorrect threshold value");
            try
            {
                foreach (String first in ht)
                {
                    Console.WriteLine(first + " -> " + ht.Get(first));
                }
                Console.WriteLine("=========================");
            }
            catch (NonExistentKey <String> nek)
            {
                Console.WriteLine(nek.Message);
                Console.WriteLine(nek.StackTrace);
            }
        }
コード例 #5
0
        /// <summary>
        /// This test case was shared with devavrat kalam(dk2792)
        /// </summary>
        private void test5()
        {
            Table <String, String> ht = TableFactory.Make <String, String>(-1, 0.5);

            Console.WriteLine("If the provided loadfactor is negative, ask user to enter positive value");
            ht.Put("Any", "Negative loadfactor");
            try
            {
                foreach (String first in ht)
                {
                    Console.WriteLine(first + " -> " + ht.Get(first));
                }
                Console.WriteLine("=========================");
            }
            catch (NonExistentKey <String> nek)
            {
                Console.WriteLine(nek.Message);
                Console.WriteLine(nek.StackTrace);
            }
        }
コード例 #6
0
ファイル: solution.cs プロジェクト: tel5027/HashTable
        public static void Main(string[] args)
        {
            ///Three unit tests written by me
            TestTable.test();

            ///Provided tests. Tests Put and Get methods, as well as the
            ///NonExistantKey exception
            Table <String, String> ht = TableFactory.Make <String, String>(4, 0.5);

            ht.Put("Joe", "Doe");
            ht.Put("Jane", "Brain");
            ht.Put("Chris", "Swiss");
            try
            {
                foreach (String first in ht)
                {
                    Console.WriteLine(first + " -> " + ht.Get(first));
                }
                Console.WriteLine("=========================");

                ht.Put("Wavy", "Gravy");
                ht.Put("Chris", "Bliss");
                foreach (String first in ht)
                {
                    Console.WriteLine(first + " -> " + ht.Get(first));
                }
                Console.WriteLine("=========================");

                Console.Write("Jane -> ");
                Console.WriteLine(ht.Get("Jane"));
                Console.Write("John -> ");
                Console.WriteLine(ht.Get("John"));
            }
            catch (NonExistentKey <String> nek)
            {
                Console.WriteLine(nek.Message);
                Console.WriteLine(nek.StackTrace);
            }

            Console.ReadLine();
        }
コード例 #7
0
        private void test3()
        {
            Table <object, String> ht = TableFactory.Make <object, String>(1, 0.5);

            Console.WriteLine("This is to make sure that null value cannot be inserted as Key");
            Console.WriteLine("Trying to Insert null as key");
            ht.Put(null, "Null check");
            try
            {
                foreach (String first in ht)
                {
                    Console.WriteLine(first + " -> " + ht.Get(first));
                }
                Console.WriteLine("=========================");
            }
            catch (NonExistentKey <String> nek)
            {
                Console.WriteLine(nek.Message);
                Console.WriteLine(nek.StackTrace);
            }
        }
コード例 #8
0
        /// <summary>
        /// This test case has been shared with Ashwani Kumar(ak8647) and Devavrat Kalam(dk2792)
        /// </summary>
        private void test4()
        {
            Table <String, String> ht = TableFactory.Make <String, String>(6, 0.5);

            Console.WriteLine("This is to make sure that rehashing works properly");
            ht.Put("Betty", "boop");
            ht.Put("Buggs", "Bunny");
            ht.Put("Charlie", "Brown");
            ht.Put("Duffy", "Duck");
            ht.Put("Dennis", "The Mennace");
            ht.Put("Donald", "Duck");
            ht.Put("Garfield", "MickeyMouse");
            ht.Put("Olive", "Oyl");
            ht.Put("Popeye", "Tailorman");
            ht.Put("Powerpuff", "Girls");
            ht.Put("Road", "Runner");
            ht.Put("Scooby", "Doo");
            ht.Put("Snoopy", "Dog");
            ht.Put("Ninja", "Turtle");
            ht.Put("The", "Simpsons");
            ht.Put("Tom", "Jerry");
            ht.Put("Yogi", "Bear");

            try
            {
                foreach (String first in ht)
                {
                    Console.WriteLine(first + " -> " + ht.Get(first));
                }
                Console.WriteLine("=========================");
            }
            catch (NonExistentKey <String> nek)
            {
                Console.WriteLine(nek.Message);
                Console.WriteLine(nek.StackTrace);
            }
        }
コード例 #9
0
ファイル: solution.cs プロジェクト: tel5027/HashTable
        ///<summary>
        /// Unit Test class for the LinkedHashTable implementation
        ///</summary>

        public static void test()
        {
            try
            {
                Console.WriteLine("=========================");
                Console.WriteLine("=========TEST 1==========");
                Console.WriteLine("=========================");

                ///Unique keys test. Tom, 1 and Sam, 12 should have their values
                ///updated to 9 and 21 respectfully.
                Table <String, int> t1 = TableFactory.Make <String, int>(10, 0.5);
                t1.Put("Tom", 1);
                t1.Put("Casey", 2);
                t1.Put("Adam", 3);
                t1.Put("James", 4);
                t1.Put("Erik", 5);
                t1.Put("Dan", 6);
                t1.Put("Jeremy", 7);
                t1.Put("Bill", 8);
                t1.Put("Tom", 9);
                t1.Put("Kenny", 10);
                t1.Put("David", 11);
                t1.Put("Sam", 12);
                t1.Put("Robert", 13);
                t1.Put("Lisa", 14);
                t1.Put("Margaret", 15);
                t1.Put("Della", 16);
                t1.Put("Marc", 17);
                t1.Put("Tiffany", 18);
                t1.Put("Kori", 19);
                t1.Put("Jack", 20);
                t1.Put("Sam", 21);

                foreach (String s in t1)
                {
                    Console.WriteLine(s + " -> " + t1.Get(s));
                }
            }
            catch (NonExistentKey <String> nek)
            {
                Console.WriteLine(nek.Message);
                Console.WriteLine(nek.StackTrace);
            }

            Console.WriteLine(" ");

            try
            {
                Console.WriteLine("=========================");
                Console.WriteLine("=========TEST 2==========");
                Console.WriteLine("=========================");

                //Large test, Tests behavior for a large sized HashTree.
                //Start with initial capacity of 100, Continue to rehash until
                //2000 elements are contained in the HashTree
                Table <Guid, String> t1 = TableFactory.Make <Guid, String>(100, 0.5);
                for (int i = 0; i < 2000; i++)
                {
                    Guid g = Guid.NewGuid();
                    t1.Put(g, g.ToString());
                }

                foreach (Guid g in t1)
                {
                    Console.WriteLine(g + " -> " + t1.Get(g));
                }
            }
            catch (NonExistentKey <String> nek)
            {
                Console.WriteLine(nek.Message);
                Console.WriteLine(nek.StackTrace);
            }

            Console.WriteLine(" ");

            try
            {
                Console.WriteLine("=========================");
                Console.WriteLine("=========TEST 3==========");
                Console.WriteLine("=========================");

                ///Contains test. Tests the contains function to see if the table contains
                ///the given key
                Table <String, bool> t1 = TableFactory.Make <String, bool>(20, 0.5);
                t1.Put("I'm a boy", true);
                t1.Put("Candy is healthy", false);
                t1.Put("This class is awesome", true);
                t1.Put("I'm a brown noser", true);
                t1.Put("F grade is passing", false);
                t1.Put("This class is difficult", false);
                t1.Put("I enjoyed this project", true);
                t1.Put("I love RIT Hockey", true);
                t1.Put("Writing unit tests is hard", true);
                t1.Put("I can do it!", true);
                t1.Put("I'm taking 7 classes this semester", false);
                t1.Put("ReHash() works properly", true);
                t1.Put("Prof. Brown likes video games", true);
                t1.Put("Latest C# Version is 4.5", false);

                if (t1.Contains("I can do it!"))
                {
                    Console.WriteLine("Key: I can do it! is in the table");
                }
                else
                {
                    Console.WriteLine("Key: I can do it! is not in the table");
                }

                if (t1.Contains("Books are expensive!"))
                {
                    Console.WriteLine("Key: Books are expensive! is in the table");
                }
                else
                {
                    Console.WriteLine("Key: Books are expensive! is not in the table");
                }

                if (t1.Contains("Writing unit tests is hard"))
                {
                    Console.WriteLine("Key: Writing unit tests is hard is in the table");
                }
                else
                {
                    Console.WriteLine("Key: Writing unit tests is hard is not in the table");
                }

                if (t1.Contains("I'm a scary dude!"))
                {
                    Console.WriteLine("Key: I'm a scary dude! is in the table");
                }
                else
                {
                    Console.WriteLine("Key: I'm a scary dude! is not in the table");
                }

                Console.WriteLine("=========================");

                foreach (String s in t1)
                {
                    Console.WriteLine(s + " -> " + t1.Get(s));
                }

                Console.WriteLine("=========================");
            }
            catch (NonExistentKey <String> nek)
            {
                Console.WriteLine(nek.Message);
                Console.WriteLine(nek.StackTrace);
            }

            Console.WriteLine(" ");
            Console.WriteLine("=========================");
            Console.WriteLine("=========TEST 4==========");
            Console.WriteLine("=========================");
        }