public void CircuitStateEndDefinitionTest()
        {
            ProjectTester.InitResources();
            CircuitProject project      = CircuitProject.Create(null);
            CircuitButton  button       = null;
            CircuitSymbol  buttonSymbol = null;
            Gate           led          = null;
            CircuitSymbol  ledSymbol    = null;

            project.InTransaction(() => {
                button       = project.CircuitButtonSet.Create("b", false, PinSide.Right);
                buttonSymbol = project.CircuitSymbolSet.Create(button, project.ProjectSet.Project.LogicalCircuit, 1, 1);
                led          = project.GateSet.Gate(GateType.Led, 1, false);
                ledSymbol    = project.CircuitSymbolSet.Create(led, project.ProjectSet.Project.LogicalCircuit, 5, 1);
            });

            CircuitState   target         = new CircuitState(3);
            int            buttonResult   = target.ReserveState();
            FunctionButton functionButton = new FunctionButton(target, new CircuitSymbol[] { buttonSymbol }, buttonResult);
            FunctionLed    functionLed    = new FunctionLed(target, new CircuitSymbol[] { ledSymbol }, buttonResult);

            target.EndDefinition();

            Assert.IsTrue(functionButton.Dependent != null && functionButton.Dependent.Length == 1 && functionButton.Dependent[0] == functionLed);
            Assert.IsTrue(functionLed.Dependent == null);
        }
        public void CircuitProjectSaveLoadTest()
        {
            string dir  = Path.Combine(this.TestContext.TestRunDirectory, this.TestContext.TestName + DateTime.UtcNow.Ticks, "Some Test Sub Directory");
            string file = Path.Combine(dir, "My Test File.CircuitProject");

            // save in inexistent folder
            CircuitProject project1 = CircuitProject.Create(null);

            project1.InTransaction(() => {
                LogicalCircuit main        = project1.ProjectSet.Project.LogicalCircuit;
                CircuitButton button       = project1.CircuitButtonSet.Create("b", false, PinSide.Right);
                CircuitSymbol buttonSymbol = project1.CircuitSymbolSet.Create(button, main, 1, 2);
                Gate led = project1.GateSet.Gate(GateType.Led, 1, false);
                project1.CircuitSymbolSet.Create(led, main, 6, 2);
                Wire wire = project1.WireSet.Create(main, new GridPoint(3, 3), new GridPoint(6, 3));
            });
            Assert.IsTrue(!Directory.Exists(dir));
            project1.Save(file);
            Assert.IsTrue(File.Exists(file));
            CircuitProject project2 = CircuitProject.Create(file);

            Assert.IsTrue(ProjectTester.Equal(project1, project2));

            // save in existing folder and existing file.
            CircuitProject project3 = ProjectTester.Load(this.TestContext, Properties.Resources.Digital_Clock, null);

            Assert.IsTrue(File.Exists(file));
            project3.Save(file);
            CircuitProject project4 = CircuitProject.Create(file);

            File.Delete(file);
            Assert.IsTrue(ProjectTester.Equal(project3, project4));
        }
        public void ConductorMapThreeWiresJoinTest()
        {
            CircuitProject project = CircuitProject.Create(null);
            LogicalCircuit circuit = project.ProjectSet.Project.LogicalCircuit;
            Wire           wire1   = null;
            Wire           wire2   = null;
            Wire           wire3   = null;

            project.InTransaction(() => wire1 = project.WireSet.Create(circuit, new GridPoint(1, 2), new GridPoint(3, 4)));
            project.InTransaction(() => wire2 = project.WireSet.Create(circuit, new GridPoint(5, 6), new GridPoint(7, 8)));

            ConductorMap target0 = new ConductorMap(circuit);

            Assert.AreEqual(2, target0.Conductors.Count());

            project.InTransaction(() => wire3 = project.WireSet.Create(circuit, new GridPoint(5, 6), new GridPoint(1, 2)));

            ConductorMap target = new ConductorMap(circuit);

            Assert.AreEqual(1, target.Conductors.Count());
            Conductor conductor;

            Assert.IsTrue(target.TryGetValue(new GridPoint(7, 8), out conductor));
            Assert.AreEqual(3, conductor.Wires.Count());
            Assert.AreEqual(4, conductor.Points.Count());
        }
        public void ConductorMapTwoWiresTwoConductorTest()
        {
            CircuitProject project = CircuitProject.Create(null);
            LogicalCircuit circuit = project.ProjectSet.Project.LogicalCircuit;
            Wire           wire1   = null;
            Wire           wire2   = null;

            project.InTransaction(() => wire1 = project.WireSet.Create(circuit, new GridPoint(1, 2), new GridPoint(3, 4)));
            project.InTransaction(() => wire2 = project.WireSet.Create(circuit, new GridPoint(5, 6), new GridPoint(7, 8)));
            Assert.IsNotNull(wire1);
            Assert.IsNotNull(wire2);

            ConductorMap target = new ConductorMap(circuit);

            Assert.AreEqual(2, target.Conductors.Count());

            Conductor conductor1;

            Assert.IsTrue(target.TryGetValue(new GridPoint(3, 4), out conductor1));
            Assert.AreEqual(1, conductor1.Wires.Count());
            Assert.AreEqual(2, conductor1.Points.Count());

            Conductor conductor2;

            Assert.IsTrue(target.TryGetValue(new GridPoint(3, 4), out conductor2));
            Assert.AreEqual(1, conductor2.Wires.Count());
            Assert.AreEqual(2, conductor2.Points.Count());
        }
        public void GraphicsArrayAddressBitWidthTest()
        {
            CircuitProject project = CircuitProject.Create(null);
            GraphicsArray  target  = null;

            project.InTransaction(() => {
                target = project.GraphicsArraySet.Create(1, 1, 1, 1);
                project.CircuitSymbolSet.Create(target, project.ProjectSet.Project.LogicalCircuit, 10, 10);
            });
            Assert.IsNotNull(target);
            Assert.AreEqual(1, target.AddressBitWidth);

            Func <int, int, int, int, int> abw = (int dataBitWidth, int bpp, int w, int h) => {
                project.InTransaction(() => {
                    target.DataBitWidth = dataBitWidth;
                    target.BitsPerPixel = bpp;
                    target.Width        = w;
                    target.Height       = h;
                });
                return(target.AddressBitWidth);
            };

            Assert.AreEqual(5, abw(8, 1, 10, 10));
            Assert.AreEqual(7, abw(1, 1, 10, 10));
            Assert.AreEqual(10, abw(1, 8, 10, 10));
            Assert.AreEqual(13, abw(8, 1, 320, 200));
            Assert.AreEqual(15, abw(8, 4, 320, 200));
            Assert.AreEqual(16, abw(8, 8, 320, 200));
            Assert.AreEqual(19, abw(8, GraphicsArray.MaxBitsPerPixel, GraphicsArray.MaxWidth, GraphicsArray.MaxHeight));
            Assert.AreEqual(22, abw(1, GraphicsArray.MaxBitsPerPixel, GraphicsArray.MaxWidth, GraphicsArray.MaxHeight));
        }
        public void ConductorMapEmptyTest()
        {
            CircuitProject project = CircuitProject.Create(null);
            LogicalCircuit circuit = project.ProjectSet.Project.LogicalCircuit;
            ConductorMap   target  = new ConductorMap(circuit);

            Assert.AreEqual(0, target.Conductors.Count());
        }
Пример #7
0
        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 ConductorMapOneWireTest()
        {
            CircuitProject project = CircuitProject.Create(null);
            LogicalCircuit circuit = project.ProjectSet.Project.LogicalCircuit;
            Wire           wire    = null;

            project.InTransaction(() => wire = project.WireSet.Create(circuit, new GridPoint(1, 2), new GridPoint(3, 4)));
            Assert.IsNotNull(wire);
            ConductorMap target = new ConductorMap(circuit);

            Assert.AreEqual(1, target.Conductors.Count());
            Conductor conductor;
            bool      success = target.TryGetValue(new GridPoint(3, 4), out conductor);

            Assert.IsTrue(success);
            Assert.AreEqual(1, conductor.Wires.Count());
            Assert.AreSame(wire, conductor.Wires.First());
        }