public void CapacityChanged() { DebugGood1 good = new DebugGood1(100, 0); int count = 0; int expected = 0; good.OnCapacityChanged += (g, v) => { Assert.AreEqual(good, g); Assert.AreEqual(expected, v); count++; }; // Normal Value expected = 100; good.Capacity = 100; Assert.AreEqual(1, count); count = 0; // Oversized Value expected = int.MaxValue; good.Capacity = int.MaxValue; Assert.AreEqual(1, count); count = 0; // Negative Value expected = 0; good.Capacity = -100; Assert.AreEqual(1, count); count = 0; }
public void CollectorGoodsChanged() { InitCollectorItem(Pos); DebugGood1 good1 = new DebugGood1(100, 0); DebugGood2 good2 = new DebugGood2(100, 0); int newGoodCount = 0; int lostGoodCount = 0; Collector.OnNewCollectableGood += (g, v) => { newGoodCount++; }; Collector.OnLostCollectableGood += (g, v) => { lostGoodCount++; }; // Check Init Assert.AreEqual(0, Collector.CollectableGoods.Count()); Assert.AreEqual(false, Collector.ContainsGood<DebugGood1>()); Assert.AreEqual(false, Collector.ContainsGood<DebugGood2>()); Assert.AreEqual(null, Collector.GetCollectableGood<DebugGood1>()); Assert.AreEqual(null, Collector.GetCollectableGood<DebugGood2>()); Assert.AreEqual(0, newGoodCount); Assert.AreEqual(0, lostGoodCount); newGoodCount = lostGoodCount = 0; // Insert Good1 Collector.AddCollectableGood(good1); Assert.AreEqual(1, Collector.CollectableGoods.Count()); Assert.AreEqual(true, Collector.ContainsGood<DebugGood1>()); Assert.AreEqual(false, Collector.ContainsGood<DebugGood2>()); Assert.AreEqual(good1, Collector.GetCollectableGood<DebugGood1>()); Assert.AreEqual(null, Collector.GetCollectableGood<DebugGood2>()); Assert.AreEqual(1, newGoodCount); Assert.AreEqual(0, lostGoodCount); newGoodCount = lostGoodCount = 0; // Insert Good1 again try { Collector.AddCollectableGood(good1); throw new Exception("Should throw an Exception"); } catch (InvalidOperationException) { } Assert.AreEqual(1, Collector.CollectableGoods.Count()); Assert.AreEqual(true, Collector.ContainsGood<DebugGood1>()); Assert.AreEqual(false, Collector.ContainsGood<DebugGood2>()); Assert.AreEqual(good1, Collector.GetCollectableGood<DebugGood1>()); Assert.AreEqual(null, Collector.GetCollectableGood<DebugGood2>()); Assert.AreEqual(0, newGoodCount); Assert.AreEqual(0, lostGoodCount); newGoodCount = lostGoodCount = 0; // Insert another instance of Good1 DebugGood1 good12 = new DebugGood1(100, 0); try { Collector.AddCollectableGood(good12); throw new Exception("Should throw an Exception"); } catch (InvalidOperationException) { } Assert.AreEqual(1, Collector.CollectableGoods.Count()); Assert.AreEqual(true, Collector.ContainsGood<DebugGood1>()); Assert.AreEqual(false, Collector.ContainsGood<DebugGood2>()); Assert.AreEqual(good1, Collector.GetCollectableGood<DebugGood1>()); Assert.AreEqual(null, Collector.GetCollectableGood<DebugGood2>()); Assert.AreEqual(0, newGoodCount); Assert.AreEqual(0, lostGoodCount); newGoodCount = lostGoodCount = 0; // Insert an instance of good2 Collector.AddCollectableGood(good2); Assert.AreEqual(2, Collector.CollectableGoods.Count()); Assert.AreEqual(true, Collector.ContainsGood<DebugGood1>()); Assert.AreEqual(true, Collector.ContainsGood<DebugGood2>()); Assert.AreEqual(good1, Collector.GetCollectableGood<DebugGood1>()); Assert.AreEqual(good2, Collector.GetCollectableGood<DebugGood2>()); Assert.AreEqual(1, newGoodCount); Assert.AreEqual(0, lostGoodCount); newGoodCount = lostGoodCount = 0; // Remove Good1 Collector.RemoveCollectableGood<DebugGood1>(); Assert.AreEqual(1, Collector.CollectableGoods.Count()); Assert.AreEqual(false, Collector.ContainsGood<DebugGood1>()); Assert.AreEqual(true, Collector.ContainsGood<DebugGood2>()); Assert.AreEqual(null, Collector.GetCollectableGood<DebugGood1>()); Assert.AreEqual(good2, Collector.GetCollectableGood<DebugGood2>()); Assert.AreEqual(0, newGoodCount); Assert.AreEqual(1, lostGoodCount); newGoodCount = lostGoodCount = 0; // Remove Good2 Collector.RemoveCollectableGood<DebugGood2>(); Assert.AreEqual(0, Collector.CollectableGoods.Count()); Assert.AreEqual(false, Collector.ContainsGood<DebugGood1>()); Assert.AreEqual(false, Collector.ContainsGood<DebugGood2>()); Assert.AreEqual(null, Collector.GetCollectableGood<DebugGood1>()); Assert.AreEqual(null, Collector.GetCollectableGood<DebugGood2>()); Assert.AreEqual(0, newGoodCount); Assert.AreEqual(1, lostGoodCount); newGoodCount = lostGoodCount = 0; }
public void AmountCapacityInteraction() { DebugGood1 good = new DebugGood1(100, 0); good.Capacity = int.MaxValue; int amountCount = 0; int capacityCount = 0; int amountExpected = 0; int capacityExcepted = 0; good.OnAmountChanged += (g, v) => { Assert.AreEqual(good, g); Assert.AreEqual(amountExpected, v); amountCount++; }; good.OnCapacityChanged += (g, v) => { Assert.AreEqual(good, g); Assert.AreEqual(capacityExcepted, v); capacityCount++; }; // Initialwert Value capacityExcepted = 0; amountExpected = 0; good.Amount = 0; good.Capacity = 0; Assert.AreEqual(1, amountCount); Assert.AreEqual(1, capacityCount); Assert.AreEqual(amountExpected, good.Amount); Assert.AreEqual(capacityExcepted, good.Capacity); amountCount = capacityCount = 0; // raise Capacity (to 100) capacityExcepted = 100; amountExpected = 0; good.Capacity = 100; Assert.AreEqual(0, amountCount); Assert.AreEqual(1, capacityCount); Assert.AreEqual(amountExpected, good.Amount); Assert.AreEqual(capacityExcepted, good.Capacity); amountCount = capacityCount = 0; // raise Amount within range (50) capacityExcepted = 100; amountExpected = 50; good.Amount = 50; Assert.AreEqual(1, amountCount); Assert.AreEqual(0, capacityCount); Assert.AreEqual(amountExpected, good.Amount); Assert.AreEqual(capacityExcepted, good.Capacity); amountCount = capacityCount = 0; // raise Amount to range (100) capacityExcepted = 100; amountExpected = 100; good.Amount = 100; Assert.AreEqual(1, amountCount); Assert.AreEqual(0, capacityCount); Assert.AreEqual(amountExpected, good.Amount); Assert.AreEqual(capacityExcepted, good.Capacity); amountCount = capacityCount = 0; // raise Amount over range (150) capacityExcepted = 100; amountExpected = 100; good.Amount = 150; Assert.AreEqual(1, amountCount); Assert.AreEqual(0, capacityCount); Assert.AreEqual(amountExpected, good.Amount); Assert.AreEqual(capacityExcepted, good.Capacity); amountCount = capacityCount = 0; // raise Capacity (to 150) capacityExcepted = 150; amountExpected = 100; good.Capacity = 150; Assert.AreEqual(0, amountCount); Assert.AreEqual(1, capacityCount); Assert.AreEqual(amountExpected, good.Amount); Assert.AreEqual(capacityExcepted, good.Capacity); amountCount = capacityCount = 0; // lower capacity (to 50) capacityExcepted = 50; amountExpected = 50; good.Capacity = 50; Assert.AreEqual(1, amountCount); Assert.AreEqual(1, capacityCount); Assert.AreEqual(amountExpected, good.Amount); Assert.AreEqual(capacityExcepted, good.Capacity); amountCount = capacityCount = 0; // lower Amount to Zero capacityExcepted = 50; amountExpected = 0; good.Amount = 0; Assert.AreEqual(1, amountCount); Assert.AreEqual(0, capacityCount); Assert.AreEqual(amountExpected, good.Amount); Assert.AreEqual(capacityExcepted, good.Capacity); amountCount = capacityCount = 0; // lower Capacity to Zero capacityExcepted = 0; amountExpected = 0; good.Capacity = 0; Assert.AreEqual(0, amountCount); Assert.AreEqual(1, capacityCount); Assert.AreEqual(amountExpected, good.Amount); Assert.AreEqual(capacityExcepted, good.Capacity); amountCount = capacityCount = 0; }
public void CollectableRangeCheck() { InitCollectorItem(new Vector2(50, 100)); InitCollectableItem(new Vector2(150, 100)); DebugGood1 collectableGood = new DebugGood1(200, 200); Assert.AreEqual(null, collectableGood.Property); Collectable.CollectableRadius = 20; Collectable.AddCollectableGood(collectableGood); Assert.AreEqual(Collectable, collectableGood.Property); DebugGood1 collectorGood = new DebugGood1(100, 0); Collector.CollectorRange = 20; Collector.AddCollectableGood(collectorGood); int result = 0; // Collect from out of range result = Collector.Collect<DebugGood1>(Collectable, 10); Assert.AreEqual(0, result); Assert.AreEqual(200, collectableGood.Amount); Assert.AreEqual(0, collectorGood.Amount); // Collect within range Collector.Item.Position = new Vector3(110, 100, 0); result = Collector.Collect<DebugGood1>(Collectable, 10); Assert.AreEqual(10, result); Assert.AreEqual(190, collectableGood.Amount); Assert.AreEqual(10, collectorGood.Amount); // Collect too much result = Collector.Collect<DebugGood1>(Collectable, 100); Assert.AreEqual(90, result); Assert.AreEqual(100, collectableGood.Amount); Assert.AreEqual(100, collectorGood.Amount); // Give something result = Collector.Give<DebugGood1>(Collectable, 20); Assert.AreEqual(20, result); Assert.AreEqual(120, collectableGood.Amount); Assert.AreEqual(80, collectorGood.Amount); // Give too much (less than available) result = Collector.Give<DebugGood1>(Collectable, 200); Assert.AreEqual(80, result); Assert.AreEqual(200, collectableGood.Amount); Assert.AreEqual(0, collectorGood.Amount); // Give too much (more than acceptable) collectorGood.Capacity = 200; collectorGood.Amount = 200; collectableGood.Amount = 150; result = Collector.Give<DebugGood1>(Collectable, 200); Assert.AreEqual(50, result); Assert.AreEqual(200, collectableGood.Amount); Assert.AreEqual(150, collectorGood.Amount); // Give from out of range Collector.Item.Position = new Vector3(50, 100, 0); collectableGood.Amount = 100; result = Collector.Give<DebugGood1>(Collectable, 10); Assert.AreEqual(0, result); Assert.AreEqual(100, collectableGood.Amount); Assert.AreEqual(150, collectorGood.Amount); }