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); }
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()); }
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()); }
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()); }
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()); }
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()); }
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()); }
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)); }
public bool Put(string key, string val) { var alreadyExists = data.Contains(key, val); if (!alreadyExists) { data.Add(key, val); } return(!alreadyExists); }
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")); }
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")); }
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); }