public void CircuitTestSocketBuildTruthTable1Test()
        {
            ProjectTester.SwitchTo(this.CircuitProject, "1 Bit Wire");
            CircuitTestSocket      s1        = new CircuitTestSocket(this.CircuitProject.ProjectSet.Project.LogicalCircuit);
            ExpressionParser       parser    = new ExpressionParser(s1);
            Predicate <TruthState> predicate = parser.Parse("q=x", true);
            double             progress      = -1;
            bool               truncated;
            IList <TruthState> table1 = s1.BuildTruthTable(
                p => { Assert.IsTrue(0 <= p && p <= 100); progress = p; },
                () => true,
                null,
                2,
                out truncated
                );

            Assert.IsTrue(Math.Abs(progress - 100) < 2);
            Assert.IsTrue(!truncated);
            Assert.IsTrue(table1 != null && table1.Count == 2);
            Assert.IsTrue(table1[0].Input[0] == 0 && table1[0].Output[0] == 0);
            Assert.IsTrue(table1[1].Input[0] == 1 && table1[1].Output[0] == 1);

            IList <TruthState> table2 = s1.BuildTruthTable(
                p => { Assert.IsTrue(0 <= p && p <= 100); progress = p; },
                () => true,
                predicate,
                2,
                out truncated
                );

            Assert.IsTrue(Math.Abs(progress - 100) < 2);
            Assert.IsTrue(!truncated);
            Assert.IsTrue(table2 != null && table2.Count == 0);
        }
 private void AssertTestable(CircuitProject project, string circuitName, bool isTestable)
 {
     ProjectTester.SwitchTo(project, circuitName);
     Assert.AreEqual(isTestable, CircuitTestSocket.IsTestable(project.ProjectSet.Project.LogicalCircuit),
                     "{0} should {1}be testable", project.ProjectSet.Project.LogicalCircuit.Name, isTestable ? "" : "not "
                     );
 }
        private void CircuitMapCleanUpTest(CircuitProject circuitProject, string logicalCircuitName, int expectedFunctions)
        {
            ProjectTester.SwitchTo(circuitProject, logicalCircuitName);

            CircuitMap   map   = new CircuitMap(circuitProject.ProjectSet.Project.LogicalCircuit);
            CircuitState state = map.Apply(CircuitRunner.HistorySize);

            Assert.AreEqual(expectedFunctions, state.Functions.Count(), "wrong number of functions");
        }
        public static CircuitProject Load(TestContext testContext, string projectText, string initialCircuit)
        {
            // First save project text to test directory
            string path = Path.Combine(testContext.TestRunDirectory, string.Format("{0}.{1}.{2}.xml", testContext.FullyQualifiedTestClassName, testContext.TestName, DateTime.UtcNow.Ticks));

            File.WriteAllText(path, projectText, Encoding.UTF8);
            // Load it from test directory
            CircuitProject circuitProject = CircuitProject.Create(path);

            File.Delete(path);
            ProjectTester.InitResources();
            if (initialCircuit != null)
            {
                ProjectTester.SwitchTo(circuitProject, initialCircuit);
            }
            ProjectTester.GuaranteeGlyph(circuitProject);
            return(circuitProject);
        }
        public void CircuitTestSocketConstructorTest()
        {
            ProjectTester.SwitchTo(this.CircuitProject, "Unconnected");
            CircuitTestSocket s1 = new CircuitTestSocket(this.CircuitProject.ProjectSet.Project.LogicalCircuit);

            Assert.AreEqual(0, s1.Inputs.Count());
            Assert.AreEqual(0, s1.Outputs.Count());

            ProjectTester.SwitchTo(this.CircuitProject, "1 Bit Wire");
            CircuitTestSocket s2 = new CircuitTestSocket(this.CircuitProject.ProjectSet.Project.LogicalCircuit);

            Assert.AreEqual(1, s2.Inputs.Count());
            Assert.AreEqual(1, s2.Outputs.Count());
            Assert.AreEqual(1, s2.Inputs.Sum(i => i.Pin.BitWidth));
            Assert.AreEqual(1, s2.Outputs.Sum(i => i.Pin.BitWidth));

            ProjectTester.SwitchTo(this.CircuitProject, "8 bit adder");
            CircuitTestSocket s3 = new CircuitTestSocket(this.CircuitProject.ProjectSet.Project.LogicalCircuit);

            Assert.AreEqual(3, s3.Inputs.Count());
            Assert.AreEqual(3, s3.Outputs.Count());
            Assert.AreEqual(17, s3.Inputs.Sum(i => i.Pin.BitWidth));
            Assert.AreEqual(10, s3.Outputs.Sum(i => i.Pin.BitWidth));
        }
        public void CircuitTestSocketBuildTruthTable5Test()
        {
            ProjectTester.SwitchTo(this.CircuitProject, "8 bit adder");
            CircuitTestSocket      s1        = new CircuitTestSocket(this.CircuitProject.ProjectSet.Project.LogicalCircuit);
            ExpressionParser       parser    = new ExpressionParser(s1);
            Predicate <TruthState> predicate = parser.Parse("outC << 8 | s = inC + a + b && v = !(a & 0x80 != b & 0x80 || a & 0x80 == s & 0x80)", true);
            double             progress      = -1;
            bool               truncated;
            int                maxSize = 128;
            IList <TruthState> table1  = s1.BuildTruthTable(
                p => { Assert.IsTrue(0 <= p && p <= 100); progress = p; },
                () => true,
                null,
                maxSize,
                out truncated
                );

            Assert.IsTrue(truncated);
            Assert.IsTrue(table1 != null && table1.Count == maxSize);
            foreach (TruthState state in table1)
            {
                Assert.IsFalse(predicate(state));
            }

            IList <TruthState> table2 = s1.BuildTruthTable(
                p => { Assert.IsTrue(0 <= p && p <= 100); progress = p; },
                () => true,
                predicate,
                1,
                out truncated
                );

            Assert.IsTrue(Math.Abs(progress - 100) < 2);
            Assert.IsTrue(!truncated);
            Assert.IsTrue(table2 != null && table2.Count == 0);
        }