Beispiel #1
0
        public void DisconnectedAdjacentComponentsMatchesElement()
        {
            var        element   = new MockedElement(1);
            IComponent component = element.Terminals.First();

            Assert.Equal(component.AdjacentComponents, new[] { element });
        }
Beispiel #2
0
        public void AppendComplexConnections()
        {
            MockedElement element1 = new MockedElement(2);
            MockedElement element2 = new MockedElement(2);
            MockedElement element3 = new MockedElement(3);

            var n1 = element1.Terminals.First().
                     ConnectTo(element2.Terminals.First()).
                     ConnectTo(element3.Terminals.First());

            var n2 = element1.Terminals.Last().
                     ConnectTo(element2.Terminals.Last()).
                     ConnectTo(element3.Terminals.Last());

            var circuit = n1.GetCircuit();

            var elements  = new[] { element1, element2, element3 };
            var terminals = elements.SelectMany(element => element.Terminals);
            var nodes     = new[] { n1, n2 };

            var components = (new[] {
                elements.Cast <IComponent>(),
                terminals.Cast <IComponent>(),
                nodes.Cast <IComponent>()
            }).
                             SelectMany(cSerie => cSerie);

            Assert.Empty(components.Except(circuit.Components));
            Assert.Empty(circuit.Components.Except(components));
        }
Beispiel #3
0
        public void AdjacentComponentsMatchTerminals(int numberOfTerminals)
        {
            var        element   = new MockedElement(numberOfTerminals);
            IComponent component = element;

            Assert.Equal(component.AdjacentComponents, element.Terminals);
        }
Beispiel #4
0
        public void ConnectT2TFromDisconnected()
        {
            MockedElement element   = new MockedElement(2);
            var           terminals = element.Terminals.ToList();
            Node          node      = terminals[0].ConnectTo(terminals[1]);

            Assert.All(terminals, terminal => Assert.Equal(node, terminal.Node));
        }
Beispiel #5
0
        public void ConnectT2Self()
        {
            MockedElement element = new MockedElement(1);

            var terminal = element.Terminals.First();

            Assert.Throws <InvalidOperationException>(() => terminal.ConnectTo(terminal));
        }
Beispiel #6
0
        public void ConnectedMatchesNode()
        {
            var element = new MockedElement(2);
            var node    = element.Terminals.First().ConnectTo(element.Terminals.Last());

            Assert.NotNull(element.Terminals.First().Node);
            Assert.Equal(node, element.Terminals.First().Node);
        }
Beispiel #7
0
        public void AppendComponents()
        {
            var element = new MockedElement(2);
            var circuit = element.GetCircuit();

            Assert.Contains(element, circuit.Components);
            Assert.All(element.Terminals, terminal => Assert.Contains(terminal, circuit.Components));
        }
Beispiel #8
0
        public void AdjacentComponentsMatchTerminals()
        {
            var element = new MockedElement(2);
            var node    = element.Terminals.First().ConnectTo(element.Terminals.Last());

            IComponent component = node;

            Assert.Equal(component.AdjacentComponents, node.Terminals);
        }
Beispiel #9
0
        public void ConnectedAdjacentComponentsMatchesElementAndNode()
        {
            var element = new MockedElement(2);
            var node    = element.Terminals.First().ConnectTo(element.Terminals.Last());

            IComponent component = element.Terminals.First();

            Assert.Equal(component.AdjacentComponents, new[] { (IComponent)element, node });
        }
Beispiel #10
0
        public void NodeObeysKirchhofsCurrentLaw()
        {
            var node = new MockedElement(3).Terminals.ConnectAll();

            node.Terminals.Cast <IComponent>().SelectMany(t => t.Variables).ToList().ForEach(t => t.Setter(new System.Numerics.Complex(1.0, -1.0)));
            var equation = ((IComponent)node).Equations.First();

            Assert.Equal(new Complex(3.0, -3.0), equation());
        }
Beispiel #11
0
        public void NodeVariablesSetsCurrent()
        {
            var        node      = new MockedElement(2).Terminals.ConnectAll();
            IComponent component = node;
            var        voltage   = new System.Numerics.Complex(3.0, 4.0);

            component.Variables.First().Setter(voltage);

            Assert.Equal(voltage, node.Voltage);
        }
Beispiel #12
0
        public void TerminalVariablesSetsCurrent()
        {
            var        terminal  = new MockedElement(1).Terminals.First();
            IComponent component = terminal;
            var        current   = new System.Numerics.Complex(3.0, 4.0);

            component.Variables.First().Setter(current);

            Assert.Equal(current, terminal.Current);
        }
Beispiel #13
0
        public void Disconnection()
        {
            MockedElement element   = new MockedElement(2);
            var           terminals = element.Terminals.ToList();
            Node          node      = terminals[0].ConnectTo(terminals[1]);

            terminals[0].Disconnect();
            Assert.All(element.Terminals, (terminal) => Assert.False(terminal.IsConnected()));

            Assert.Empty(node.Terminals);
        }
