Example #1
0
 public void UpdateValue_Arguments()
 {
     IDictionary<string, int> s = null;
     Assert.Throws<ArgumentNullException>(() => s.UpdateValue ("key", v => v));
     s = new Dictionary<string, int> ();
     Assert.Throws<ArgumentNullException>(() => s.UpdateValue ("key", null));
 }
Example #2
0
 public void UpdateValue()
 {
     #region UpdateValue
     var words = new[]{
         "Count",
         "the",
         "the",
         "repeated",
         "words",
     };
     var wordCounts = new Dictionary<string, int> ();
     foreach (var word in words) {
         int c;
         wordCounts.TryGetValue (word, out c);
         Assert.AreEqual (c + 1, wordCounts.UpdateValue (word, v => v + 1));
     }
     Assert.AreEqual (4, wordCounts.Count);
     Assert.AreEqual (1, wordCounts ["Count"]);
     Assert.AreEqual (2, wordCounts ["the"]);
     Assert.AreEqual (1, wordCounts ["repeated"]);
     Assert.AreEqual (1, wordCounts ["words"]);
     #endregion
 }