public void NumberOfEquationsEqualsTwo()
        {
            IComponent V         = new IdealDCVoltageSource(1.0);
            var        equations = V.Equations;

            Assert.Equal(2, equations.Count);
        }
        public void FollowsVoltageDropDisconnected()
        {
            var V1 = new IdealDCVoltageSource(1.0);
            var V2 = new IdealDCVoltageSource(1.0);
            var V3 = new IdealDCVoltageSource(1.0);

            var equations1 = ((IComponent)V1).Equations;
            var equations2 = ((IComponent)V2).Equations;
            var equations3 = ((IComponent)V3).Equations;

            V2.Positive.ConnectTo(V3.Negative);

            Assert.Equal(default(Complex), equations1.First()());
            Assert.Equal(default(Complex), equations2.First()());
            Assert.Equal(default(Complex), equations3.First()());
        }
        public void FollowsVoltageDropConnected(
            Complex voltageNode1,
            Complex voltageNode2,
            double voltage,
            Complex expectedValue)
        {
            var V      = new IdealDCVoltageSource(voltage);
            var dipole = new MockedDipole();

            var equation = ((IComponent)V).Equations.First();

            IComponent node1 = V.Positive.ConnectTo(dipole.Positive);
            IComponent node2 = V.Negative.ConnectTo(dipole.Negative);

            node1.Variables.First().Setter(voltageNode1);
            node2.Variables.First().Setter(voltageNode2);

            Assert.Equal(expectedValue, equation());
        }
Esempio n. 4
0
        public void SimpleMockedSolvedCircuit()
        {
            var R = new IdealResistor(2);
            var V = new IdealDCVoltageSource(12);

            R.Positive.ConnectTo(V.Positive);
            R.Negative.ConnectTo(V.Negative);

            var circuit = R.GetCircuit();

            var values = new[]
            {
                new Complex(6.0, 0),
                new Complex(12.0, 0),
                new Complex(-6.0, 0),
                new Complex(6.0, 0),
                new Complex(0.0, 0.0),
                new Complex(-6.0, 0)
            }.ToList();

            circuit.Solve(new MockedSolver()
            {
                SolvedState = values
            });

            Assert.Equal(new Complex(12.0, 0), R.Positive.Node.Voltage);
            Assert.Equal(new Complex(0.0, 0), R.Negative.Node.Voltage);

            Assert.Equal(new Complex(6, 0), R.Positive.Current);
            Assert.Equal(new Complex(-6, 0), R.Negative.Current);

            Assert.Equal(new Complex(-6, 0), V.Positive.Current);
            Assert.Equal(new Complex(6, 0), V.Negative.Current);

            Assert.All(((IComponent)circuit).Equations.Select(equation => equation()), result => Assert.Equal(new Complex(0, 0), result));
        }
        public void VoltageYieldsValue(double voltage)
        {
            var V = new IdealDCVoltageSource(voltage);

            Assert.Equal(voltage, V.Voltage);
        }
        public void VariablesReturnEmptyList()
        {
            IComponent V = new IdealDCVoltageSource(1.0);

            Assert.Empty(V.Variables);
        }