private TestGSet.IntElement RemoveTest(TestGSet.IntElement key) { TestGSet.IntElement e = expected.Remove(key); if (e == null) { Assert.Equal(null, gset.Remove(key)); } else { Assert.Equal(e.id, gset.Remove(key).id); } return(e); }
private bool ContainsTest(TestLightWeightCache.IntEntry key) { bool c = cache.Contains(key); if (c) { Assert.True(hashMap.Contains(key)); } else { TestLightWeightCache.IntEntry h = hashMap.Remove(key); if (h != null) { Assert.True(cache.IsExpired(h, currentTestTime)); } } return(c); }
public virtual void TestExceptionCases() { { //test contains LightWeightGSet <int, int> gset = new LightWeightGSet <int, int>(16); try { //test contains with a null element gset.Contains(null); NUnit.Framework.Assert.Fail(); } catch (ArgumentNullException e) { LightWeightGSet.Log.Info("GOOD: getting " + e, e); } } { //test get LightWeightGSet <int, int> gset = new LightWeightGSet <int, int>(16); try { //test get with a null element gset.Get(null); NUnit.Framework.Assert.Fail(); } catch (ArgumentNullException e) { LightWeightGSet.Log.Info("GOOD: getting " + e, e); } } { //test put LightWeightGSet <int, int> gset = new LightWeightGSet <int, int>(16); try { //test put with a null element gset.Put(null); NUnit.Framework.Assert.Fail(); } catch (ArgumentNullException e) { LightWeightGSet.Log.Info("GOOD: getting " + e, e); } try { //test putting an element which is not implementing LinkedElement gset.Put(1); NUnit.Framework.Assert.Fail(); } catch (ArgumentException e) { LightWeightGSet.Log.Info("GOOD: getting " + e, e); } } { //test iterator TestGSet.IntElement[] data = new TestGSet.IntElement[5]; for (int i = 0; i < data.Length; i++) { data[i] = new TestGSet.IntElement(i, i); } for (int v = 1; v < data.Length - 1; v++) { { //test remove while iterating GSet <TestGSet.IntElement, TestGSet.IntElement> gset = CreateGSet(data); foreach (TestGSet.IntElement i_1 in gset) { if (i_1.value == v) { //okay because data[0] is not in gset gset.Remove(data[0]); } } try { //exception because data[1] is in gset foreach (TestGSet.IntElement i_2 in gset) { if (i_2.value == v) { gset.Remove(data[1]); } } NUnit.Framework.Assert.Fail(); } catch (ConcurrentModificationException e) { LightWeightGSet.Log.Info("GOOD: getting " + e, e); } } { //test put new element while iterating GSet <TestGSet.IntElement, TestGSet.IntElement> gset = CreateGSet(data); try { foreach (TestGSet.IntElement i_1 in gset) { if (i_1.value == v) { gset.Put(data[0]); } } NUnit.Framework.Assert.Fail(); } catch (ConcurrentModificationException e) { LightWeightGSet.Log.Info("GOOD: getting " + e, e); } } { //test put existing element while iterating GSet <TestGSet.IntElement, TestGSet.IntElement> gset = CreateGSet(data); try { foreach (TestGSet.IntElement i_1 in gset) { if (i_1.value == v) { gset.Put(data[3]); } } NUnit.Framework.Assert.Fail(); } catch (ConcurrentModificationException e) { LightWeightGSet.Log.Info("GOOD: getting " + e, e); } } } } }