public void AddIfNotContainsKey()
        {
            // Type
            var @this = new Dictionary<string, string>();

            // Examples
            @this.AddIfNotContainsKey("Fizz", "FizzBuzz"); // Add "FizzBuzz";
            @this.AddIfNotContainsKey("Fizz", () => "Buzz"); // Add Nothing;

            // Unit Test
            Assert.AreEqual("FizzBuzz", @this["Fizz"]);
        }
        public void AddIfNotContainsKeyTestCase2()
        {
            var key = RandomValueEx.GetRandomString();
            var dic = new Dictionary<String, String>();

            var result = dic.AddIfNotContainsKey( key, () => RandomValueEx.GetRandomString() );
            Assert.IsTrue( result );
            Assert.AreEqual( 1, dic.Count );

            result = dic.AddIfNotContainsKey( key, () => RandomValueEx.GetRandomString() );
            Assert.IsFalse( false );
            Assert.AreEqual( 1, dic.Count );
        }
Example #3
0
        static int Fravik(int[] a)
        {
            Dictionary<int, int> t = new Dictionary<int, int>();
            foreach (int n in a)
            {
                t.AddIfNotContainsKey(n, 1, 1);
            }

            return (from n in t
                   where n.Value != 1
                   select n).ToArray()[0].Key;
        }