Exemplo n.º 1
0
    public bool HasPower(PowerRelated powerRelated)
    {
        PowerGrid powerGrid;

        IsPluggedIn(powerRelated, out powerGrid);
        return(powerGrid != null && powerGrid.IsOperating);
    }
Exemplo n.º 2
0
    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));
    }
Exemplo n.º 3
0
    public void IsPluggedInTest()
    {
        PowerRelated powerRelated = new PowerRelated();

        powerGrid.PlugIn(powerRelated);
        Assert.AreEqual(1, gridHashSet.Count);
        Assert.IsTrue(powerGrid.IsPluggedIn(powerRelated));
    }
Exemplo n.º 4
0
    public bool PlugIn(PowerRelated powerRelated, PowerGrid powerGrid)
    {
        if (powerRelated == null)
        {
            throw new ArgumentNullException("powerRelated");
        }

        return(powerGrid != null && powerGrid.PlugIn(powerRelated));
    }
Exemplo n.º 5
0
    public bool CanPlugIn(PowerRelated powerRelated)
    {
        if (powerRelated == null)
        {
            throw new ArgumentNullException("powerRelated");
        }

        return(powerGrids.Any(grid => grid.CanPlugIn(powerRelated)));
    }
Exemplo n.º 6
0
    public void UnplugTest()
    {
        PowerRelated powerRelated = new PowerRelated();

        powerGrid.PlugIn(powerRelated);
        Assert.AreEqual(1, gridHashSet.Count);
        powerGrid.Unplug(powerRelated);
        Assert.AreEqual(0, gridHashSet.Count);
    }
Exemplo n.º 7
0
    public void Unplug(PowerRelated powerRelated)
    {
        if (powerRelated == null)
        {
            throw new ArgumentNullException("powerRelated");
        }

        powerGrid.Remove(powerRelated);
    }
Exemplo n.º 8
0
    public bool IsPluggedIn(PowerRelated powerRelated)
    {
        if (powerRelated == null)
        {
            throw new ArgumentNullException("powerRelated");
        }

        return(powerGrid.Contains(powerRelated));
    }
Exemplo n.º 9
0
    public bool CanPlugIn(PowerRelated powerRelated)
    {
        if (powerRelated == null)
        {
            throw new ArgumentNullException("powerRelated");
        }

        return(true);
    }
Exemplo n.º 10
0
    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);
    }
Exemplo n.º 13
0
    public bool PlugIn(PowerRelated powerRelated)
    {
        if (powerRelated == null)
        {
            throw new ArgumentNullException("powerRelated");
        }

        if (!CanPlugIn(powerRelated))
        {
            return(false);
        }

        powerGrid.Add(powerRelated);
        return(true);
    }
Exemplo n.º 14
0
    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);
    }
Exemplo n.º 15
0
    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));
    }
Exemplo n.º 16
0
    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));
    }
Exemplo n.º 18
0
    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);
    }