public void GetContentsTest() { IWDT iwdt = new IWDT(); var contents = iwdt.GetContents(); Assert.AreEqual(0, contents.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)); }); contents = iwdt.GetContents(); Assert.AreEqual(3, contents.Count); Assert.IsTrue(contents.Contains(new KeyValuePair <Tuple <int, int>, int>(Tuple.Create(1, 1), 2))); Assert.IsTrue(contents.Contains(new KeyValuePair <Tuple <int, int>, int>(Tuple.Create(2, 1), 3))); Assert.IsTrue(contents.Contains(new KeyValuePair <Tuple <int, int>, int>(Tuple.Create(3, 1), 4))); iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; contents = iwdt.GetContents(); Assert.AreEqual(2, contents.Count); Assert.IsTrue(contents.Contains(new KeyValuePair <Tuple <int, int>, int>(Tuple.Create(2, 1), 3))); Assert.IsTrue(contents.Contains(new KeyValuePair <Tuple <int, int>, int>(Tuple.Create(3, 1), 4))); }
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 GetEnumeratorTest() { IWDT iwdt = new IWDT(); var asEnumerable = (IEnumerable <KeyValuePair <Tuple <int, int>, int> >)iwdt; using (var it = asEnumerable.GetEnumerator()) Assert.IsFalse(it.MoveNext()); 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)); }); 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; using (var it = asEnumerable.GetEnumerator()) { Assert.IsTrue(it.MoveNext()); Assert.IsTrue(it.MoveNext()); Assert.IsFalse(it.MoveNext()); } }
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 TryAddTest() { IWDT iwdt = new IWDT(); Assert.IsTrue(iwdt.TryAdd(HT(1, 1), 4)); Assert.AreEqual(4, iwdt.GetItem(HT(1, 2))); Assert.IsFalse(iwdt.TryAdd(HT(1, 3), 8)); iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; Assert.IsTrue(iwdt.TryAdd(HT(1, 3), 8)); Assert.AreEqual(8, iwdt.GetItem(HT(1, 2))); }
public void InsertContentsTest() { IWDT iwdt = new IWDT(); IEnumerable <KeyValuePair <Tuple <int, int>, Tuple <int, int> > > contents = new KeyValuePair <Tuple <int, int>, Tuple <int, int> >[] { new KeyValuePair <Tuple <int, int>, Tuple <int, int> > (Tuple.Create(1, 1), Tuple.Create(2, 1)), new KeyValuePair <Tuple <int, int>, Tuple <int, int> > (Tuple.Create(3, 1), Tuple.Create(7, 1)), new KeyValuePair <Tuple <int, int>, Tuple <int, int> > (Tuple.Create(5, 1), Tuple.Create(13, 1)) } ; iwdt.InsertContents(contents); Assert.AreEqual(Tuple.Create(2, 1), iwdt.GetItem(HT(1, 2))); Assert.AreEqual(Tuple.Create(7, 1), iwdt.GetItem(HT(3, 2))); Assert.AreEqual(Tuple.Create(13, 1), iwdt.GetItem(HT(5, 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 SetItemTest() { IWDT iwdt = new IWDT(); iwdt.SetItem(HT(1, 1), 3); Assert.AreEqual(3, iwdt.GetItem(HT(1, 2))); iwdt.SetItem(HT(1, 1), 7); Assert.AreEqual(7, iwdt.GetItem(HT(1, 2))); iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; iwdt.SetItem(HT(1, 3), 13); Assert.AreEqual(13, iwdt.GetItem(HT(1, 2))); }
public void ClearTest() { IWDT iwdt = new IWDT(); var asCollection = (ICollection <KeyValuePair <Tuple <int, int>, Tuple <int, int> > >)iwdt; IEnumerable <KeyValuePair <Tuple <int, int>, Tuple <int, int> > > contents = new KeyValuePair <Tuple <int, int>, Tuple <int, int> >[] { new KeyValuePair <Tuple <int, int>, Tuple <int, int> > (Tuple.Create(1, 1), Tuple.Create(2, 1)), new KeyValuePair <Tuple <int, int>, Tuple <int, int> > (Tuple.Create(3, 1), Tuple.Create(7, 1)), new KeyValuePair <Tuple <int, int>, Tuple <int, int> > (Tuple.Create(5, 1), Tuple.Create(13, 1)) } ; iwdt.InsertContents(contents); asCollection.Clear(); Assert.AreEqual(0, iwdt.Count); }
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 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 TryUpdateTest() { var iwdt = new IWDT(); Assert.IsFalse(iwdt.TryUpdate(HT(1, 2), Tuple.Create(12, 1), Tuple.Create(2, 2))); 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.TryUpdate(HT(1, 2), Tuple.Create(12, 1), Tuple.Create(2, 2))); Assert.AreEqual(Tuple.Create(12, 1), iwdt.GetItem(HT(1, 2))); iwdt.Keys[Tuple.Create(2, 1)].IsGarbage = true; iwdt.Values[Tuple.Create(4, 1)].IsGarbage = true; Assert.IsFalse(iwdt.TryUpdate(HT(2, 2), Tuple.Create(13, 1), Tuple.Create(3, 2))); Assert.IsFalse(iwdt.TryUpdate(HT(3, 2), Tuple.Create(14, 1), Tuple.Create(4, 2))); }
public void GetOrAddTest() { IWDT iwdt = new IWDT(); var ret = iwdt.GetOrAdd(HT(1, 1), Tuple.Create(2, 1)); Assert.AreEqual(Tuple.Create(2, 1), ret); Assert.AreEqual(Tuple.Create(2, 1), iwdt.GetItem(HT(1, 1))); ret = iwdt.GetOrAdd(HT(1, 1), Tuple.Create(3, 1)); Assert.AreEqual(Tuple.Create(2, 1), ret); Assert.AreEqual(Tuple.Create(2, 1), iwdt.GetItem(HT(1, 2))); iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; ret = iwdt.GetOrAdd(HT(1, 2), Tuple.Create(3, 1)); Assert.AreEqual(Tuple.Create(3, 1), ret); Assert.AreEqual(Tuple.Create(3, 1), iwdt.GetItem(HT(1, 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 ItemTest() { var iwdt = new IWDT(); var asDictionary = (IDictionary <Tuple <int, int>, Tuple <int, int> >)iwdt; Tuple <int, int> value; try { value = asDictionary[Tuple.Create(1, 2)]; Assert.Fail(); } catch (KeyNotFoundException) {} asDictionary[Tuple.Create(1, 1)] = Tuple.Create(2, 1); asDictionary[Tuple.Create(2, 1)] = Tuple.Create(3, 1); Assert.AreEqual(Tuple.Create(2, 1), asDictionary[Tuple.Create(1, 2)]); Assert.AreEqual(Tuple.Create(3, 1), asDictionary[Tuple.Create(2, 2)]); iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; iwdt.Values[Tuple.Create(3, 1)].IsGarbage = true; try { value = asDictionary[Tuple.Create(1, 2)]; Assert.Fail(); } catch (KeyNotFoundException) { } try { value = asDictionary[Tuple.Create(2, 2)]; Assert.Fail(); } catch (KeyNotFoundException) { } }
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 AddTest() { IWDT iwdt = new IWDT(); var asCollection = (ICollection <KeyValuePair <Tuple <int, int>, int> >)iwdt; asCollection.Add(new KeyValuePair <Tuple <int, int>, int>(Tuple.Create(1, 1), 4)); Assert.AreEqual(4, iwdt.GetItem(HT(1, 2))); try { asCollection.Add(new KeyValuePair <Tuple <int, int>, int>(Tuple.Create(1, 3), 8)); Assert.Fail(); } catch (ArgumentException) { } iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; asCollection.Add(new KeyValuePair <Tuple <int, int>, int>(Tuple.Create(1, 3), 8)); Assert.AreEqual(8, iwdt.GetItem(HT(1, 2))); }
public void AddTest1() { IWDT iwdt = new IWDT(); var asDictionary = (IDictionary <Tuple <int, int>, int>)iwdt; asDictionary.Add(Tuple.Create(1, 1), 4); Assert.AreEqual(4, iwdt.GetItem(HT(1, 2))); try { asDictionary.Add(Tuple.Create(1, 3), 8); Assert.Fail(); } catch (ArgumentException) { } iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; asDictionary.Add(Tuple.Create(1, 3), 8); Assert.AreEqual(8, iwdt.GetItem(HT(1, 2))); }
public void ValuesTest() { IWDT iwdt = new IWDT(); var asDictionary = (IDictionary <Tuple <int, int>, Tuple <int, int> >)iwdt; var values = asDictionary.Values; Assert.AreEqual(0, values.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>)); }); Assert.AreEqual(3, values.Count); Assert.IsTrue(values.Contains(Tuple.Create(2, 1))); Assert.IsTrue(values.Contains(Tuple.Create(3, 1))); Assert.IsTrue(values.Contains(Tuple.Create(4, 1))); iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; iwdt.Values[Tuple.Create(4, 1)].IsGarbage = true; Assert.AreEqual(1, values.Count); Assert.IsTrue(values.Contains(Tuple.Create(3, 1))); }
public void SetItemTest() { IWDT iwdt = new IWDT(); iwdt.SetItem(HT(1, 1), Tuple.Create(3, 1)); Assert.AreEqual(Tuple.Create(3, 1), iwdt.GetItem(HT(1, 2))); iwdt.SetItem(HT(1, 1), Tuple.Create(7, 1)); Assert.AreEqual(Tuple.Create(7, 1), iwdt.GetItem(HT(1, 2))); iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true; iwdt.SetItem(HT(1, 3), Tuple.Create(13, 1)); Assert.AreEqual(Tuple.Create(13, 1), iwdt.GetItem(HT(1, 2))); iwdt.Values[Tuple.Create(13, 1)].IsGarbage = true; iwdt.SetItem(HT(1, 3), Tuple.Create(13, 3)); Assert.AreEqual(Tuple.Create(13, 3), iwdt.GetItem(HT(1, 2))); }
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)); }