Example #1
0
 static void TimedGet(int key)
 {
     _sw.Restart();
     _map.Get(key);
     _sw.Stop();
     Console.WriteLine(String.Format("Time to get {0} from {1} items: {2}", key, _map.Count, _sw.Elapsed));
 }
Example #2
0
        public void Get_ForNotExistingKey_ThrowsException()
        {
            //arrange
            var cht = new ChainingHashTable <string, int>(5);
            //arrange + act
            Action act = () => { cht.Get("null"); };

            //assert
            act.Should().Throw <System.Collections.Generic.KeyNotFoundException>();
        }
Example #3
0
        public void Get_ForNull_ThrowsException()
        {
            //arrange
            var cht = new ChainingHashTable <string, int>(5);
            //arrange + act
            Action act = () => { cht.Get(null); };

            //assert
            act.Should().Throw <ArgumentException>();
        }
Example #4
0
        public static void HashTableTest()
        {
            ChainingHashTable ht = new ChainingHashTable();

            //Set()
            ht.Set(123456, 100);
            ht.Set(654321, 200);
            ht.Set("ABC", 300);
            ht.Set("CBA", 400);

            //Get()
            Console.WriteLine("Get(CDE) = {0}", ht.Get("123456"));
            Console.WriteLine("Get(ABC) = {0}\n\n", ht.Get("ABC"));

            //Indexer set
            ht[1]   = 500;
            ht[0.5] = 600;
            ht['A'] = 700;

            //Indexer get
            Console.WriteLine("ht[1] = {0}", ht[1]);
            Console.WriteLine("ht[0.5] = {0}", ht[0.5]);
        }
Example #5
0
        public void Get_ForExistingKey_ReturnsTheValue()
        {
            //arrange
            const string key   = "1";
            const int    value = 1;
            var          cht   = new ChainingHashTable <string, int>(5);

            cht.Add(key, value);
            //act
            var result = cht.Get(key);

            //assert
            result.Should().Be(value);
        }