public void Clear() { IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>(); Player p = new Player("78945", "Someone"); lhm[p.Id] = p; lhm.Clear(); Assert.AreEqual(0, lhm.Count); foreach (KeyValuePair<string, Player> pair in lhm) Assert.Fail("Should not be any entries but found Key = " + pair.Key + " and Value = " + pair.Value); }
public void FirstKeyFirstValue() { LinkedHashMap<string, Player> lhm = new LinkedHashMap<string, Player>(); Fill(lhm); Assert.AreEqual(players[0].Id, lhm.FirstKey); Assert.AreEqual(players[0], lhm.FirstValue); // override First Player antWithSameId = new Player("12341", "Another"); lhm[antWithSameId.Id] = antWithSameId; Assert.AreEqual(players[1].Id, lhm.FirstKey); Assert.AreEqual(players[1], lhm.FirstValue); }
public void LastKeyLastValue() { LinkedHashMap<string, Player> lhm = new LinkedHashMap<string, Player>(); Fill(lhm); Assert.AreEqual(players[players.Length - 1].Id, lhm.LastKey); Assert.AreEqual(players[players.Length-1], lhm.LastValue); // override Player antWithSameId = new Player("12341", "Another"); lhm[antWithSameId.Id] = antWithSameId; Assert.AreEqual(antWithSameId.Id, lhm.LastKey); Assert.AreEqual(antWithSameId, lhm.LastValue); }
public void ShowDiff() { IDictionary<string, Player> dict = new Dictionary<string, Player>(); IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>(); Fill(dict); Fill(lhm); // Override the first element Player o = new Player("12341", "Ovirride"); dict[o.Id] = o; lhm[o.Id] = o; Console.Out.WriteLine("Dictionary order:"); foreach (KeyValuePair<string, Player> pair in dict) { Console.Out.WriteLine("Key->{0}", pair.Key); } Console.Out.WriteLine("LinkedHashMap order:"); foreach (KeyValuePair<string, Player> pair in lhm) { Console.Out.WriteLine("Key->{0}", pair.Key); } }
public void GetEnumeratorModifyExceptionFromUpdate() { IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>(); lhm["123"] = new Player("123", "yyyyyyy"); Assert.Throws<InvalidOperationException>(() => { foreach (KeyValuePair<string, Player> pair in lhm) { lhm["123"] = new Player("123", "aaaaaaa"); } }); }