Exemple #1
0
        public void TestHashTableCollisionValue()
        {
            Hashtable testHashTable7 = new Hashtable();

            testHashTable7.AddToHashTable("cat", "dog");
            testHashTable7.AddToHashTable("rat", "newValue");
            string testAnswer4 = testHashTable7.GetFromHashTable("rat");

            Assert.Equal("newValue", testAnswer4);
        }
Exemple #2
0
        public void TestHashTableCollision2()
        {
            Hashtable testHashTable6 = new Hashtable();

            testHashTable6.AddToHashTable("cat", "dog");
            testHashTable6.AddToHashTable("rat", "newValue");
            string testAnswer4 = testHashTable6.GetFromHashTable("cat"); //checking orig is still there too

            Assert.Equal("dog", testAnswer4);
        }
Exemple #3
0
        public void TestHashTableAdd2()
        {
            Hashtable testHashTable2 = new Hashtable();

            testHashTable2.AddToHashTable("cat", "dog");
            Assert.Equal("dog", testHashTable2.HashTableArray[312].Head.Value);
        }
Exemple #4
0
        public void TestHashTableAdd1()
        {
            Hashtable testHashTable1 = new Hashtable();

            testHashTable1.AddToHashTable("cat", "dog");
            Assert.Equal("cat", testHashTable1.HashTableArray[312].Head.Key);
        }
Exemple #5
0
        public void TestHashContainsFail()
        {
            Hashtable testHashTable11 = new Hashtable();

            testHashTable11.AddToHashTable("cat", "dog");
            bool htAnswer11 = testHashTable11.HashTableContains("apple");

            Assert.False(htAnswer11);
        }
Exemple #6
0
        public void TestHashContainsPass()
        {
            Hashtable testHashTable10 = new Hashtable();

            testHashTable10.AddToHashTable("cat", "dog");
            bool htAnswer10 = testHashTable10.HashTableContains("cat");

            Assert.True(htAnswer10);
        }
Exemple #7
0
        public void TestHashTableGetForNull()
        {
            Hashtable testHashTable4 = new Hashtable();

            testHashTable4.AddToHashTable("cat", "dog");
            string testAnswer2 = testHashTable4.GetFromHashTable("bob");

            Assert.Null(testAnswer2);
        }
Exemple #8
0
        public void TestHashTableGet()
        {
            Hashtable testHashTable3 = new Hashtable();

            testHashTable3.AddToHashTable("cat", "dog");
            string testAnswer1 = testHashTable3.GetFromHashTable("cat");

            Assert.Equal("dog", testAnswer1);
        }
        /// <summary>
        /// Compares two trees and itentify where they shares the same values
        /// </summary>
        /// <param name="root1">one tree</param>
        /// <param name="root2">second tree</param>
        /// <returns>a list of the values the two trees share</returns>
        public static List <int> TreeIntersection(BinaryTree root1, BinaryTree root2)
        {
            QueueForTrees algoQueue     = new QueueForTrees();
            Hashtable     algoHashtable = new Hashtable();
            List <int>    returnAnswer  = new List <int>();
            string        valForHT      = "";
            bool          comparison;

            if (root1 == null || root2 == null)
            {
                return(returnAnswer);
            }

            TreeNode algoQT1Node = root1.root;

            algoQueue.Enqueue(algoQT1Node);
            while (algoQueue.Front != null)
            {
                Node temp = algoQueue.Dequeue();
                algoHashtable.AddToHashTable(temp.Value.Value.ToString(), temp.Value.Value.ToString());
                if (temp.Value.LeftChild != null)
                {
                    algoQueue.Enqueue(temp.Value.LeftChild);
                }
                if (temp.Value.RightChild != null)
                {
                    algoQueue.Enqueue(temp.Value.RightChild);
                }
            }
            //can re-use the queue because it wouldn't exit above while loop until it was empty
            TreeNode algoQT2Node = root2.root;

            algoQueue.Enqueue(algoQT2Node);
            while (algoQueue.Front != null)
            {
                Node temp = algoQueue.Dequeue();
                valForHT   = temp.Value.Value.ToString();
                comparison = algoHashtable.HashTableContains(valForHT);
                if (comparison == true)
                {
                    returnAnswer.Add(temp.Value.Value);
                }
                if (temp.Value.LeftChild != null)
                {
                    algoQueue.Enqueue(temp.Value.LeftChild);
                }
                if (temp.Value.RightChild != null)
                {
                    algoQueue.Enqueue(temp.Value.RightChild);
                }
            }
            return(returnAnswer);
        }
        /// <summary>
        /// determines if a string has unique characters in it, excluding spaces and isn't case sensative.
        /// </summary>
        /// <param name="input">the string to evaluate</param>
        /// <returns>true if all unique, else false</returns>
        public static bool UniqueChara(string input)
        {
            Hashtable ht           = new Hashtable();
            string    temp         = "";
            string    inputToUpper = input.ToUpper();

            if (input.Length == 0)
            {
                return(false); //technically no chara is and isn't uniqueu chara, i chose false
            }
            for (int i = 0; i < input.Length; i++)
            {
                temp = inputToUpper[i].ToString();
                if (ht.HashTableContains(temp) == true)
                {
                    return(false); //means duplicate
                }
                else
                {
                    ht.AddToHashTable(temp, temp);
                }
            }
            return(true); //means it got through string and it didn't exit due to a duplicate
        }