Ejemplo n.º 1
0
        public void SetNoStaleDuration_RemovesTimestamps()
        {
            //  setup
            PPool.Clear(prefab);

            //  arrange
            List <GameObject> list     = new List <GameObject>();
            float             duration = 0; //  seconds
            int count = 9;

            //  act (create objects with timestamps)
            PPool.SetLimit(prefab, staleDuration: duration);
            for (int i = 0; i < count; i++)
            {
                list.Add(PPool.Get(prefab));
            }
            for (int i = 0; i < count; i++)
            {
                PPool.Put(list[i]);
            }
            list.Clear();

            //  act (remove timestamps)
            PPool.SetLimit(prefab, staleDuration: PPool.UNLIMITED);
            int available = PPool.GetAvailable(prefab);

            //  assert
            Assert.AreEqual(count, available, "Wrong number available");
        }
Ejemplo n.º 2
0
        public void Clear_DestroysAllObjects()
        {
            //  setup
            PPool.Clear(prefab);

            //  arrange
            List <GameObject> list = new List <GameObject>();
            int count = 9;

            //  act
            for (int i = 0; i < count; i++)
            {
                GameObject g = PPool.Get(prefab);
                if (g != null)
                {
                    list.Add(g);
                }
            }
            for (int i = 0; i < count; i++)
            {
                PPool.Put(list[0]);
            }
            PPool.Clear(prefab);
            int total = PPool.GetAvailable(prefab) + PPool.GetInUse(prefab);

            //  assert
            Assert.AreEqual(0, total, "Pool contains objects");
        }
Ejemplo n.º 3
0
        public void Expire_ReducesObjectCount()
        {
            //  setup
            PPool.Clear(prefab);

            //  arrange
            float             shortStale = 0;
            int               count      = 7;
            List <GameObject> list       = new List <GameObject>();

            PPool.SetLimit(prefab, staleDuration: shortStale);
            for (int i = 0; i < count; i++)
            {
                list.Add(PPool.Get(prefab));
            }
            for (int i = 0; i < count; i++)
            {
                PPool.Put(list[i]);
            }
            list.Clear();

            //  act
            PPool.Expire(prefab, true);
            int available = PPool.GetAvailable(prefab);

            //  assert
            Assert.AreEqual(0, available, "Pool did not expire unused objects");
        }
Ejemplo n.º 4
0
        public void Cull_ReducesObjectCount()
        {
            //  setup
            PPool.Clear(prefab);

            //  arrange
            int count              = 9;
            int reduced            = count - 1;
            List <GameObject> list = new List <GameObject>();

            for (int i = 0; i < count; i++)
            {
                list.Add(PPool.Get(prefab));
            }
            for (int i = 0; i < count; i++)
            {
                PPool.Put(list[0]);
            }
            list.Clear();

            //  act
            PPool.SetLimit(prefab, poolSize: reduced);
            int available = PPool.GetAvailable(prefab);

            //  assert
            Assert.AreEqual(reduced, available, "Available objects does not match expected count");
        }
Ejemplo n.º 5
0
        public void GetAvailable_IndicatesUnusedQuantity()
        {
            //  setup
            PPool.Clear(prefab);

            //  arrange
            int count = 3;

            GameObject[] gos = new GameObject[count];

            //  act
            for (int i = 0; i < count; i++)
            {
                gos[i] = PPool.Get(prefab);
            }
            int resultForEmpty = PPool.GetAvailable(prefab);

            for (int i = 0; i < count; i++)
            {
                PPool.Put(gos[i]);
            }
            int resultForReclaimed = PPool.GetAvailable(prefab);

            //  assert
            Assert.AreEqual(0, resultForEmpty, "Pool not empty");
            Assert.AreEqual(count, resultForReclaimed, "Pool missing reclaimed objects");
        }
Ejemplo n.º 6
0
        public void Prewarm_CreatesObjects()
        {
            //  setup
            PPool.Clear(prefab);

            //  arrange
            int   count    = 8;
            float duration = 0; //  second

            //  act
            PPool.Prewarm(prefab, count, duration);
            int complete = PPool.GetAvailable(prefab);

            //  assert
            Assert.AreEqual(count, complete, "Contains wrong number of objects");
        }
Ejemplo n.º 7
0
        public void Put_ReturnsObjectToPool()
        {
            //  setup
            PPool.Clear(prefab);

            //  arrange
            GameObject instance  = PPool.Get(prefab);
            int        available = PPool.GetAvailable(prefab);

            ////  act
            bool putResult = PPool.Put(instance);
            int  result    = PPool.GetAvailable(prefab);

            //  assert
            Assert.IsTrue(putResult, "Pool indicated object was destroyed");
            Assert.AreEqual(0, available, "Should be no available objects");
            Assert.AreEqual(1, result, "Should be one available object");
        }
Ejemplo n.º 8
0
        public void SetLimit_AssignsPersistenceLimit()
        {
            //  setup
            PPool.Clear(prefab);

            //  arrange
            float duration = 0;

            PPool.SetLimit(prefab, staleDuration: duration);

            //  act
            GameObject instance  = PPool.Get(prefab);
            bool       putResult = PPool.Put(instance);

            Delay(duration + 1);
            PPool.Expire(prefab);
            Delay(duration + 1);
            int available = PPool.GetAvailable(prefab);

            //  assert
            Assert.IsTrue(putResult, "Pool indicates item was destroyed");
            Assert.AreEqual(0, available, "Pool kept objects past expiration");
        }