Esempio n. 1
0
        public static void RelenquishedPoolItemsAreMovedToFrontOfPoolInstanceList(int rand)
        {
            PoolBase pool = new DemoPool();
            List <DemoPooledObjectInstance> _instances = new List <DemoPooledObjectInstance>();

            // Spawn instances
            for (int i = 0; i < 200; i++)
            {
                _instances.Add((DemoPooledObjectInstance)pool.GetNext());
            }

            Random r      = new Random(rand);
            int    rCount = 0;

            for (int i = 0; i < _instances.Count; i++)
            {
                if (r.NextDouble() > 0.5)
                {
                    rCount++;
                    _instances[i].RelenquishFromInstance();
                }
            }

            Assert.True(pool.InternalValidatePoolInstanceLayout(rCount),
                        "Pool is not arranging available instances at front of instance list!");
        }
        public static void PoolDoesCreateObjects(int spawnCount)
        {
            IPool pool = new DemoPool();

            for (int i = 0; i < spawnCount; i++)
            {
                pool.GetNext();
            }

            Assert.AreEqual(spawnCount, pool.instanceCount,
                            "Pool is not spawning instances correctly!");
        }
Esempio n. 3
0
        public static void PoolDoesEnforceRecyclingAfterMaxCapacityReached(int poolMaxCapacity, int activationCount)
        {
            IPool pool = new DemoPool();

            pool.capacityMax = poolMaxCapacity;
            for (int i = 0; i < activationCount; i++)
            {
                pool.GetNext();
            }

            Assert.LessOrEqual(pool.instanceCount, poolMaxCapacity,
                               "Pool is failing to recycle after maximum instance capacity is reached!");
        }
Esempio n. 4
0
        public static void PoolDoesDeleteOverflowInstancesAfterMaxCapacityExceeded(int poolMaxCapacity)
        {
            IPool pool = new DemoPool();

            pool.capacityMax = poolMaxCapacity * 2;
            for (int i = 0; i < pool.capacityMax; i++)
            {
                pool.GetNext();
            }

            // Set pool max to a lower number; this should force the pool to delete objects
            pool.capacityMax = poolMaxCapacity;

            Assert.LessOrEqual(pool.instanceCount, poolMaxCapacity,
                               "Pool is failing to destroy overflow instances after max capacity is exceeded!");
        }
Esempio n. 5
0
        public static void PoolsCanRelenquishAndReClaimInstances(int spawnNum, int relenquishCount)
        {
            IPool pool = new DemoPool();
            List <DemoPooledObjectInstance> _instances = new List <DemoPooledObjectInstance>();

            // Spawn instances
            for (int i = 0; i < spawnNum; i++)
            {
                _instances.Add((DemoPooledObjectInstance)pool.GetNext());
            }

            // Delete instances
            for (int i = 0; i < Math.Min(relenquishCount, _instances.Count); i++)
            {
                _instances[i].RelenquishFromInstance();
            }

            Assert.AreEqual(Math.Max(spawnNum - relenquishCount, 0), pool.activeCount,
                            "Pooled instances are not being read as relenquished!");
        }
Esempio n. 6
0
        public static void PoolRemoveFromInstanceDoesFunction(int spawnNum, int removeCount)
        {
            IPool pool = new DemoPool();
            List <DemoPooledObjectInstance> _instances = new List <DemoPooledObjectInstance>();

            // Spawn instances
            for (int i = 0; i < spawnNum; i++)
            {
                _instances.Add((DemoPooledObjectInstance)pool.GetNext());
            }

            // Delete instances
            for (int i = 0; i < Math.Min(removeCount, _instances.Count); i++)
            {
                _instances[i].DeleteObjectInstance();
            }

            Assert.AreEqual(Math.Max(spawnNum - removeCount, 0), pool.instanceCount,
                            "Pools are not properly removing instances when the removal command comes from the instance!");
        }
        public static void PoolDoesRecycleObjects(int poolMaxCapacity, int spawnCount)
        {
            IPool pool = new DemoPool();

            pool.capacityMax = poolMaxCapacity;

            for (int i = 0; i < spawnCount; i++)
            {
                pool.GetNext();
            }

            int equalTarg = spawnCount;

            if (poolMaxCapacity > 0 && poolMaxCapacity < spawnCount)
            {
                equalTarg = poolMaxCapacity;
            }

            Assert.AreEqual(equalTarg, pool.instanceCount,
                            "Pool is not properly recycling instances!");
        }
Esempio n. 8
0
        public static void PoolCleanDoesRemoveAvailableInstances(int spawnCount, int deactivateCount)
        {
            IPool pool = new DemoPool();
            List <DemoPooledObjectInstance> _instances = new List <DemoPooledObjectInstance>();

            // Spawn instances
            for (int i = 0; i < spawnCount; i++)
            {
                _instances.Add((DemoPooledObjectInstance)pool.GetNext());
            }

            // Deactivate instances
            for (int i = 0; i < Math.Min(deactivateCount, _instances.Count); i++)
            {
                _instances[i].RelenquishFromInstance();
            }

            // Clean pool
            pool.Clean();

            Assert.AreEqual(Math.Max(spawnCount - deactivateCount, 0), pool.instanceCount,
                            "Pool cleaning does not remove unused instances as expected!");
        }