Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        private void TestFunction(Func <CircuitState, int[], int, CircuitFunction> create, Func <CircuitState, int[], int, bool> isValid)
        {
            for (int count = 1; count <= 12; count++)
            {
                CircuitState state  = new CircuitState(3);
                int          result = state.ReserveState();
                int[]        param  = new int[count];
                for (int i = 0; i < param.Length; i++)
                {
                    param[i] = state.ReserveState();
                }
                CircuitFunction func        = create(state, param, result);
                bool            canContinue = true;
                while (canContinue)
                {
                    func.Evaluate();
                    Assert.IsTrue(isValid(state, param, result));
                    for (int i = param.Length - 1; canContinue = (0 <= i); i--)
                    {
                        switch (state[param[i]])
                        {
                        case State.Off:
                            state[param[i]] = State.On0;
                            break;

                        case State.On0:
                            state[param[i]] = State.On1;
                            break;

                        case State.On1:
                            state[param[i]] = State.Off;
                            break;
                        }
                        if (state[param[i]] != State.Off)
                        {
                            break;
                        }
                    }
                }
            }
        }