Ejemplo n.º 1
0
 private TestGSet.IntElement PutTest(TestGSet.IntElement element)
 {
     TestGSet.IntElement e = expected.Put(element);
     if (e == null)
     {
         Assert.Equal(null, gset.Put(element));
     }
     else
     {
         Assert.Equal(e.id, gset.Put(element).id);
     }
     return(e);
 }
Ejemplo n.º 2
0
 private TestLightWeightCache.IntEntry PutTest(TestLightWeightCache.IntEntry entry
                                               )
 {
     TestLightWeightCache.IntEntry c = cache.Put(entry);
     if (c != null)
     {
         Assert.Equal(hashMap.Put(entry).id, c.id);
     }
     else
     {
         TestLightWeightCache.IntEntry h = hashMap.Put(entry);
         if (h != null && h != entry)
         {
             // if h == entry, its expiration time is already updated
             Assert.True(cache.IsExpired(h, currentTestTime));
         }
     }
     return(c);
 }
Ejemplo n.º 3
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);
                 }
             }
         }
     }
 }