public void TestAddRemove() { dict0.Add(1, 5); dict0.Add(5, 1); dict0.Add(2, 2); Assert.AreEqual(3, dict0.Count); Assert.AreEqual(5, dict0[1]); Assert.AreEqual(1, dict0[5]); Assert.AreEqual(2, dict0[2]); dict0.Remove(1); Assert.AreEqual(2, dict0.Count); Assert.IsFalse(dict0.ContainsKey(1)); dict0.Add(2, 3); Assert.AreEqual(2, dict0.Count); Assert.AreEqual(3, dict0[2]); dict0.Add(3, 0); Assert.AreEqual(3, dict0.Count); Assert.AreEqual(0, dict0[3]); dict0.Add(1, 4); Assert.AreEqual(4, dict0.Count); Assert.AreEqual(4, dict0[1]); dict0.Add(1, 8); Assert.AreEqual(4, dict0.Count); Assert.AreEqual(8, dict0[1]); dict0.Remove(1); Assert.AreEqual(3, dict0.Count); dict0.Add(1, 2); Assert.AreEqual(4, dict0.Count); Assert.AreEqual(2, dict0[1]); Assert.AreEqual(3, dict0[2]); Assert.AreEqual(0, dict0[3]); Assert.AreEqual(1, dict0[5]); }
public void TestEnumerationAfterRemoval() { dict1.Remove(alice); int i = 0; bool[] r = new bool[2]; foreach (KeyValuePair <string, int> e in dict1) { if (bob.Equals(e.Key)) { Assert.AreEqual(2, e.Value); r[0] = true; } else if (cedric.Equals(e.Key)) { Assert.AreEqual(3, e.Value); r[1] = true; } ++i; } Assert.AreEqual(2, i); foreach (bool rr in r) { Assert.IsTrue(rr); } }