Ejemplo n.º 1
0
        public void General_Positive()
        {
            string filePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            filePath += "../../../../Circuits/Circuit1_FullAdder.txt";
            Validator.InternalCircuitNamesForTests = new string[] {
                "INPUT_HIGH", "INPUT_LOW", "PROBE", "NAND", "OR", "AND", "NOT"
            };

            CircuitParser parser = CircuitParser.GetParser();

            (bool success, string fileName, string error)result = parser.AddFile(filePath);

            Assert.AreEqual(true, result.success);

            int nodeCount = 0;

            foreach (var nodeString in parser.GetNodeString(result.fileName))
            {
                nodeCount++;
            }

            Assert.AreEqual(16, nodeCount);

            int connectionCount = 0;

            foreach (var connectionString in parser.GetConnectionString(result.fileName))
            {
                connectionCount++;
            }

            Assert.AreEqual(14, connectionCount);
        }
Ejemplo n.º 2
0
        public static (bool success, Circuit circuit, string error) GetFromFile(string filePath)
        {
            CircuitParser parser = CircuitParser.GetParser();

            (bool success, string fileName, string error)result = parser.AddFile(filePath);

            if (result.success)
            {
                string fileName = result.fileName;

                CircuitBuilder circuitBuilder = new CircuitBuilder();
                circuitBuilder.SetName(fileName);

                foreach (var nodeString in parser.GetNodeString(fileName))
                {
                    circuitBuilder.AddNode(nodeString.name, nodeString.type);
                }

                foreach (var connectionString in parser.GetConnectionString(fileName))
                {
                    foreach (string outputNode in connectionString.outputs)
                    {
                        circuitBuilder.AddConnection(connectionString.input, outputNode);
                    }
                }

                circuits[fileName] = circuitBuilder.GetCircuit();
                return(true, circuits[fileName], "");
            }
            else
            {
                return(false, null, result.error);
            }
        }
Ejemplo n.º 3
0
        public void NotConnected_Negative()
        {
            string filePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            filePath += "../../../../Circuits/Circuit5_NotConnected.txt";
            Validator.InternalCircuitNamesForTests = new string[] {
                "INPUT_HIGH", "INPUT_LOW", "PROBE", "NAND", "OR", "AND", "NOT"
            };

            CircuitParser parser = CircuitParser.GetParser();

            (bool success, string fileName, string error)result = parser.AddFile(filePath);

            Assert.AreEqual(false, result.success);
            Assert.AreEqual("NODE2 has no outputs.", result.error);
        }
Ejemplo n.º 4
0
        public void InfiniteLoop_Negative()
        {
            string filePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            filePath += "../../../../Circuits/Circuit4_InfiniteLoop.txt";
            Validator.InternalCircuitNamesForTests = new string[] {
                "INPUT_HIGH", "INPUT_LOW", "PROBE", "NAND", "OR", "AND", "NOT"
            };

            CircuitParser parser = CircuitParser.GetParser();

            (bool success, string fileName, string error)result = parser.AddFile(filePath);

            Assert.AreEqual(false, result.success);
            Assert.AreEqual("Node: 'S' leads to an infinite loop.", result.error);
        }