public void KeysAndValues() { var dict = new SmallDictionary <int, string>(); VerifyIntArrays(new int[0], dict.Keys.ToArray()); VerifyStringArrays(new string[0], dict.Values.ToArray()); dict.Add(2, "abc"); VerifyIntArrays(new int[] { 2 }, dict.Keys.ToArray()); VerifyStringArrays(new string[] { "abc" }, dict.Values.ToArray()); // This test is too strict, it enforces a particular order of the results. dict.Add(5, "def"); dict.Add(11, "third"); VerifyIntArrays(new int[] { 2, 5, 11 }, dict.Keys.ToArray()); VerifyStringArrays(new string[] { "abc", "def", "third" }, dict.Values.ToArray()); }
public void Enumerator() { var dict = new SmallDictionary <int, string>(); foreach (var kvp in dict) { Assert.Fail("Should get no iterations looping over empty dictionary"); } dict.Add(2, "abc"); int count = 0; foreach (var kvp in dict) { count++; Assert.AreEqual(2, kvp.Key); Assert.AreEqual("abc", kvp.Value); } Assert.AreEqual(1, count); dict.Add(5, "def"); dict.Add(11, "third"); count = 0; Dictionary <int, string> normalDict = new Dictionary <int, string>(dict); Assert.AreEqual("abc", normalDict[2]); Assert.AreEqual("def", normalDict[5]); Assert.AreEqual("third", normalDict[11]); Assert.AreEqual(3, normalDict.Count); foreach (var kvp in dict) { count++; Assert.IsTrue(normalDict.ContainsKey(kvp.Key)); Assert.AreEqual(normalDict[kvp.Key], kvp.Value); normalDict.Remove(kvp.Key); } Assert.AreEqual(3, count); }
public void GetMissingKeyEmpty() { var dict = new SmallDictionary <int, string>(); var temp = dict[2]; }
public void GetZeroKey() { var dict = new SmallDictionary <int, string>(); var temp = dict[0]; }
public void AddZeroKey() { var dict = new SmallDictionary <int, string>(); dict.Add(0, "abc"); }
public void ItemZeroKey() { var dict = new SmallDictionary <int, string>(); dict[0] = "abc"; }