void Test_exhaustively() { MyHashTableSeperateChaining <string, string> table = new MyHashTableSeperateChaining <string, string>(); table.Insert("a", "1"); table.Insert("b", "2"); table.Insert("c", "3"); Assert.Equal(3, table.Size); Assert.False(table.IsEmpty()); table.Remove("a"); Assert.False(table.ContainsKey("a")); Assert.True(table.ContainsKey("b")); Assert.True(table.ContainsKey("c")); Assert.Equal(2, table.Size); var keys = table.Keys(); var values = table.Values(); Assert.Equal(2, keys.Count); Assert.Equal(2, values.Count); table.Clear(); Assert.True(table.IsEmpty()); Assert.False(table.ContainsKey("a")); Assert.False(table.ContainsKey("b")); Assert.False(table.ContainsKey("c")); var keys2 = table.Keys(); var values2 = table.Values(); Assert.Empty(keys2); Assert.Empty(values2); table.Insert("h", "100"); table.Insert("z", "255"); table.Insert("z", "300"); Assert.Equal(2, table.Size); Assert.False(table.IsEmpty()); Assert.Equal("300", table.GetValue("z")); Assert.False(table.ContainsKey("a")); Assert.False(table.ContainsKey("b")); Assert.False(table.ContainsKey("c")); Assert.True(table.ContainsKey("h")); Assert.True(table.ContainsKey("z")); var keys3 = table.Keys(); var values3 = table.Values(); Assert.Equal(2, keys3.Count); Assert.Equal(2, values3.Count); table.Remove("z"); Assert.Equal(1, table.Size); Assert.False(table.IsEmpty()); Assert.True(table.ContainsKey("h")); Assert.False(table.ContainsKey("z")); table.Remove("h"); Assert.True(table.IsEmpty()); Assert.False(table.ContainsKey("h")); Assert.False(table.ContainsKey("z")); var keys4 = table.Keys(); var values4 = table.Values(); Assert.Empty(keys4); Assert.Empty(values4); Assert.Throws <ArgumentException>(() => table.Remove("z")); }
void Test_remove() { MyHashTableSeperateChaining <string, int> table = new MyHashTableSeperateChaining <string, int>(); table.Insert("a", 1); table.Insert("b", 2); table.Insert("c", 3); table.Insert("d", 4); Assert.Equal(2, table.Remove("b")); Assert.True(table.ContainsKey("a")); Assert.False(table.ContainsKey("b")); Assert.True(table.ContainsKey("c")); Assert.True(table.ContainsKey("d")); Assert.Equal(3, table.Remove("c")); Assert.True(table.ContainsKey("a")); Assert.False(table.ContainsKey("b")); Assert.False(table.ContainsKey("c")); Assert.True(table.ContainsKey("d")); Assert.Equal(1, table.Remove("a")); Assert.False(table.ContainsKey("a")); Assert.False(table.ContainsKey("b")); Assert.False(table.ContainsKey("c")); Assert.True(table.ContainsKey("d")); Assert.Equal(4, table.Remove("d")); Assert.False(table.ContainsKey("a")); Assert.False(table.ContainsKey("b")); Assert.False(table.ContainsKey("c")); Assert.False(table.ContainsKey("d")); Assert.True(table.IsEmpty()); }