public void TestForCollisionOfHashKeys2() { MyHashtable test3 = new MyHashtable(); test3.Add("Cat", 1); test3.Add("Cat", 2); test3.Add("Doe", 3); test3.Add("Doe", 4); List <int> catValueList = test3.Find("Cat"); List <int> doeValueList = test3.Find("Doe"); List <int> expected = new List <int> { 1, 2, 3, 4 }; Assert.Equal(expected, catValueList); Assert.Equal(expected, doeValueList); }
public void MyHashtable_Add1_Find1_succeeds() { var hashtbl = new MyHashtable <string, Person>(10); var p = new Person() { Name = "Louise", City = "Dublin" }; hashtbl.Add(p.Name, p); var result = hashtbl.Find(p.Name); Assert.AreEqual(result.Name, p.Name); Assert.AreEqual(result.City, p.City); }
public void TestForAddingValuesToHash() { MyHashtable test1 = new MyHashtable(); test1.Add("test", 1); test1.Add("test", 2); test1.Add("test", 3); test1.Add("test", 4); List <int> result = test1.Find("test"); List <int> expect = new List <int> { 1, 2, 3, 4 }; Assert.Equal(expect, result); }
static void Main(string[] args) { MyHashtable ht = new MyHashtable(); ht.Add("one", 5); Console.WriteLine("Added => Key: one, value: 5 "); ht.Add("one", 15); Console.WriteLine("Added => Key: one, value: 15 "); ht.Add("two", 10); Console.WriteLine("Added => Key: two, value: 10 "); Console.WriteLine(); List <int> valueList = ht.Find("one"); Console.WriteLine("Key of 'one' contains following values: "); foreach (int val in valueList) { Console.WriteLine(val); } Console.WriteLine(); bool contain = ht.Contains("one"); bool contains = ht.Contains("One"); Console.WriteLine(); Console.WriteLine("Hastable contains a key of 'one': " + contain); Console.WriteLine("Hastable contains a key of 'One': " + contains); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Collision test of 'Cat' and 'Doe' : "); Console.WriteLine(); MyHashtable colsn = new MyHashtable(); colsn.Add("Cat", 50); Console.WriteLine("Added => Key: Cat, value: 50 "); colsn.Add("Doe", 100); Console.WriteLine("Added => Key: Doe, value: 100 "); List <int> catList = colsn.Find("Cat"); List <int> doeList = colsn.Find("Doe"); Console.WriteLine("Key: Cat holds following value(s): "); foreach (int i in catList) { Console.WriteLine(i); } Console.WriteLine(); Console.WriteLine("Key: Doe holds following value(s);"); foreach (int i in doeList) { Console.WriteLine(i); } Console.WriteLine(); bool containCat = colsn.Contains("Cat"); bool containDoe = colsn.Contains("Doe"); Console.WriteLine(); Console.WriteLine("Hastable contains a key of 'Cat': " + containCat); Console.WriteLine("Hastable contains a key of 'Doe': " + containDoe); }