public void TestRecycleLater() { TimerManager timerManager = new TimerManager(); ObjectsPool <PoolDummy> pool = new ObjectsPool <PoolDummy>(timerManager); PoolDummy o1 = pool.NextObject(); PoolDummy o2 = pool.NextObject(); PoolDummy o3 = pool.NextObject(); Assert.AreEqual(pool.size, 0); pool.RecycleObjectLater(o1); pool.RecycleObjectLater(o2); pool.RecycleObjectLater(o3); Assert.AreEqual(pool.size, 0); timerManager.Update(0.016f); Assert.AreEqual(pool.size, 3); PoolDummy o4 = pool.NextObject(); PoolDummy o5 = pool.NextObject(); PoolDummy o6 = pool.NextObject(); Assert.AreEqual(pool.size, 0); Assert.AreEqual(o1, o4); Assert.AreEqual(o2, o5); Assert.AreEqual(o3, o6); }
public void TestNextObject2() { TimerManager timerManager = new TimerManager(); ObjectsPool <PoolDummy> pool = new ObjectsPool <PoolDummy>(timerManager); PoolDummy o1 = pool.NextObject(); PoolDummy o2 = pool.NextObject(); PoolDummy o3 = pool.NextObject(); Assert.AreEqual(pool.size, 0); pool.RecycleObject(o1); pool.RecycleObject(o2); Assert.AreEqual(pool.size, 2); PoolDummy o4 = pool.NextObject(); PoolDummy o5 = pool.NextObject(); PoolDummy o6 = pool.NextObject(); Assert.AreEqual(pool.size, 0); Assert.AreEqual(o1, o4); Assert.AreEqual(o2, o5); Assert.AreNotEqual(o3, o6); }