Example #1
0
        public void Capacity_is_never_exceeded_when_there_are_duplicates()
        {
            var pool = new DistinctValueSortedPool <int, WithFinalizer>(Capacity, (t1, t2) =>
            {
                int t1Oddity = t1.Index % 2;
                int t2Oddity = t2.Index % 2;

                if (t1Oddity.CompareTo(t2Oddity) != 0)
                {
                    return(t1Oddity.CompareTo(t2Oddity));
                }

                return(t1.Index.CompareTo(t2.Index));
            }, new WithFinalizerComparer());

            int capacityMultiplier = 10;

            for (int i = 0; i < Capacity * capacityMultiplier; i++)
            {
                WithFinalizer newOne = new WithFinalizer(i % (Capacity * 2));
                pool.TryInsert(newOne.Index, newOne);
            }

            CollectAndFinalize();

            _finalizedCount.Should().BeLessOrEqualTo(Capacity * (capacityMultiplier - 1));
            _allCount.Should().Be(Capacity * capacityMultiplier);
            pool.Count.Should().Be(Capacity);
        }
Example #2
0
        public void Capacity_is_never_exceeded_when_there_are_duplicates()
        {
            Comparer <WithFinalizer> comparer = Comparer <WithFinalizer> .Create((t1, t2) =>
            {
                int t1Oddity = t1.Index % 2;
                int t2Oddity = t2.Index % 2;

                if (t1Oddity.CompareTo(t2Oddity) != 0)
                {
                    return(t1Oddity.CompareTo(t2Oddity));
                }

                return(t1.Index.CompareTo(t2.Index));
            });

            var pool = new WithFinalizerDistinctPool(Capacity, comparer, new WithFinalizerComparer(), LimboLogs.Instance);

            int capacityMultiplier = 10;

            for (int i = 0; i < Capacity * capacityMultiplier; i++)
            {
                WithFinalizer newOne = new WithFinalizer(i % (Capacity * 2));
                pool.TryInsert(newOne.Index, newOne);
            }

            CollectAndFinalize();

            _finalizedCount.Should().BeLessOrEqualTo(Capacity * (capacityMultiplier - 1));
            _allCount.Should().Be(Capacity * capacityMultiplier);
            pool.Count.Should().Be(Capacity);
        }
Example #3
0
        public void Capacity_is_never_exceeded()
        {
            var pool = new DistinctValueSortedPool <int, WithFinalizer>(Capacity, (t1, t2) =>
            {
                int t1Oddity = t1.Index % 2;
                int t2Oddity = t2.Index % 2;

                if (t1Oddity.CompareTo(t2Oddity) != 0)
                {
                    return(t1Oddity.CompareTo(t2Oddity));
                }

                return(t1.Index.CompareTo(t2.Index));
            }, new WithFinalizerComparer());

            int capacityMultiplier = 10;
            int expectedAllCount   = Capacity * capacityMultiplier;

            WithFinalizer newOne;

            for (int i = 0; i < expectedAllCount; i++)
            {
                newOne = new WithFinalizer();
                pool.TryInsert(newOne.Index, newOne);
            }

            newOne = null;

            CollectAndFinalize();

            _allCount.Should().Be(expectedAllCount);
            _finalizedCount.Should().BeLessOrEqualTo(expectedAllCount - Capacity);
            pool.Count.Should().Be(Capacity);
        }
Example #4
0
        public void When_Disposable_with_finalizer_is_disposed_Then_managed_and_unmanaged_resources_are_disposed()
        {
            var disposable = new WithFinalizer();

            Assert.That(disposable.IsDisposed, Is.False);
            disposable.Dispose();
            Assert.That(WithoutFinalizer.DisposeOverrideCalled, Is.True);
            Assert.That(WithoutFinalizer.BothManagedAndUnmanagedWereDisposed, Is.True);
            Assert.That(disposable.IsDisposed, Is.True);
            Assert.Throws <ObjectDisposedException>(() => disposable.CallEnsureNotDisposed());
        }
Example #5
0
        public void Capacity_is_never_exceeded()
        {
            IComparer <WithFinalizer> comparer = Comparer <WithFinalizer> .Create((t1, t2) =>
            {
                int t1Oddity = t1.Index % 2;
                int t2Oddity = t2.Index % 2;

                if (t1Oddity.CompareTo(t2Oddity) != 0)
                {
                    return(t1Oddity.CompareTo(t2Oddity));
                }

                return(t1.Index.CompareTo(t2.Index));
            });

            var pool = new WithFinalizerDistinctPool(Capacity, comparer, new WithFinalizerComparer(), LimboLogs.Instance);

            int capacityMultiplier = 10;
            int expectedAllCount   = Capacity * capacityMultiplier;

            WithFinalizer newOne;

            for (int i = 0; i < expectedAllCount; i++)
            {
                newOne = new WithFinalizer();
                pool.TryInsert(newOne.Index, newOne);
            }

            newOne = null;

            CollectAndFinalize();

            _allCount.Should().Be(expectedAllCount);
            _finalizedCount.Should().BeLessOrEqualTo(expectedAllCount - Capacity);
            pool.Count.Should().Be(Capacity);
        }