public void ClearActive_ClearsWorkPairings() { ProductionBaySlot slot = new ProductionBaySlot( new RegeneratingBank { Maximum = 1000, Quantity = 0 }, new RegeneratingBank { Maximum = 100, Quantity = 20 }, null, 0) { Active = MetalRecipe }; // Use reflection to read and write to a private value var field = typeof(ProductionBaySlot) .GetField("WorkPairings", BindingFlags.NonPublic | BindingFlags.Instance); // Give it a "valid" value field.SetValue(slot, new Dictionary <Citizen, Ingredient <Resource> > { { new Citizen(), ScrapIng } }); // Clear it slot.ClearActive( ); // See what happened Dictionary <Citizen, Ingredient <Resource> > pairs = field.GetValue(slot) as Dictionary <Citizen, Ingredient <Resource> >; Assert.IsTrue(pairs == null || pairs.Keys.Count == 0, "Pairs was neither empty or null"); }
public void ManageWorkers_GivesLowEnergyWorkersRest() { ProductionBaySlot slot = new ProductionBaySlot(null, null, null, 100, new List <Citizen> { new Citizen { Energy = new Bank { Maximum = 100, Quantity = 4 } }, new Citizen { Energy = new Bank { Maximum = 100, Quantity = 80 } } }); var WorkPairingsAccessor = typeof(ProductionBaySlot) .GetField("WorkPairings", BindingFlags.NonPublic | BindingFlags.Instance); WorkPairingsAccessor.SetValue(slot, new Dictionary <Citizen, Ingredient <Resource> > { { slot.Workers[0], ScrapIng }, { slot.Workers[1], ScrapIng } }); slot.ManageWorkers( ); int pairCount = (WorkPairingsAccessor.GetValue(slot) as Dictionary <Citizen, Ingredient <Resource> >).Count; Assert.IsTrue(pairCount == 1, $"Expected only 1 workpairing, actual {pairCount}"); }
public void ActivateRecipeRec_CallsClearActiveWhenNotNull() { ProductionBaySlot slot = new ProductionBaySlot( new RegeneratingBank { Maximum = 1000, Quantity = 0 }, new RegeneratingBank { Maximum = 100, Quantity = 20 }, null, 0) { Active = new Recipe <Resource, Resource>(MetalRecipe) }; var field = typeof(ProductionBaySlot) .GetField("WorkPairings", BindingFlags.NonPublic | BindingFlags.Instance); field.SetValue(slot, new Dictionary <Citizen, Ingredient <Resource> > { { new Citizen(), ScrapIng } }); slot.ActivateRecipe(MetalRecipe); Dictionary <Citizen, Ingredient <Resource> > pairs = field.GetValue(slot) as Dictionary <Citizen, Ingredient <Resource> >; Assert.IsTrue(pairs == null || pairs.Keys.Count == 0, "Did not clear workpairings, must not have called ClearActive"); }
public void ExpendIngredient_ErrorsIfLackingMaterials() { ProductionBaySlot slot = new ProductionBaySlot(null, null, new ResourceBank(200, new List <Quantified <Resource> > { new Quantified <Resource>(Scrap, 3) }), 0); Assert.ThrowsException <LackingResourceException>(() => slot.ExpendIngredient(ScrapIng)); }
public void ExpendIngredient_Works() { ProductionBaySlot slot = new ProductionBaySlot(null, null, new ResourceBank(200, new List <Quantified <Resource> > { new Quantified <Resource>(Scrap, 20) }), 0); slot.ExpendIngredient(ScrapIng); Assert.IsTrue(slot.Resources[Scrap] == 16, $"Expected 16, instead have {slot.Resources[Scrap].Quantity}"); }
public void ExpendIngredient_CallsOnLackingInsteadOfError() { ProductionBaySlot slot = new ProductionBaySlot(null, null, new ResourceBank(200, new List <Quantified <Resource> > { new Quantified <Resource>(Scrap, 3) }), 0); bool works = false; slot.ExpendIngredient(ScrapIng, () => works = true); Assert.IsTrue(works, "Did not call action"); }
public void ExpendEnergy_TakesFromPoolFirst() { ProductionBaySlot slot = new ProductionBaySlot( new RegeneratingBank { Maximum = 1000, Quantity = 8 }, new RegeneratingBank { Maximum = 10, Quantity = 10 }, null, 0); slot.ExpendEnergy(10, () => Assert.Fail("Should not error.")); }
public void ExpendEnergy_ErrorsIfNotEnoughEnergy() { ProductionBaySlot slot = new ProductionBaySlot( new RegeneratingBank { Maximum = 1000, Quantity = 0 }, new RegeneratingBank { Maximum = 100, Quantity = 20 }, null, 0); Assert.ThrowsException <NotEnoughEnergyException>(() => slot.ExpendEnergy(1000)); }
public void ExpendEnergy_TakesFromReserveIfPoolEmpty() { ProductionBaySlot slot = new ProductionBaySlot( new RegeneratingBank { Maximum = 1000, Quantity = 0 }, new RegeneratingBank { Maximum = 100, Quantity = 20 }, null, 0); slot.ExpendEnergy(10); Assert.IsTrue(slot.Reserve == 10, $"Expected slot.Reserve to be 10, actually {slot.Reserve}"); }
public void ManageWorkers_OnlyGivesQualifiedWorkersAJob() { var slot = new ProductionBaySlot( new RegeneratingBank { Maximum = 1000, Quantity = 1000 }, new RegeneratingBank { Maximum = 1000, Quantity = 1000 }, new ResourceBank(100), 10); slot.Resources.Add(Scrap, 1000); for (int i = 0; i < 4; i++) { slot.AddWorker(new Citizen { Energy = new Bank { Quantity = 10000, Maximum = 10000, } }); } slot.AddWorker(new Citizen { Skills = new List <Skill> { MetalWork }, Energy = new Bank { Quantity = 10000, Maximum = 10000, } }); slot.ActivateRecipe(MetalRecipe_WithSkillReq); while (!slot.Resources.Contains(Metal)) { slot.Think( ); } for (int i = 0; i < 4; i++) { Assert.IsTrue(slot.Workers[i].Energy.IsFull, $"Took energy from worker {i}"); } Assert.IsFalse(slot.Workers[4].Energy.IsFull, "Worker 5 has full energy and should not."); }
public void FinishRecipe_ErrorsOnIncompleteActive() { ProductionBaySlot slot = new ProductionBaySlot( new RegeneratingBank { Maximum = 1000, Quantity = 0 }, new RegeneratingBank { Maximum = 100, Quantity = 20 }, new ResourceBank(100), 0) { Active = new Recipe <Resource, Resource>(MetalRecipe) }; Assert.ThrowsException <NotYetCompletedException>(() => slot.FinishRecipe( )); }
public void ActivateRecipeRec_Activates() { ProductionBaySlot slot = new ProductionBaySlot( new RegeneratingBank { Maximum = 1000, Quantity = 0 }, new RegeneratingBank { Maximum = 100, Quantity = 20 }, null, 0) { }; slot.ActivateRecipe(MetalRecipe); Assert.IsNotNull(slot.Active, "Active was not set"); }
public void ClearActive_ClearsActive() { ProductionBaySlot slot = new ProductionBaySlot( new RegeneratingBank { Maximum = 1000, Quantity = 0 }, new RegeneratingBank { Maximum = 100, Quantity = 20 }, null, 0) { Active = MetalRecipe }; slot.ClearActive( ); Assert.IsTrue(slot.Active == null); }
public void FinishRecipe_CallsClearActiveWhenComplete() { ProductionBaySlot slot = new ProductionBaySlot( new RegeneratingBank { Maximum = 1000, Quantity = 0 }, new RegeneratingBank { Maximum = 100, Quantity = 20 }, new ResourceBank(100), 0) { Active = new Recipe <Resource, Resource>(MetalRecipe) }; slot.Active.Ingredients.ForEach(ing => ing.Progress.Quantity = ing.Progress.Maximum); slot.FinishRecipe( ); Assert.IsTrue(slot.Active == null, "Active is not null, must not have cleared"); }
public void FinishRecipe_CreatesCorrectAmountOnComplete() { ProductionBaySlot slot = new ProductionBaySlot( new RegeneratingBank { Maximum = 1000, Quantity = 0 }, new RegeneratingBank { Maximum = 100, Quantity = 20 }, new ResourceBank(100), 0) { Active = new Recipe <Resource, Resource>(MetalRecipe) }; slot.Active.Ingredients.ForEach(ing => ing.Progress.Quantity = ing.Progress.Maximum); slot.FinishRecipe( ); Assert.IsTrue(slot.Resources[0].Quantity == 1, $"Produced too many. Expected 1, actual {slot.Resources[0].Quantity}"); }
public void ActivateRecipeN_RemovesNFromLineup() { ProductionBaySlot slot = new ProductionBaySlot( new RegeneratingBank { Maximum = 1000, Quantity = 0 }, new RegeneratingBank { Maximum = 100, Quantity = 20 }, null, 0) { Lineup = new List <Recipe <Resource, Resource> > { new Recipe <Resource, Resource>(MetalRecipe) } }; slot.ActivateRecipe(0); Assert.IsTrue(slot.Lineup.Count == 0, $"Expected the lineup to be empty, size is {slot.Lineup.Count}"); }
public void FinishRecipe_AddsCorrectAmountOnComplete() { ProductionBaySlot slot = new ProductionBaySlot( new RegeneratingBank { Maximum = 1000, Quantity = 0 }, new RegeneratingBank { Maximum = 100, Quantity = 20 }, new ResourceBank(100, new List <Quantified <Resource> > { new Quantified <Resource>(Metal, 1) }), 0) { Active = new Recipe <Resource, Resource>(MetalRecipe) }; slot.Active.Ingredients.ForEach(ing => ing.Progress.Quantity = ing.Progress.Maximum); slot.FinishRecipe( ); Assert.IsTrue(slot.Resources[Metal].Quantity > 1, $"Expected 1, actually {slot.Resources[Metal].Quantity}"); }
public void ManageWorkers_GivesRefreshedWorkersAJob() { ProductionBaySlot slot = new ProductionBaySlot(null, null, null, new List <Citizen> { new Citizen { Energy = new Bank { Maximum = 100, Quantity = 80 } }, new Citizen { Energy = new Bank { Maximum = 100, Quantity = 80 } } }); slot.ManageWorkers( ); var WorkPairingsAccessor = typeof(ProductionBaySlot) .GetField("WorkPairings", BindingFlags.NonPublic | BindingFlags.Instance); var pairCount = (WorkPairingsAccessor.GetValue(slot) as Dictionary <Citizen, Ingredient <Resource> >).Count; Assert.IsTrue(pairCount == 2, $"Expected 2 workpairings, actual {pairCount}"); }
public void FinishRecipe_CreatesNewResourceOnComplete() { ProductionBaySlot slot = new ProductionBaySlot( new RegeneratingBank { Maximum = 1000, Quantity = 0 }, new RegeneratingBank { Maximum = 100, Quantity = 20 }, new ResourceBank(100), 0) { Active = new Recipe <Resource, Resource>(MetalRecipe) }; slot.Active.Ingredients.ForEach(ing => ing.Progress.Quantity = ing.Progress.Maximum); slot.FinishRecipe( () => { Assert.Fail($"Not yet completed: {slot.Active.Progress.IsFull.ToString( )}"); }); Assert.IsTrue(slot.Resources.Contents.Count > 0, "Was expecting something to be added to the resources."); }