Пример #1
0
        public void Recylcing_2_object_10_times_should_not_create_more_than_2_objects()
        {
            var car  = new MockPoolObject();
            var pool = new GameObjectPool
            {
                poolableObject = car
            };

            pool.AddObjectsToPool(2);

            var poolObjects = new Dictionary <string, ICanBePooled>();

            for (int i = 0; i < 10; i++)
            {
                var carInPool = pool.LockObjectForRecycling();
                Assert.IsTrue(carInPool.IsActive);
                pool.DeactivateObject(carInPool);
                Assert.IsFalse(carInPool.IsActive);

                if (poolObjects.ContainsKey(carInPool.Name))
                {
                    continue;
                }

                poolObjects.Add(carInPool.Name, carInPool);

                Assert.IsTrue(poolObjects.Count <= 2);
            }
        }
Пример #2
0
        public void Deactivating_inactive_object_shouldnt_change_state()
        {
            var car  = new MockPoolObject();
            var pool = new GameObjectPool
            {
                poolableObject = car
            };

            pool.AddObjectsToPool(1);

            var carInPool = pool.LockObjectForRecycling();

            Assert.IsTrue(carInPool.IsActive);
            pool.DeactivateObject(carInPool);
            Assert.IsFalse(carInPool.IsActive);
            pool.DeactivateObject(carInPool);
            Assert.IsFalse(carInPool.IsActive);
        }
Пример #3
0
        public void Recylcing_one_object_10_times_should_pass()
        {
            var car  = new MockPoolObject();
            var pool = new GameObjectPool
            {
                poolableObject = car
            };

            pool.AddObjectsToPool(1);

            for (int i = 0; i < 10; i++)
            {
                var carInPool = pool.LockObjectForRecycling();
                Assert.IsTrue(carInPool.IsActive);
                pool.DeactivateObject(carInPool);
                Assert.IsFalse(carInPool.IsActive);
            }
        }