public void HangingConnection_Positive() { string file = "# Test" + Environment.NewLine + "A: INPUT_HIGH;"+ Environment.NewLine + "B: INPUT_HIGH;"+ Environment.NewLine + "S: PROBE;"+ Environment.NewLine + "NODE1: NAND;"+ Environment.NewLine + "" + Environment.NewLine + "A: NODE1;"+ Environment.NewLine + "B: NODE1;"+ Environment.NewLine + "NODE1: S;"; FileAsObject o = new FileAsObject(); HangingConnectionChecker hangingConnectionChecker = new HangingConnectionChecker(file); o.Attach(new NodeLine("A: INPUT_HIGH;")); o.Attach(new NodeLine("B: INPUT_HIGH;")); o.Attach(new NodeLine("S: PROBE;")); o.Attach(new NodeLine("NODE1: NAND;")); o.Attach(new ConnectionLine("A: NODE1;")); o.Attach(new ConnectionLine("B: NODE1;")); o.Attach(new ConnectionLine("NODE1: S;")); (bool success, string validationError)res = o.Accept(hangingConnectionChecker); Assert.AreEqual(true, res.success); }
public void FormatChecker_Negative() { string file = "# Test" + Environment.NewLine + "A: INPUT_HIGH;"+ Environment.NewLine + "B: INPUT_HIGH;"+ Environment.NewLine + "S: PROBE;"+ Environment.NewLine + "NODE1: NAND;"+ Environment.NewLine + "A: NODE1;"+ Environment.NewLine + "B: NODE1;"+ Environment.NewLine + "NODE1: S;"; FileAsObject o = new FileAsObject(); FormatChecker formatChecker = new FormatChecker(file); o.Attach(new NodeLine("A: INPUT_HIGH;")); o.Attach(new NodeLine("B: INPUT_HIGH;")); o.Attach(new NodeLine("S: PROBE;")); o.Attach(new NodeLine("NODE1: NAND;")); o.Attach(new ConnectionLine("A: NODE1;")); o.Attach(new ConnectionLine("B: NODE1;")); o.Attach(new ConnectionLine("NODE1: S;")); (bool success, string validationError)res = o.Accept(formatChecker); Assert.AreEqual(false, res.success); Assert.AreEqual("Encountered connection before empty line. (line: 'A: NODE1;')", res.validationError); }
public void Line_Positive() { FileAsObject o = new FileAsObject(); LineChecker lineChecker = new LineChecker(); lineChecker.SetInternalCircuitNamesForTests(new string[] { "INPUT_HIGH", "INPUT_LOW", "PROBE", "NAND" }); o.Attach(new NodeLine("A: INPUT_HIGH;")); o.Attach(new NodeLine("B: INPUT_HIGH;")); o.Attach(new NodeLine("S: PROBE;")); o.Attach(new NodeLine("NODE1: NAND;")); o.Attach(new ConnectionLine("A: NODE1;")); o.Attach(new ConnectionLine("B: NODE1;")); o.Attach(new ConnectionLine("NODE1: S;")); (bool success, string validationError)res = o.Accept(lineChecker); Assert.AreEqual(true, res.success); }
public void Loop_Negative() { string file = "# Test" + Environment.NewLine + "A: INPUT_HIGH;"+ Environment.NewLine + "B: INPUT_HIGH;"+ Environment.NewLine + "S: PROBE;"+ Environment.NewLine + "NODE1: NAND;"+ Environment.NewLine + "NODE2: NAND;"+ Environment.NewLine + "NODE3: NAND;"+ Environment.NewLine + "" + Environment.NewLine + "A: NODE1;"+ Environment.NewLine + "B: NODE1;"+ Environment.NewLine + "NODE1: NODE2;"+ Environment.NewLine + "NODE2: NODE1;"+ Environment.NewLine + "NODE3: S;"; FileAsObject o = new FileAsObject(); LoopChecker loopChecker = new LoopChecker(file); o.Attach(new NodeLine("A: INPUT_HIGH;")); o.Attach(new NodeLine("B: INPUT_HIGH;")); o.Attach(new NodeLine("S: PROBE;")); o.Attach(new NodeLine("NODE1: NAND;")); o.Attach(new NodeLine("NODE2: NAND;")); o.Attach(new NodeLine("NODE3: NAND;")); o.Attach(new ConnectionLine("A: NODE1;")); o.Attach(new ConnectionLine("B: NODE1;")); o.Attach(new ConnectionLine("NODE1: NODE2;")); o.Attach(new ConnectionLine("NODE2: NODE1;")); o.Attach(new ConnectionLine("NODE3: S;")); (bool success, string validationError)res = o.Accept(loopChecker); Assert.AreEqual(false, res.success); Assert.AreEqual("Node: 'A' leads to an infinite loop.", res.validationError); }
public static (bool success, string validationError) Validate(string content) { FileAsObject o = new FileAsObject(); using (StringReader reader = new StringReader(content)) { bool blockOne = true; string line; while ((line = reader.ReadLine()) != null) { if (line.StartsWith("#")) { continue; } if (line.Equals("")) { blockOne = false; continue; } if (blockOne) { o.Attach(new NodeLine(line)); } else { o.Attach(new ConnectionLine(line)); } } } FormatChecker formatChecker = new FormatChecker(content); LineChecker lineChecker = new LineChecker(); if (InternalCircuitNamesForTests != null) { lineChecker.SetInternalCircuitNamesForTests(InternalCircuitNamesForTests); } LoopChecker loopChecker = new LoopChecker(content); HangingConnectionChecker hangingConnectionChecker = new HangingConnectionChecker(content); (bool success, string validationError)res; if (!(res = o.Accept(formatChecker)).success) { return(res); } if (!(res = o.Accept(lineChecker)).success) { return(res); } if (!(res = o.Accept(hangingConnectionChecker)).success) { return(res); } if (!(res = o.Accept(loopChecker)).success) { return(res); } return( success : true, validationError : "" ); }