public bool HasPower(PowerRelated powerRelated) { PowerGrid powerGrid; IsPluggedIn(powerRelated, out powerGrid); return(powerGrid != null && powerGrid.IsOperating); }
public void ChargeAccumulatorsTest() { PowerRelated powerProducer = new PowerRelated { OutputRate = 50.0f }; PowerRelated firstPowerConsumer = new PowerRelated { InputRate = 30.0f }; PowerRelated accumulator = new PowerRelated { InputRate = 10.0f, OutputRate = 10.0f, Capacity = 100.0f }; powerGrid.PlugIn(powerProducer); powerGrid.PlugIn(firstPowerConsumer); powerGrid.PlugIn(accumulator); Assert.AreEqual(3, gridHashSet.Count); powerGrid.Update(); Assert.IsTrue(powerGrid.IsOperating); Assert.IsTrue(accumulator.AccumulatedPower.AreEqual(10.0f)); powerGrid.Update(); Assert.IsTrue(powerGrid.IsOperating); Assert.IsTrue(accumulator.AccumulatedPower.AreEqual(20.0f)); powerGrid.Update(); Assert.IsTrue(powerGrid.IsOperating); Assert.IsTrue(accumulator.AccumulatedPower.AreEqual(30.0f)); }
public void IsPluggedInTest() { PowerRelated powerRelated = new PowerRelated(); powerGrid.PlugIn(powerRelated); Assert.AreEqual(1, gridHashSet.Count); Assert.IsTrue(powerGrid.IsPluggedIn(powerRelated)); }
public bool PlugIn(PowerRelated powerRelated, PowerGrid powerGrid) { if (powerRelated == null) { throw new ArgumentNullException("powerRelated"); } return(powerGrid != null && powerGrid.PlugIn(powerRelated)); }
public bool CanPlugIn(PowerRelated powerRelated) { if (powerRelated == null) { throw new ArgumentNullException("powerRelated"); } return(powerGrids.Any(grid => grid.CanPlugIn(powerRelated))); }
public void UnplugTest() { PowerRelated powerRelated = new PowerRelated(); powerGrid.PlugIn(powerRelated); Assert.AreEqual(1, gridHashSet.Count); powerGrid.Unplug(powerRelated); Assert.AreEqual(0, gridHashSet.Count); }
public void Unplug(PowerRelated powerRelated) { if (powerRelated == null) { throw new ArgumentNullException("powerRelated"); } powerGrid.Remove(powerRelated); }
public bool IsPluggedIn(PowerRelated powerRelated) { if (powerRelated == null) { throw new ArgumentNullException("powerRelated"); } return(powerGrid.Contains(powerRelated)); }
public bool CanPlugIn(PowerRelated powerRelated) { if (powerRelated == null) { throw new ArgumentNullException("powerRelated"); } return(true); }
public void DischargeAccumulatorsEnoughPowerTest() { PowerRelated powerProducer = new PowerRelated { OutputRate = 30.0f }; PowerRelated firstPowerConsumer = new PowerRelated { InputRate = 30.0f }; PowerRelated firstAccumulator = new PowerRelated { InputRate = 10.0f, OutputRate = 10.0f, Capacity = 100.0f }; PowerRelated secondAccumulator = new PowerRelated { InputRate = 10.0f, OutputRate = 10.0f, Capacity = 100.0f }; PowerRelated thirdAccumulator = new PowerRelated { InputRate = 10.0f, OutputRate = 10.0f, Capacity = 100.0f }; powerGrid.PlugIn(powerProducer); powerGrid.PlugIn(firstAccumulator); powerGrid.PlugIn(secondAccumulator); powerGrid.PlugIn(thirdAccumulator); Assert.AreEqual(4, gridHashSet.Count); powerGrid.Update(); powerGrid.Update(); powerGrid.Update(); Assert.IsTrue(powerGrid.IsOperating); Assert.IsTrue(firstAccumulator.AccumulatedPower.AreEqual(30.0f)); Assert.IsTrue(secondAccumulator.AccumulatedPower.AreEqual(30.0f)); Assert.IsTrue(thirdAccumulator.AccumulatedPower.AreEqual(30.0f)); powerGrid.PlugIn(firstPowerConsumer); powerGrid.Update(); Assert.IsTrue(powerGrid.IsOperating); Assert.IsTrue(firstAccumulator.AccumulatedPower.AreEqual(30.0f)); Assert.IsTrue(secondAccumulator.AccumulatedPower.AreEqual(30.0f)); Assert.IsTrue(thirdAccumulator.AccumulatedPower.AreEqual(30.0f)); powerGrid.Unplug(powerProducer); powerGrid.Update(); Assert.IsTrue(powerGrid.IsOperating); Assert.IsTrue(firstAccumulator.AccumulatedPower.AreEqual(20.0f)); Assert.IsTrue(secondAccumulator.AccumulatedPower.AreEqual(20.0f)); Assert.IsTrue(thirdAccumulator.AccumulatedPower.AreEqual(20.0f)); powerGrid.Update(); powerGrid.Update(); Assert.IsTrue(powerGrid.IsOperating); Assert.IsTrue(firstAccumulator.IsEmpty); Assert.IsTrue(secondAccumulator.IsEmpty); Assert.IsTrue(thirdAccumulator.IsEmpty); powerGrid.Update(); Assert.IsFalse(powerGrid.IsOperating); }
public void UnplugTest() { PowerRelated powerRelated = new PowerRelated(); Assert.IsTrue(livePowerSystem.PlugIn(powerRelated)); Assert.AreEqual(1, powerGrids.Count); livePowerSystem.Unplug(powerRelated); Assert.AreEqual(1, powerGrids.Count); livePowerSystem.Update(); Assert.AreEqual(0, powerGrids.Count); }
public void IsPluggedInTest() { PowerRelated powerRelated = new PowerRelated(); Assert.IsTrue(livePowerSystem.PlugIn(powerRelated)); Assert.AreEqual(1, powerGrids.Count); PowerGrid powerGrid; Assert.IsTrue(livePowerSystem.IsPluggedIn(powerRelated, out powerGrid)); Assert.IsNotNull(powerGrid); }
public bool PlugIn(PowerRelated powerRelated) { if (powerRelated == null) { throw new ArgumentNullException("powerRelated"); } if (!CanPlugIn(powerRelated)) { return(false); } powerGrid.Add(powerRelated); return(true); }
public void UpdateEnoughPowerTest() { PowerRelated powerProducer = new PowerRelated { OutputRate = 50.0f }; PowerRelated firstPowerConsumer = new PowerRelated { InputRate = 30.0f }; powerGrid.PlugIn(powerProducer); powerGrid.PlugIn(firstPowerConsumer); Assert.AreEqual(2, gridHashSet.Count); powerGrid.Update(); Assert.IsTrue(powerGrid.IsOperating); }
public bool PlugIn(PowerRelated powerRelated) { if (powerRelated == null) { throw new ArgumentNullException("powerRelated"); } if (IsEmpty) { powerGrids.Add(new PowerGrid()); } PowerGrid powerGrid = powerGrids.FirstOrDefault(grid => grid.CanPlugIn(powerRelated)); return(PlugIn(powerRelated, powerGrid)); }
public bool IsPluggedIn(PowerRelated powerRelated, out PowerGrid powerGrid) { if (powerRelated == null) { throw new ArgumentNullException("powerRelated"); } if (IsEmpty) { powerGrid = null; return(false); } powerGrid = powerGrids.FirstOrDefault(grid => grid.IsPluggedIn(powerRelated)); return(powerGrid != null); }
public void UpdateEnoughPowerTest() { PowerRelated powerProducer = new PowerRelated { OutputRate = 50.0f }; PowerRelated firstPowerConsumer = new PowerRelated { InputRate = 30.0f }; livePowerSystem.PlugIn(powerProducer); livePowerSystem.PlugIn(firstPowerConsumer); Assert.AreEqual(1, powerGrids.Count); livePowerSystem.Update(); Assert.IsTrue(livePowerSystem.HasPower(powerProducer)); Assert.IsTrue(livePowerSystem.HasPower(firstPowerConsumer)); }
public void Unplug(PowerRelated powerRelated) { if (powerRelated == null) { throw new ArgumentNullException("powerRelated"); } PowerGrid powerGrid; IsPluggedIn(powerRelated, out powerGrid); if (powerGrid == null) { return; } Unplug(powerRelated, powerGrid); }