Пример #1
0
 internal GSetTestCase(int tablelength, int datasize, int modulus)
 {
     denominator = Math.Min((datasize >> 7) + 1, 1 << 16);
     info        = GetType().Name + ": tablelength=" + tablelength + ", datasize=" + datasize
                   + ", modulus=" + modulus + ", denominator=" + denominator;
     Println(info);
     data = new TestGSet.IntData(datasize, modulus);
     gset = new LightWeightGSet <TestGSet.IntElement, TestGSet.IntElement>(tablelength);
     Assert.Equal(0, gset.Size());
 }
Пример #2
0
 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);
                 }
             }
         }
     }
 }