public void KeysTest() { IWDT iwdt = new IWDT(); var asDictionary = (IDictionary <Tuple <int, int>, Tuple <int, int> >)iwdt; Assert.AreEqual(0, asDictionary.Keys.Count); iwdt.AddOrUpdate(HT(1, 1), Tuple.Create(2, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(2, 1), Tuple.Create(3, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(3, 1), Tuple.Create(4, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); var keys = asDictionary.Keys; Assert.AreEqual(3, keys.Count); Assert.IsTrue(keys.Contains(Tuple.Create(1, 1))); Assert.IsTrue(keys.Contains(Tuple.Create(2, 1))); Assert.IsTrue(keys.Contains(Tuple.Create(3, 1))); iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; iwdt.Values[Tuple.Create(4, 1)].IsGarbage = true; keys = asDictionary.Keys; Assert.AreEqual(1, keys.Count); Assert.IsTrue(keys.Contains(Tuple.Create(2, 1))); }
public void TryGetValueTest() { IWDT iwdt = new IWDT(); Tuple <int, int> value; Assert.IsFalse(iwdt.TryGetValue(HT(1, 2), out value)); iwdt.AddOrUpdate(HT(1, 1), Tuple.Create(2, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(2, 1), Tuple.Create(3, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(3, 1), Tuple.Create(4, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); Assert.IsTrue(iwdt.TryGetValue(HT(1, 2), out value)); Assert.AreEqual(Tuple.Create(2, 1), value); Assert.IsTrue(iwdt.TryGetValue(HT(2, 2), out value)); Assert.AreEqual(Tuple.Create(3, 1), value); Assert.IsTrue(iwdt.TryGetValue(HT(3, 2), out value)); Assert.AreEqual(Tuple.Create(4, 1), value); iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; iwdt.Values[Tuple.Create(4, 1)].IsGarbage = true; Assert.IsFalse(iwdt.TryGetValue(HT(1, 2), out value)); Assert.IsFalse(iwdt.TryGetValue(HT(3, 2), out value)); }
public void ToArrayTest() { IWDT iwdt = new IWDT(); Assert.AreEqual(0, iwdt.ToArray().Length); iwdt.AddOrUpdate(HT(1, 1), Tuple.Create(2, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(2, 1), Tuple.Create(3, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(3, 1), Tuple.Create(4, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); var array = iwdt.ToArray(); Assert.AreEqual(3, array.Length); var list = System.Linq.Enumerable.ToList(array); Assert.IsTrue(list.Contains(new KeyValuePair <Tuple <int, int>, Tuple <int, int> >(Tuple.Create(1, 1), Tuple.Create(2, 1)))); Assert.IsTrue(list.Contains(new KeyValuePair <Tuple <int, int>, Tuple <int, int> >(Tuple.Create(2, 1), Tuple.Create(3, 1)))); Assert.IsTrue(list.Contains(new KeyValuePair <Tuple <int, int>, Tuple <int, int> >(Tuple.Create(3, 1), Tuple.Create(4, 1)))); iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; iwdt.Values[Tuple.Create(4, 1)].IsGarbage = true; array = iwdt.ToArray(); Assert.AreEqual(1, array.Length); Assert.AreEqual(new KeyValuePair <Tuple <int, int>, Tuple <int, int> >(Tuple.Create(2, 1), Tuple.Create(3, 1)), array[0]); }
public void GetEnumeratorTest() { IWDT iwdt = new IWDT(); var asEnumerable = (IEnumerable <KeyValuePair <Tuple <int, int>, Tuple <int, int> > >)iwdt; using (var it = asEnumerable.GetEnumerator()) Assert.IsFalse(it.MoveNext()); iwdt.AddOrUpdate(HT(1, 1), Tuple.Create(2, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(2, 1), Tuple.Create(3, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(3, 1), Tuple.Create(4, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); using (var it = asEnumerable.GetEnumerator()) { Assert.IsTrue(it.MoveNext()); Assert.IsTrue(it.MoveNext()); Assert.IsTrue(it.MoveNext()); Assert.IsFalse(it.MoveNext()); } iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; iwdt.Values[Tuple.Create(4, 1)].IsGarbage = true; using (var it = asEnumerable.GetEnumerator()) { Assert.IsTrue(it.MoveNext()); Assert.IsFalse(it.MoveNext()); } }
public void GetItemTest() { IWDT iwdt = new IWDT(); try { var itm = iwdt.GetItem(HT(1, 1)); Assert.Fail(); } catch (KeyNotFoundException) { } iwdt.AddOrUpdate(HT(1, 1), 2, (k, v) => { throw new AssertFailedException(); return(default(int)); }); iwdt.AddOrUpdate(HT(2, 1), 3, (k, v) => { throw new AssertFailedException(); return(default(int)); }); iwdt.AddOrUpdate(HT(3, 1), 4, (k, v) => { throw new AssertFailedException(); return(default(int)); }); Assert.AreEqual(2, iwdt.GetItem(HT(1, 2))); Assert.AreEqual(3, iwdt.GetItem(HT(2, 2))); Assert.AreEqual(4, iwdt.GetItem(HT(3, 2))); iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; try { var itm = iwdt.GetItem(HT(1, 2)); Assert.Fail(); } catch (KeyNotFoundException) { } }
public void GetContentsTest() { IWDT iwdt = new IWDT(); var contents = iwdt.GetContents(); Assert.AreEqual(0, contents.Count); iwdt.AddOrUpdate(HT(1, 1), Tuple.Create(2, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(2, 1), Tuple.Create(3, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(3, 1), Tuple.Create(4, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); contents = iwdt.GetContents(); Assert.AreEqual(3, contents.Count); Assert.IsTrue(contents.Contains(new KeyValuePair <Tuple <int, int>, Tuple <int, int> >(Tuple.Create(1, 1), Tuple.Create(2, 1)))); Assert.IsTrue(contents.Contains(new KeyValuePair <Tuple <int, int>, Tuple <int, int> >(Tuple.Create(2, 1), Tuple.Create(3, 1)))); Assert.IsTrue(contents.Contains(new KeyValuePair <Tuple <int, int>, Tuple <int, int> >(Tuple.Create(3, 1), Tuple.Create(4, 1)))); iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; iwdt.Values[Tuple.Create(4, 1)].IsGarbage = true; contents = iwdt.GetContents(); Assert.AreEqual(1, contents.Count); Assert.IsTrue(contents.Contains(new KeyValuePair <Tuple <int, int>, Tuple <int, int> >(Tuple.Create(2, 1), Tuple.Create(3, 1)))); }
public void CopyToTest() { IWDT iwdt = new IWDT(); var asCollection = (ICollection <KeyValuePair <Tuple <int, int>, Tuple <int, int> > >)iwdt; iwdt.AddOrUpdate(HT(1, 1), Tuple.Create(2, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(2, 1), Tuple.Create(3, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(3, 1), Tuple.Create(4, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); var array = new KeyValuePair <Tuple <int, int>, Tuple <int, int> > [3]; try { asCollection.CopyTo(array, 4); Assert.Fail(); } catch (IndexOutOfRangeException) { } try { asCollection.CopyTo(array, -1); Assert.Fail(); } catch (IndexOutOfRangeException) { } try { asCollection.CopyTo(null, 0); Assert.Fail(); } catch (ArgumentNullException) { } try { asCollection.CopyTo(array, 1); Assert.Fail(); } catch (ArgumentException) { } iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; iwdt.Values[Tuple.Create(4, 1)].IsGarbage = true; array = new KeyValuePair <Tuple <int, int>, Tuple <int, int> > [3]; asCollection.CopyTo(array, 1); Assert.AreEqual(default(KeyValuePair <Tuple <int, int>, Tuple <int, int> >), array[0]); Assert.AreEqual(new KeyValuePair <Tuple <int, int>, Tuple <int, int> >(Tuple.Create(2, 1), Tuple.Create(3, 1)), array[1]); Assert.AreEqual(default(KeyValuePair <Tuple <int, int>, Tuple <int, int> >), array[2]); }
public void ContainsKeyTest() { IWDT iwdt = new IWDT(); Assert.IsFalse(iwdt.ContainsKey(HT(1, 2))); iwdt.AddOrUpdate(HT(1, 1), 2, (k, v) => { throw new AssertFailedException(); return(default(int)); }); Assert.IsTrue(iwdt.ContainsKey(HT(1, 2))); iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; Assert.IsFalse(iwdt.ContainsKey(HT(1, 2))); iwdt.AddOrUpdate(HT(2, 1), 2, (k, v) => { throw new AssertFailedException(); return(default(int)); }); Assert.IsTrue(iwdt.ContainsKey(HT(2, 2))); Assert.IsTrue(iwdt.ContainsKey(HT(2, 2))); }
public void TryUpdateTest() { var iwdt = new IWDT(); Assert.IsFalse(iwdt.TryUpdate(HT(1, 2), 12, 2)); iwdt.AddOrUpdate(HT(1, 1), 2, (k, v) => { throw new AssertFailedException(); return(default(int)); }); iwdt.AddOrUpdate(HT(2, 1), 3, (k, v) => { throw new AssertFailedException(); return(default(int)); }); iwdt.AddOrUpdate(HT(3, 1), 4, (k, v) => { throw new AssertFailedException(); return(default(int)); }); Assert.IsTrue(iwdt.TryUpdate(HT(1, 2), 12, 2)); Assert.AreEqual(12, iwdt.GetItem(HT(1, 2))); iwdt.Keys[Tuple.Create(2, 1)].IsGarbage = true; Assert.IsFalse(iwdt.TryUpdate(HT(2, 2), 13, 3)); }
public void IsEmptyTest() { var iwdt = new IWDT(); Assert.IsTrue(iwdt.IsEmpty); iwdt.AddOrUpdate(HT(2, 1), Tuple.Create(3, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); Assert.IsFalse(iwdt.IsEmpty); iwdt.AddOrUpdate(HT(3, 1), Tuple.Create(4, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); Assert.IsFalse(iwdt.IsEmpty); iwdt.Keys[Tuple.Create(2, 1)].IsGarbage = true; iwdt.Values[Tuple.Create(4, 1)].IsGarbage = true; Assert.IsTrue(iwdt.IsEmpty); }
public void RemoveTest1() { IWDT iwdt = new IWDT(); var asDictionary = (IDictionary <Tuple <int, int>, int>)iwdt; Assert.IsFalse(asDictionary.Remove(Tuple.Create(1, 2))); iwdt.AddOrUpdate(HT(1, 1), 2, (k, v) => { throw new AssertFailedException(); return(default(int)); }); iwdt.AddOrUpdate(HT(2, 1), 3, (k, v) => { throw new AssertFailedException(); return(default(int)); }); iwdt.AddOrUpdate(HT(3, 1), 4, (k, v) => { throw new AssertFailedException(); return(default(int)); }); Assert.IsTrue(asDictionary.Remove(Tuple.Create(1, 2))); Assert.IsFalse(asDictionary.ContainsKey(Tuple.Create(1, 2))); iwdt.Keys[Tuple.Create(2, 1)].IsGarbage = true; Assert.IsFalse(asDictionary.Remove(Tuple.Create(2, 2))); }
public void DoMaintenanceTest() { var iwdt = new IWDT(); iwdt.AddOrUpdate(HT(1, 1), Tuple.Create(2, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(2, 1), Tuple.Create(3, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(3, 1), Tuple.Create(4, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.Keys[Tuple.Create(2, 1)].IsGarbage = true; iwdt.Values[Tuple.Create(4, 1)].IsGarbage = true; var asBaseDictionary = (IDictionary <Trashable, ValueTrashable>)iwdt; Assert.AreEqual(3, asBaseDictionary.Count); ((IMaintainable)iwdt).DoMaintenance(); Assert.AreEqual(1, asBaseDictionary.Count); Assert.IsTrue(asBaseDictionary.Contains(new KeyValuePair <Trashable, ValueTrashable>(iwdt.Keys[Tuple.Create(1, 1)], iwdt.Values[Tuple.Create(2, 1)]))); }
public void RemoveTest() { IWDT iwdt = new IWDT(); var asCollection = (ICollection <KeyValuePair <Tuple <int, int>, int> >)iwdt; Assert.IsFalse(asCollection.Remove(new KeyValuePair <Tuple <int, int>, int>(Tuple.Create(1, 2), 2))); iwdt.AddOrUpdate(HT(1, 1), 2, (k, v) => { throw new AssertFailedException(); return(default(int)); }); iwdt.AddOrUpdate(HT(2, 1), 3, (k, v) => { throw new AssertFailedException(); return(default(int)); }); iwdt.AddOrUpdate(HT(3, 1), 4, (k, v) => { throw new AssertFailedException(); return(default(int)); }); Assert.IsTrue(asCollection.Remove(new KeyValuePair <Tuple <int, int>, int>(Tuple.Create(1, 2), 2))); Assert.IsFalse(asCollection.Remove(new KeyValuePair <Tuple <int, int>, int>(Tuple.Create(1, 2), 2))); Assert.IsFalse(asCollection.Contains(new KeyValuePair <Tuple <int, int>, int>(Tuple.Create(1, 2), 2))); iwdt.Keys[Tuple.Create(2, 1)].IsGarbage = true; Assert.IsFalse(asCollection.Remove(new KeyValuePair <Tuple <int, int>, int>(Tuple.Create(2, 2), 3))); Assert.IsTrue(asCollection.Remove(new KeyValuePair <Tuple <int, int>, int>(Tuple.Create(3, 2), 4))); }
public void CountTest() { var iwdt = new IWDT(); var asCollection = (ICollection <KeyValuePair <Tuple <int, int>, Tuple <int, int> > >)iwdt; Assert.AreEqual(0, asCollection.Count); iwdt.AddOrUpdate(HT(2, 1), Tuple.Create(3, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); Assert.AreEqual(1, asCollection.Count); iwdt.AddOrUpdate(HT(3, 1), Tuple.Create(4, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); Assert.AreEqual(2, asCollection.Count); iwdt.Keys[Tuple.Create(2, 1)].IsGarbage = true; Assert.AreEqual(1, asCollection.Count); iwdt.Values[Tuple.Create(4, 1)].IsGarbage = true; Assert.AreEqual(0, asCollection.Count); }
public void TryRemoveTest() { IWDT iwdt = new IWDT(); var asDictionary = (IDictionary <Tuple <int, int>, Tuple <int, int> >)iwdt; Tuple <int, int> value; Assert.IsFalse(iwdt.TryRemove(HT(1, 2), out value)); iwdt.AddOrUpdate(HT(1, 1), Tuple.Create(2, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(2, 1), Tuple.Create(3, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); iwdt.AddOrUpdate(HT(3, 1), Tuple.Create(4, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); }); Assert.IsTrue(iwdt.TryRemove(HT(1, 2), out value)); Assert.AreEqual(Tuple.Create(2, 1), value); Assert.IsFalse(asDictionary.ContainsKey(Tuple.Create(1, 2))); iwdt.Keys[Tuple.Create(2, 1)].IsGarbage = true; iwdt.Values[Tuple.Create(4, 1)].IsGarbage = true; Assert.IsFalse(iwdt.TryRemove(HT(2, 2), out value)); Assert.IsFalse(iwdt.TryRemove(HT(3, 2), out value)); }
public void ValuesTest() { IWDT iwdt = new IWDT(); var asDictionary = (IDictionary <Tuple <int, int>, int>)iwdt; var values = asDictionary.Values; Assert.AreEqual(0, values.Count); iwdt.AddOrUpdate(HT(1, 1), 2, (k, v) => { throw new AssertFailedException(); return(default(int)); }); iwdt.AddOrUpdate(HT(2, 1), 3, (k, v) => { throw new AssertFailedException(); return(default(int)); }); iwdt.AddOrUpdate(HT(3, 1), 4, (k, v) => { throw new AssertFailedException(); return(default(int)); }); Assert.AreEqual(3, values.Count); Assert.IsTrue(values.Contains(2)); Assert.IsTrue(values.Contains(3)); Assert.IsTrue(values.Contains(4)); iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; Assert.AreEqual(2, values.Count); Assert.IsTrue(values.Contains(3)); Assert.IsTrue(values.Contains(4)); }