public void Expand(int amountToAdd) { var newCount = Components.Length + amountToAdd; var newEntries = new T[newCount]; Components.CopyTo(newEntries, 0); IndexPool.Expand(newCount - 1); Components = newEntries; Count = newCount; _onPoolExtending.OnNext(true); }
public void should_expand_correctly_for_new_indexes() { var explicitNewIndex = 5; var indexPool = new IndexPool(3, 3); indexPool.Expand(explicitNewIndex); Assert.Equal(explicitNewIndex + 1, indexPool.AvailableIndexes.Count); var expectedIdEntries = Enumerable.Range(0, explicitNewIndex + 1).ToArray(); Assert.All(indexPool.AvailableIndexes, x => expectedIdEntries.Contains(x)); }
public void should_expand_correctly_with_auto_expansion() { var defaultExpansionAmount = 30; var originalSize = 10; var expectedSize = defaultExpansionAmount + originalSize; var indexPool = new IndexPool(defaultExpansionAmount, originalSize); indexPool.Expand(); Assert.Equal(indexPool.AvailableIndexes.Count, expectedSize); var expectedIdEntries = Enumerable.Range(1, expectedSize).ToArray(); Assert.All(indexPool.AvailableIndexes, x => expectedIdEntries.Contains(x)); }
public void should_continually_expand_correctly_with_auto_expansion() { var expectedExpansions = 5; var defaultExpansionAmount = 30; var originalSize = 10; var expectedSize = (defaultExpansionAmount * expectedExpansions) + originalSize; var expectedIndexEntries = Enumerable.Range(0, expectedSize).ToArray(); var indexPool = new IndexPool(defaultExpansionAmount, originalSize); for (var i = 0; i < expectedExpansions; i++) { indexPool.Expand(); } Assert.Equal(expectedSize, indexPool.AvailableIndexes.Count); Assert.All(indexPool.AvailableIndexes, x => expectedIndexEntries.Contains(x)); }