Beispiel #14
0
        public void IsConnected()
        {
            MockedElement element = new MockedElement(2);

            Assert.All(element.Terminals, (terminal) => Assert.False(terminal.IsConnected()));

            var terminals = element.Terminals.ToList();

            terminals[0].ConnectTo(terminals[1]);

            Assert.All(element.Terminals, (terminal) => Assert.True(terminal.IsConnected()));
        }
Beispiel #15
0
        public void AvoidConnectedTerminals()
        {
            MockedElement element = new MockedElement(3);

            var(terminalL, terminalR) =
                (element.Terminals.First(), element.Terminals.Last());

            terminalL.ConnectTo(terminalR);

            var circuit = terminalL.GetCircuit();

            Assert.Single(circuit.Terminals);
        }
Beispiel #16
0
        public void EquationsContainsAllComponentsEquations()
        {
            MockedElement element1 = new MockedElement(2);
            MockedElement element2 = new MockedElement(2);

            var circuit = element1.Terminals.First().ConnectTo(element2.Terminals.First()).GetCircuit();

            var circuitEquations = ((IComponent)circuit).Equations;

            var componentsEquations = circuit.Components.SelectMany(component => component.Equations);

            Assert.NotEmpty(circuitEquations);
            Assert.NotEmpty(componentsEquations);
            Assert.Empty(circuitEquations.Except(componentsEquations));
            Assert.Empty(componentsEquations.Except(circuitEquations));
        }
Beispiel #17
0
        public void ConnectT2TFromConnected()
        {
            MockedElement element1 = new MockedElement(2);
            MockedElement element2 = new MockedElement(1);

            var terminals1 = element1.Terminals.ToList();
            var terminals2 = element2.Terminals.ToList();

            Node previousNode = terminals1.First().ConnectTo(terminals2.First());

            Node newNode = terminals1.Last().ConnectTo(terminals2.First());

            Assert.Empty(previousNode.Terminals);

            Assert.False(terminals1.First().IsConnected());

            Assert.Equal(newNode, terminals1.Last().Node);
            Assert.Equal(newNode, terminals2.First().Node);
        }
Beispiel #18
0
        public void VariablesContainsAllComponentsVariables()
        {
            MockedElement element1 = new MockedElement(2);
            MockedElement element2 = new MockedElement(2);

            var circuit = element1.Terminals.First().ConnectTo(element2.Terminals.First()).GetCircuit();

            var circuitVariables = ((IComponent)circuit).Variables;

            var componentsVariables = circuit.Components.SelectMany(component => component.Variables);

            var complex = new System.Numerics.Complex(1.0, 1.0);

            componentsVariables.ToList().ForEach(variable => variable.Setter(complex));

            Assert.NotEmpty(circuitVariables);
            Assert.NotEmpty(componentsVariables);
            Assert.All(circuitVariables, variable => Assert.Equal(complex, variable.Getter()));
        }
Beispiel #19
0
        public void ConnectN2N()
        {
            MockedElement element1 = new MockedElement(2);
            MockedElement element2 = new MockedElement(2);

            var terminals1 = element1.Terminals.ToList();
            var terminals2 = element2.Terminals.ToList();

            Node node1 = terminals1.First().ConnectTo(terminals1.Last());
            Node node2 = terminals2.First().ConnectTo(terminals2.Last());

            Node node3 = node1.ConnectTo(node2);

            Assert.Equal(node3, node1);

            Assert.Empty(node2.Terminals);

            Assert.Equal(terminals1.Union(terminals2), node1.Terminals);

            Assert.All(node1.Terminals, (terminal) => Assert.True(terminal.IsConnected()));
        }
Beispiel #20
0
        public void TerminalsMatchElementContent(int numberOfTerminals)
        {
            var element = new MockedElement(numberOfTerminals);

            Assert.Equal(numberOfTerminals, element.Terminals.Count);
        }
Beispiel #21
0
        public void DisconnectedIsNull()
        {
            var element = new MockedElement(1);

            Assert.Null(element.Terminals.First().Node);
        }
Beispiel #22
0
        public void NodeVariablesHasOnlyOneVariable()
        {
            IComponent node = new MockedElement(2).Terminals.ConnectAll();

            Assert.Single(node.Variables);
        }
Beispiel #23
0
        public void TerminalVariablesHasOnlyOneVariable()
        {
            IComponent terminal = new MockedElement(1).Terminals.First();

            Assert.Single(terminal.Variables);
        }
Beispiel #24
0
        public void ConnectAllWorks(int numberOfTerminals)
        {
            var terminals = new MockedElement(numberOfTerminals).Terminals;

            Assert.Equal(terminals, terminals.ConnectAll().Terminals);
        }
Beispiel #25
0
        public void ElementMatchesCreator()
        {
            var element = new MockedElement(1);

            Assert.Equal(element, element.Terminals.First().Element);
        }