public void CircuitValidatesLooped() { // Later change to importing the circuit from file var c = new Circuit(); var i1 = new InputNode(); var n1 = new NotNode(); var n2 = new NotNode(); var n3 = new NotNode(); c.AddInput(i1, NodeCurrent.None); c.Add(i1); c.Add(n1); c.Add(n2); c.Add(n3); i1.AddOutput(n1); n1.AddOutput(n2); n2.AddOutput(n3); n3.AddOutput(n1); Assert.ThrowsException <CircuitInvalidException>(() => { c.Accept(new CircuitLoopValidatorVisitor()); }); }
void StartAndDraw() { Graph graph = new Graph("graph"); Circuit.Reset(); Circuit.Start(); Circuit.Accept(new DrawVisitor(graph)); Viewer.Graph = graph; }
private void ValidateCircuit() { _circuit.Accept(new ValidationVisitor(_outputHandler)); _circuit.EntryNodes.ForEach((node) => { node.Accept(new ValidationVisitor(_outputHandler)); }); _circuit.GridNodes.ForEach((node) => { node.Accept(new ValidationVisitor(_outputHandler)); }); }
private async Task Run() { ErrorLabel.Content = ""; var ofd = new OpenFileDialog(); if (ofd.ShowDialog() == true) { try { Inputs.Children.Clear(); var builder = new CircuitBuilder(); Circuit = await builder.AddDefaultNodes() .AddFileSource(ofd.FileName) .Build(); Circuit.Accept(new CircuitLoopValidatorVisitor()); Circuit.Accept(new CircuitConnectionValidatorVisitor()); Circuit.inputNodes.ForEach(inp => { CheckBox checkBox = new CheckBox() { Content = inp.Name, IsChecked = inp.Value == Core.Nodes.NodeCurrent.High }; checkBox.Checked += (s, e) => { inp.Value = Core.Nodes.NodeCurrent.High; StartAndDraw(); }; checkBox.Unchecked += (s, e) => { inp.Value = Core.Nodes.NodeCurrent.Low; StartAndDraw(); }; Inputs.Children.Add(checkBox); }); StartAndDraw(); } catch (Exception ex) { ErrorLabel.Content = "Error bij het valideren: " + ex.Message; } } }
private void StartSimulation() { if (_circuit == null) { return; } ConsoleOutput.Add("Simulation started."); PropagationVisitor visitor = new PropagationVisitor(); _circuit.Accept(visitor); _circuit.StartSimulation(); ConsoleOutput.Add("Simulation ended."); ConsoleOutput.Add("The delay = " + visitor.Output); }
public void CircuitValidatesNotConnectedToOutput() { // Later change to importing the circuit from file var c = new Circuit(); var i1 = new InputNode(); var i2 = new InputNode(); var n1 = new AndNode(); c.AddInput(i1, NodeCurrent.None); c.AddInput(i2, NodeCurrent.None); i1.AddOutput(n1); i2.AddOutput(n1); c.Add(n1); Assert.ThrowsException <CircuitInvalidException>(() => { c.Accept(new CircuitConnectionValidatorVisitor()); }); }
public void CircuitValidatesConnected() { // Later change to importing the circuit from file var c = new Circuit(); var i1 = new InputNode(); var i2 = new InputNode(); var n1 = new AndNode(); var o1 = new OutputNode(); c.AddInput(i1, NodeCurrent.None); c.AddInput(i2, NodeCurrent.None); i1.AddOutput(n1); i2.AddOutput(n1); n1.AddOutput(o1); c.Add(n1); c.Accept(new CircuitConnectionValidatorVisitor()); Assert.IsTrue(true); }