public void ShouldHoldWeakReference()
        {
            if (GC.MaxGeneration == 0)
            {
                Assert.Inconclusive("Not working on boehm");
            }

            var table = new WeakMultiTable <NotSoWeakClass, int>();
            var wr    = GenerateWeakReferenceAndInsertIntoTable(table);

            // In theory one GC.Collect() call should be sufficient;
            // Ubuntu32 with mono 4.8.1 shows that this is just a theory ;)
            // My tests showed that calling it twice is enough, but
            // in order to be on a safe side I decided to round it up to 10.
            // I know it is not the prettiest solution, but:
            //   (a) it's just a test,
            //   (b) it works fine on every other setup,
            //   (c) we are not responsible for the code of GC.
            for (var i = 0; i < 10 && wr.IsAlive; i++)
            {
                GC.Collect();
            }

            Assert.IsFalse(wr.IsAlive);
        }
        private WeakReference GenerateWeakReferenceAndInsertIntoTable(WeakMultiTable <NotSoWeakClass, int> table)
        {
            var item = new NotSoWeakClass();

            table.Add(item, 0);
            return(new WeakReference(item));
        }
示例#3
0
 public void ShouldHandleManyLeftValuesForRight()
 {
     var table = new WeakMultiTable<int, int>();
     table.Add(5, 0);
     table.Add(6, 0);
     Assert.AreEqual(2, table.GetAllForRight(0).Count());
 }
        public void ShouldHandleRemoveOfUnexistingItem()
        {
            var table = new WeakMultiTable <int, int>();

            Assert.AreEqual(0, table.GetAllForLeft(0).Count());
            table.RemovePair(0, 0);
            Assert.AreEqual(0, table.GetAllForLeft(0).Count());
        }
        public void ShouldHandleManyLeftValuesForRight()
        {
            var table = new WeakMultiTable <int, int>();

            table.Add(5, 0);
            table.Add(6, 0);
            Assert.AreEqual(2, table.GetAllForRight(0).Count());
        }
示例#6
0
        public void ShouldHandleRemoveOfUnexistingItem()
        {
            var table = new WeakMultiTable<int, int>();

            Assert.AreEqual(0, table.GetAllForLeft(0).Count());
            table.RemovePair(0, 0);
            Assert.AreEqual(0, table.GetAllForLeft(0).Count());
        }
示例#7
0
        public void ShouldHoldWeakReference()
        {
            if (GC.MaxGeneration == 0)
            {
                Assert.Inconclusive("Not working on boehm");
            }

            var table = new WeakMultiTable <NotSoWeakClass, int>();
            var wr    = GenerateWeakReferenceAndInsertIntoTable(table);

            GC.Collect();
            Assert.IsFalse(wr.IsAlive);
        }
示例#8
0
        public void ShouldHoldWeakReference()
        {
            if (GC.MaxGeneration == 0)
            {
                Assert.Inconclusive("Not working on boehm");
            }

            var table = new WeakMultiTable<NotSoWeakClass, int>();
            var wr = GenerateWeakReferenceAndInsertIntoTable(table);

            GC.Collect();
            Assert.IsFalse(wr.IsAlive);
        }
示例#9
0
        public void ShouldRemovePair()
        {
            var table = new WeakMultiTable<int, int>();
            table.Add(0, 0);
            table.Add(1, 1);

            Assert.AreEqual(1, table.GetAllForLeft(0).Count());
            Assert.AreEqual(1, table.GetAllForLeft(1).Count());

            table.RemovePair(0, 0);

            Assert.AreEqual(0, table.GetAllForLeft(0).Count());
            Assert.AreEqual(1, table.GetAllForLeft(1).Count());
        }
        public void ShouldRemovePair()
        {
            var table = new WeakMultiTable <int, int>();

            table.Add(0, 0);
            table.Add(1, 1);

            Assert.AreEqual(1, table.GetAllForLeft(0).Count());
            Assert.AreEqual(1, table.GetAllForLeft(1).Count());

            table.RemovePair(0, 0);

            Assert.AreEqual(0, table.GetAllForLeft(0).Count());
            Assert.AreEqual(1, table.GetAllForLeft(1).Count());
        }
示例#11
0
 public Connector()
 {
     connections = new WeakMultiTable <IConnectable, IEmulationElement>();
 }
示例#12
0
文件: Connector.cs 项目: rte-se/emul8
 public Connector()
 {
     connections = new WeakMultiTable<IConnectable, IEmulationElement>();
 }
示例#13
0
 private WeakReference GenerateWeakReferenceAndInsertIntoTable(WeakMultiTable<NotSoWeakClass, int> table)
 {
     var item = new NotSoWeakClass();
     table.Add(item, 0);
     return new WeakReference(item);
 }