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"); }
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"); }
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"); }
private void Update() { if (createPrefab) { createPrefab = false; prefab = GameObject.CreatePrimitive(PrimitiveType.Cube); prefab.name = "prefab"; PPool.SetLimit(prefab, staleDuration: 2); } if (getItems) { getItems = false; list = new List <GameObject>(); for (int i = 0; i < count; i++) { list.Add(PPool.Get(prefab)); } } if (putItems) { putItems = false; for (int i = 0; i < count; i++) { PPool.Put(list[i]); } list.Clear(); } if (expirePool) { expirePool = false; PPool.Expire(prefab); } if (prewarm) { prewarm = false; PPool.Prewarm(prefab, count, 4); } }
public void SetLimit_AssignsCreationLimit() { // setup PPool.Clear(prefab); // arrange int limit = 3; PPool.SetLimit(prefab, poolSize: limit); // act GameObject[] g = new GameObject[limit + 1]; for (int i = 0; i < limit + 1; i++) { g[i] = PPool.Get(prefab); } // assert Assert.IsNull(g[limit], "Pool created objects in excess of assigned limit"); }
public void SetNoQuantityLimit_RemovesLimit() { // setup PPool.Clear(prefab); // arrange int count = 9; int limit = count - 1; List <GameObject> list = new List <GameObject>(); // act PPool.SetLimit(prefab, poolSize: limit); for (int i = 0; i < count; i++) { GameObject g = PPool.Get(prefab); if (g != null) { list.Add(g); } } int createdWhileLimted = list.Count; int countWhileLimited = PPool.GetInUse(prefab); PPool.SetLimit(prefab, poolSize: PPool.UNLIMITED); for (int i = 0; i < count; i++) { GameObject g = PPool.Get(prefab); if (g != null) { list.Add(g); } } int createUnlimited = list.Count; int countUnlimited = PPool.GetInUse(prefab); // assert Assert.AreEqual(limit, createdWhileLimted, "Wrong number created while limited"); Assert.AreEqual(limit, countWhileLimited, "Pool reports wrong amount created while limited"); Assert.AreEqual(limit + count, createUnlimited, "Unlimited object creation count incorrect"); Assert.AreEqual(limit + count, countUnlimited, "Pool reports wrong amount created while unlimited"); }
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"); }
public void Get_ReturnsNullWhenAtMaxLimit() { // setup PPool.Clear(prefab); // arrange int count = 9; List <GameObject> g = new List <GameObject>(); PPool.SetLimit(prefab, poolSize: count); // act for (int i = 0; i < count + 1; i++) { GameObject go = PPool.Get(prefab); if (go) { g.Add(go); } } // assert Assert.AreEqual(count, g.Count, "Pool created wrong number of objects"); }