コード例 #1
0
ファイル: Terminal.UT.cs プロジェクト: pamola-net/Pamola.NET
        public void DisconnectedAdjacentComponentsMatchesElement()
        {
            var        element   = new MockedElement(1);
            IComponent component = element.Terminals.First();

            Assert.Equal(component.AdjacentComponents, new[] { element });
        }
コード例 #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));
        }
コード例 #3
0
        public void AdjacentComponentsMatchTerminals(int numberOfTerminals)
        {
            var        element   = new MockedElement(numberOfTerminals);
            IComponent component = element;

            Assert.Equal(component.AdjacentComponents, element.Terminals);
        }
コード例 #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));
        }
コード例 #5
0
        public void ConnectT2Self()
        {
            MockedElement element = new MockedElement(1);

            var terminal = element.Terminals.First();

            Assert.Throws <InvalidOperationException>(() => terminal.ConnectTo(terminal));
        }
コード例 #6
0
ファイル: Terminal.UT.cs プロジェクト: pamola-net/Pamola.NET
        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);
        }
コード例 #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));
        }
コード例 #8
0
ファイル: Node.UT.cs プロジェクト: pamola-net/Pamola.NET
        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);
        }
コード例 #9
0
ファイル: Terminal.UT.cs プロジェクト: pamola-net/Pamola.NET
        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 });
        }
コード例 #10
0
ファイル: Node.UT.cs プロジェクト: pamola-net/Pamola.NET
        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());
        }
コード例 #11
0
ファイル: Node.UT.cs プロジェクト: pamola-net/Pamola.NET
        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);
        }
コード例 #12
0
ファイル: Terminal.UT.cs プロジェクト: pamola-net/Pamola.NET
        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);
        }
コード例 #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);
        }
コード例 #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()));
        }
コード例 #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);
        }
コード例 #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));
        }
コード例 #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);
        }
コード例 #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()));
        }
コード例 #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()));
        }
コード例 #20
0
        public void TerminalsMatchElementContent(int numberOfTerminals)
        {
            var element = new MockedElement(numberOfTerminals);

            Assert.Equal(numberOfTerminals, element.Terminals.Count);
        }
コード例 #21
0
ファイル: Terminal.UT.cs プロジェクト: pamola-net/Pamola.NET
        public void DisconnectedIsNull()
        {
            var element = new MockedElement(1);

            Assert.Null(element.Terminals.First().Node);
        }
コード例 #22
0
ファイル: Node.UT.cs プロジェクト: pamola-net/Pamola.NET
        public void NodeVariablesHasOnlyOneVariable()
        {
            IComponent node = new MockedElement(2).Terminals.ConnectAll();

            Assert.Single(node.Variables);
        }
コード例 #23
0
ファイル: Terminal.UT.cs プロジェクト: pamola-net/Pamola.NET
        public void TerminalVariablesHasOnlyOneVariable()
        {
            IComponent terminal = new MockedElement(1).Terminals.First();

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

            Assert.Equal(terminals, terminals.ConnectAll().Terminals);
        }
コード例 #25
0
ファイル: Terminal.UT.cs プロジェクト: pamola-net/Pamola.NET
        public void ElementMatchesCreator()
        {
            var element = new MockedElement(1);

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