private void ButtonAddElement_Click(object sender, EventArgs e) { if (_comboBoxAddNodeType.SelectedItem is NodeTypeComboBoxItem type) { try { switch (type.Value) { case NodeType.Series: _circuit.AddAfter(_currentNode, new SeriesSubcircuit()); break; case NodeType.Parallel: _circuit.AddAfter(_currentNode, new ParallelSubcircuit()); break; default: _circuit.AddAfter(_currentNode, ElementFactory.GetInstance(type.Value, _textBoxAddElementName.Text, _value)); break; } ClearCircuit(); UpdateTreeView(); } catch (Exception exception) { MessageBox.Show(exception.Message); } } }
public void RemoveRootTest() { Circuit circuit = new Circuit(); SeriesSubcircuit seriesSubcircuit = new SeriesSubcircuit(); circuit.AddAfter(null, seriesSubcircuit); circuit.Remove(seriesSubcircuit); if (circuit.Root != null) { throw new Exception("Корень был null"); } }
public void AddAfterTest() { Circuit circuit = new Circuit(); SeriesSubcircuit seriesSubcircuit = new SeriesSubcircuit(); ParallelSubcircuit parallelSubcircuit = new ParallelSubcircuit(); circuit.AddAfter(null, seriesSubcircuit); circuit.AddAfter(seriesSubcircuit, new Resistor("R", 20)); circuit.AddAfter(seriesSubcircuit, new Resistor("R", 20)); circuit.AddAfter(parallelSubcircuit, new Resistor("R", 20)); circuit.AddAfter(parallelSubcircuit, new Resistor("R", 20)); circuit.AddAfter(seriesSubcircuit, parallelSubcircuit); Assert.AreEqual(50, circuit.CalculateZ(new double[] { 1 })[0].Real, 0.01); }