コード例 #1
0
ファイル: Tester.cs プロジェクト: Elinos/TelerikAcademy
        public static void Main()
        {
            var myhashtable = new MyHashTable<int, string>();

            myhashtable.Add(3, "ar");

            myhashtable[2] = "asd";

            var indexCheck = myhashtable[2];

            Console.WriteLine("toString:");
            Console.WriteLine(myhashtable);

            Console.WriteLine("indexer:");
            Console.WriteLine(myhashtable[2]);
            Console.WriteLine(indexCheck);

            Console.WriteLine("keys:");
            var keysChecker = myhashtable.Keys;

            foreach (var key in keysChecker)
            {
                Console.WriteLine(key);
            }

            Console.WriteLine("count:");
            Console.WriteLine(myhashtable.Count);
            Console.WriteLine("remove:");
            myhashtable.Remove(4);

            Console.WriteLine(myhashtable[2]);

            myhashtable.Remove(2);

            Console.WriteLine(myhashtable[2]);
            Console.WriteLine("count:");
            Console.WriteLine(myhashtable.Count);

            string res;
            var findChecker = myhashtable.Find(3, out res);
            Console.WriteLine("Find value by key 3:");
            Console.WriteLine(res);
            Console.WriteLine(findChecker);

            Console.WriteLine(myhashtable);
            Console.WriteLine("clear");
            myhashtable.Clear();
            Console.WriteLine(myhashtable);
            Console.WriteLine("----");
            Console.WriteLine("resize");

            for (int i = 0; i < 100; i++)
            {
                myhashtable.Add(i, i.ToString());
            }

            Console.WriteLine(myhashtable);
        }
コード例 #2
0
        public void TestClear()
        {
            var hashTable = new MyHashTable<string, int>
            {
                { "five", 5 },
                { "six", 6 }
            };

            hashTable.Clear();

            Assert.AreEqual(0, hashTable.Count);
        }
コード例 #3
0
        public void TestClear()
        {
            MyHashTable <string, int> hashTable = new MyHashTable <string, int>();

            hashTable.Add("asd", 10);
            hashTable.Add("qwe", 11);
            hashTable.Add("rty", 12);
            hashTable.Add("fgh", 13);

            hashTable.Clear();

            Assert.AreEqual(0, hashTable.Count);
            Assert.AreEqual(16, hashTable.Capacity);
        }
コード例 #4
0
        public void Should_Check_Clear()
        {
            //arrange
            var key   = "key";
            var value = "value";
            var map   = new MyHashTable <string, string>();

            map.Add(key, value);

            //act
            map.Clear();
            var keyResult   = map.ContainsKey(key);
            var valueResult = map.ContainsValue(value);
            var count       = map.Count;

            //assert
            keyResult.ShouldBeEquivalentTo(false);
            valueResult.ShouldBeEquivalentTo(false);
            count.ShouldBeEquivalentTo(0);
        }
コード例 #5
0
        public static void Main()
        {
            var table = new MyHashTable<string, string>();
            table.Add("first", "Pesho");
            table.Add("second", "Gosho");
            table.Add("third", "Tosho");
            table.Add("fourth", "Ivan");
            Console.WriteLine(table.Count);

            foreach (var pair in table)
            {
                Console.WriteLine("{0} -> {1}", pair.Key, pair.Value);
            }

            string first;
            table.Find("first", out first);
            Console.WriteLine(first);

            table.Remove("second");
            Console.WriteLine(table.Count);
            foreach (var pair in table)
            {
                Console.WriteLine("{0} -> {1}", pair.Key, pair.Value);
            }

            Console.WriteLine(table["fourth"]);

            string[] keys = table.Keys;
            foreach (var key in keys)
            {
                Console.WriteLine(key);

            }

            table.Clear();
            Console.WriteLine(table.Count);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: PrivateSkittles/2420
    static void Main()
    {
        MyHashTable <string, string> hashtable = new MyHashTable <string, string>();


        //Add functions
        //Contains and ContainsKey functions used for asserting
        hashtable.Add("Mark", "Football player");
        hashtable.Add(new KeyValuePair <string, string>("Jerry", "Engineer"));
        hashtable.Add("Tina", "Ballerina");
        hashtable.Add(new KeyValuePair <string, string>("Susan", "Architect"));

        Debug.Assert(hashtable.Count == 4);
        Debug.Assert(hashtable.Contains(new KeyValuePair <string, string>("Jerry", "Engineer")) == true);
        Debug.Assert(hashtable.ContainsKey("Tina") == true);

        //Prints hashtable
        Console.WriteLine("Table: ");
        foreach (KeyValuePair <string, string> pair in hashtable)
        {
            Console.WriteLine(pair.Key + " - " + pair.Value);
        }

        Console.WriteLine();
        Console.WriteLine("Keys only: ");
        foreach (string key in hashtable.Keys)
        {
            Console.WriteLine(key);
        }

        Console.WriteLine();
        Console.WriteLine("Value only: ");
        foreach (string value in hashtable.Values)
        {
            Console.WriteLine(value);
        }


        //Remove functions
        hashtable.Remove("Mark");
        hashtable.Remove(new KeyValuePair <string, string> ("Tina", "Ballerina"));

        Debug.Assert(hashtable.Count == 2);
        Debug.Assert(hashtable.ContainsKey("Tina") == false);
        Debug.Assert(hashtable.Contains(new KeyValuePair <string, string>("Mark", "Football player")) == false);


        Console.WriteLine();
        Console.WriteLine("Table with Mark and Tina using both Remove methods: ");
        foreach (KeyValuePair <string, string> pair in hashtable)
        {
            Console.WriteLine(pair.Key + " - " + pair.Value);
        }


        //Try Get Value function
        Console.WriteLine();
        string gotValue = "";

        if (hashtable.TryGetValue("Jerry", out gotValue))
        {
            Console.WriteLine("Value out of key 'Jerry' using TryGetValue: ");
            Console.WriteLine(gotValue);
        }

        Debug.Assert(gotValue == "Engineer");


        //Clear function
        Console.WriteLine();
        Console.WriteLine("Table cleared: ");
        hashtable.Clear();
        foreach (KeyValuePair <string, string> pair in hashtable)
        {
            Console.WriteLine(pair.Key + " - " + pair.Value);
        }
        Debug.Assert(hashtable.Count == 0);

        Console.WriteLine();
    }