Пример #1
0
        public void EditableLookupRemove()
        {
            var lookup = new EditableLookup <string, int>();

            lookup.Add("a", 1);
            lookup.Add("a", 2);
            lookup.Add("b", 3);
            lookup.Add("a", 4);
            Assert.IsTrue(lookup.Contains("a"));
            Assert.IsTrue(lookup.Contains("b"));
            Assert.IsTrue(lookup.Contains("b", 3));
            Assert.IsFalse(lookup.Contains("b", 17));

            Assert.IsTrue(lookup.Remove("b"));
            Assert.IsFalse(lookup.Remove("b")); // no longer there
            Assert.AreEqual(1, lookup.Count);
            Assert.AreEqual(3, lookup["a"].Count());
            Assert.IsTrue(lookup.Remove("a", 1));
            Assert.IsFalse(lookup.Remove("a", 1));    // no longer there
            Assert.IsFalse(lookup.Remove("foo", 99)); // never existed

            Assert.AreEqual(6, lookup["a"].Sum());    // 2 + 4
            lookup.Remove("a", 2);
            lookup.Remove("a", 4);
            Assert.IsFalse(lookup.Contains("a"));
            Assert.AreEqual(0, lookup.Count);
        }
Пример #2
0
 public void EditableLookupComparer()
 {
     var lookup = new EditableLookup<string, int>(StringComparer.OrdinalIgnoreCase);
     lookup.Add("a", 1);
     lookup.Add("A", 1);
     Assert.IsTrue(lookup.Contains("a"));
     Assert.IsTrue(lookup.Contains("A"));
     Assert.AreEqual(1, lookup.Count);
     Assert.AreEqual(2, lookup["a"].Count());
 }
Пример #3
0
 public void EditableLookupNullComparer()
 {
     var lookup = new EditableLookup<string, int>(null);
     lookup.Add("a", 1);
     lookup.Add("a", 1);
     Assert.IsTrue(lookup.Contains("a"));
     Assert.IsFalse(lookup.Contains("A"));
     Assert.AreEqual(1, lookup.Count);
     Assert.AreEqual(2, lookup["a"].Count());
 }
Пример #4
0
        public void EditableLookupComparer()
        {
            var lookup = new EditableLookup <string, int>(StringComparer.OrdinalIgnoreCase);

            lookup.Add("a", 1);
            lookup.Add("A", 1);
            Assert.IsTrue(lookup.Contains("a"));
            Assert.IsTrue(lookup.Contains("A"));
            Assert.AreEqual(1, lookup.Count);
            Assert.AreEqual(2, lookup["a"].Count());
        }
Пример #5
0
        public void EditableLookupNullComparer()
        {
            var lookup = new EditableLookup <string, int>(null);

            lookup.Add("a", 1);
            lookup.Add("a", 1);
            Assert.IsTrue(lookup.Contains("a"));
            Assert.IsFalse(lookup.Contains("A"));
            Assert.AreEqual(1, lookup.Count);
            Assert.AreEqual(2, lookup["a"].Count());
        }
Пример #6
0
 public void EditableLookupBasic()
 {
     var lookup = new EditableLookup<string, int>();
     lookup.Add("a", 1);
     lookup.Add("a", 1);
     Assert.IsTrue(lookup.Contains("a"));
     Assert.IsFalse(lookup.Contains("A"));
     Assert.AreEqual(1, lookup.Count);
     Assert.AreEqual(2, lookup["a"].Count());
     Assert.AreEqual(0, lookup["foo"].Count());
 }
Пример #7
0
        public void EditableLookupBasic()
        {
            var lookup = new EditableLookup <string, int>();

            lookup.Add("a", 1);
            lookup.Add("a", 1);
            Assert.IsTrue(lookup.Contains("a"));
            Assert.IsFalse(lookup.Contains("A"));
            Assert.AreEqual(1, lookup.Count);
            Assert.AreEqual(2, lookup["a"].Count());
            Assert.AreEqual(0, lookup["foo"].Count());
        }
Пример #8
0
 public Task <bool> Add(string key, string value)
 {
     if (_data.Contains(key, value))
     {
         return(Task.FromResult(false));
     }
     _data.Add(key, value);
     return(Task.FromResult(true));
 }
Пример #9
0
        public bool Put(string key, string val)
        {
            var alreadyExists = data.Contains(key, val);

            if (!alreadyExists)
            {
                data.Add(key, val);
            }

            return(!alreadyExists);
        }
Пример #10
0
 public void EditableLookupAddRangeEmptyKey()
 {
     var lookup = new EditableLookup<string, int>();
     int[] data = new int[0];
     lookup.Add("foo", 1);
     Assert.AreEqual(1, lookup.Count);
     lookup.AddRange("bar", data);
     // want to check that empty insert hasn't left
     // a rogue group
     Assert.AreEqual(1, lookup.Count);
     Assert.IsFalse(lookup.Contains("bar"));
 }
Пример #11
0
        public void EditableLookupAddRangeEmptyKey()
        {
            var lookup = new EditableLookup <string, int>();

            int[] data = new int[0];
            lookup.Add("foo", 1);
            Assert.AreEqual(1, lookup.Count);
            lookup.AddRange("bar", data);
            // want to check that empty insert hasn't left
            // a rogue group
            Assert.AreEqual(1, lookup.Count);
            Assert.IsFalse(lookup.Contains("bar"));
        }
Пример #12
0
        public void EditableLookupRemove()
        {
            var lookup = new EditableLookup<string, int>();
            lookup.Add("a", 1);
            lookup.Add("a", 2);
            lookup.Add("b", 3);
            lookup.Add("a", 4);
            Assert.IsTrue(lookup.Contains("a"));
            Assert.IsTrue(lookup.Contains("b"));
            Assert.IsTrue(lookup.Contains("b", 3));
            Assert.IsFalse(lookup.Contains("b", 17));

            Assert.IsTrue(lookup.Remove("b"));
            Assert.IsFalse(lookup.Remove("b")); // no longer there
            Assert.AreEqual(1, lookup.Count);
            Assert.AreEqual(3, lookup["a"].Count());
            Assert.IsTrue(lookup.Remove("a", 1));
            Assert.IsFalse(lookup.Remove("a", 1)); // no longer there
            Assert.IsFalse(lookup.Remove("foo", 99)); // never existed

            Assert.AreEqual(6, lookup["a"].Sum()); // 2 + 4
            lookup.Remove("a", 2);
            lookup.Remove("a", 4);
            Assert.IsFalse(lookup.Contains("a"));
            Assert.AreEqual(0, lookup.Count);            
        }