Exemplo n.º 1
0
 public int Allocate()
 {
     if (IndexesRemaining == 0)
     {
         Expand();
     }
     return(IndexPool.AllocateInstance());
 }
Exemplo n.º 2
0
        public void should_allocate_and_remove_next_available_index()
        {
            var indexPool = new IndexPool(10, 10);
            var index     = indexPool.AllocateInstance();

            Assert.InRange(index, 0, 10);
            Assert.DoesNotContain(index, indexPool.AvailableIndexes);
        }
Exemplo n.º 3
0
        public void should_expand_and_allocate_and_remove_next_available_index_when_empty()
        {
            var defaultExpansionAmount = 30;
            var originalSize           = 10;
            var expectedSize           = defaultExpansionAmount + originalSize;
            var indexPool = new IndexPool(defaultExpansionAmount, originalSize);

            indexPool.Clear();
            var index = indexPool.AllocateInstance();

            var expectedIdEntries = Enumerable.Range(0, expectedSize).ToList();

            Assert.InRange(index, 0, expectedSize);
            Assert.DoesNotContain(index, indexPool.AvailableIndexes);
            Assert.All(indexPool.AvailableIndexes, x => expectedIdEntries.Contains(x));
        }
Exemplo n.º 4
0
        public void should_continually_expand_correctly_when_allocating_over_count()
        {
            var expectedAllocations    = 200;
            var defaultExpansionAmount = 5;
            var originalSize           = 10;
            var expectedIndexEntries   = Enumerable.Range(0, expectedAllocations).ToArray();
            var actualIndexEntries     = new List <int>();
            var indexPool = new IndexPool(defaultExpansionAmount, originalSize);

            for (var i = 0; i < expectedAllocations; i++)
            {
                var index = indexPool.AllocateInstance();
                actualIndexEntries.Add(index);
            }

            Assert.Equal(0, indexPool.AvailableIndexes.Count);
            Assert.Equal(expectedAllocations, actualIndexEntries.Count);
            Assert.All(indexPool.AvailableIndexes, x => expectedIndexEntries.Contains(x));
        }