public void DisconnectedAdjacentComponentsMatchesElement() { var element = new MockedElement(1); IComponent component = element.Terminals.First(); Assert.Equal(component.AdjacentComponents, new[] { element }); }
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)); }
public void AdjacentComponentsMatchTerminals(int numberOfTerminals) { var element = new MockedElement(numberOfTerminals); IComponent component = element; Assert.Equal(component.AdjacentComponents, element.Terminals); }
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)); }
public void ConnectT2Self() { MockedElement element = new MockedElement(1); var terminal = element.Terminals.First(); Assert.Throws <InvalidOperationException>(() => terminal.ConnectTo(terminal)); }
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); }
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)); }
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); }
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 }); }
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()); }
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); }
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); }
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); }
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())); }
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); }
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)); }
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); }
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())); }
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())); }
public void TerminalsMatchElementContent(int numberOfTerminals) { var element = new MockedElement(numberOfTerminals); Assert.Equal(numberOfTerminals, element.Terminals.Count); }
public void DisconnectedIsNull() { var element = new MockedElement(1); Assert.Null(element.Terminals.First().Node); }
public void NodeVariablesHasOnlyOneVariable() { IComponent node = new MockedElement(2).Terminals.ConnectAll(); Assert.Single(node.Variables); }
public void TerminalVariablesHasOnlyOneVariable() { IComponent terminal = new MockedElement(1).Terminals.First(); Assert.Single(terminal.Variables); }
public void ConnectAllWorks(int numberOfTerminals) { var terminals = new MockedElement(numberOfTerminals).Terminals; Assert.Equal(terminals, terminals.ConnectAll().Terminals); }
public void ElementMatchesCreator() { var element = new MockedElement(1); Assert.Equal(element, element.Terminals.First().Element); }