/// <summary>Return capacity as percentage of total memory</summary> private static void TestCapacity(long maxMemory, double percent) { int capacity = LightWeightGSet.ComputeCapacity(maxMemory, percent, "map"); LightWeightGSet.Log.Info("Validating - total memory " + maxMemory + " percent " + percent + " returned capacity " + capacity); // Returned capacity is zero or power of two Assert.True(IsPowerOfTwo(capacity)); // Ensure the capacity returned is the nearest to the asked perecentage int capacityPercent = GetPercent(maxMemory, capacity); if (capacityPercent == percent) { return; } else { if (capacityPercent > percent) { Assert.True(GetPercent(maxMemory, capacity * 2) > percent); } else { Assert.True(GetPercent(maxMemory, capacity / 2) < percent); } } }
private static GSet <TestGSet.IntElement, TestGSet.IntElement> CreateGSet(TestGSet.IntElement [] data) { GSet <TestGSet.IntElement, TestGSet.IntElement> gset = new LightWeightGSet <TestGSet.IntElement , TestGSet.IntElement>(8); for (int i = 1; i < data.Length; i++) { gset.Put(data[i]); } return(gset); }
public virtual void TestRemoveAllViaIterator() { AList <int> list = GetRandomList(100, 123); LightWeightGSet <TestLightWeightGSet.TestElement, TestLightWeightGSet.TestElement> set = new LightWeightGSet <TestLightWeightGSet.TestElement, TestLightWeightGSet.TestElement >(16); foreach (int i in list) { set.Put(new TestLightWeightGSet.TestElement(i)); } for (IEnumerator <TestLightWeightGSet.TestElement> iter = set.GetEnumerator(); iter .HasNext();) { iter.Next(); iter.Remove(); } Assert.Equal(0, set.Size()); }
public virtual void TestRemoveSomeViaIterator() { AList <int> list = GetRandomList(100, 123); LightWeightGSet <TestLightWeightGSet.TestElement, TestLightWeightGSet.TestElement> set = new LightWeightGSet <TestLightWeightGSet.TestElement, TestLightWeightGSet.TestElement >(16); foreach (int i in list) { set.Put(new TestLightWeightGSet.TestElement(i)); } long sum = 0; for (IEnumerator <TestLightWeightGSet.TestElement> iter = set.GetEnumerator(); iter .HasNext();) { sum += iter.Next().GetVal(); } long mode = sum / set.Size(); Log.Info("Removing all elements above " + mode); for (IEnumerator <TestLightWeightGSet.TestElement> iter_1 = set.GetEnumerator(); iter_1 .HasNext();) { int item = iter_1.Next().GetVal(); if (item > mode) { iter_1.Remove(); } } for (IEnumerator <TestLightWeightGSet.TestElement> iter_2 = set.GetEnumerator(); iter_2 .HasNext();) { Assert.True(iter_2.Next().GetVal() <= mode); } }
/// <summary> /// Test for /// <see cref="LightWeightGSet{K, E}.ComputeCapacity(double, string)"/> /// with invalid negative max memory /// </summary> public virtual void TestComputeCapacityInvalidMemory() { LightWeightGSet.ComputeCapacity(-1, 50.0, "testMap"); }
/// <summary> /// Test for /// <see cref="LightWeightGSet{K, E}.ComputeCapacity(double, string)"/> /// with invalid percent greater than 100. /// </summary> public virtual void TestComputeCapacityInvalidPercent() { LightWeightGSet.ComputeCapacity(1024, 101.0, "testMap"); }
/// <summary> /// Test for /// <see cref="LightWeightGSet{K, E}.ComputeCapacity(double, string)"/> /// with invalid percent less than 0. /// </summary> public virtual void TestComputeCapacityNegativePercent() { LightWeightGSet.ComputeCapacity(1024, -1.0, "testMap"); }
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); } } } } }
internal SetIterator(LightWeightGSet <K, E> _enclosing) { this._enclosing = _enclosing; }