Exemplo n.º 1
0
        public void DoesSimulateWork()
        {
            InputUnit input = new InputUnit();
            Not       not   = new Not();
            Bus       bus   = new Bus(input, not);

            not.AddInput(bus);
            input.AddOutput(bus);

            not.Simulate();
            Assert.AreEqual(0, not.nextState);
        }
Exemplo n.º 2
0
        private void btnSimulate2_Click(object sender, EventArgs e)
        {
            InputUnit  input1 = new InputUnit();
            InputUnit  input2 = new InputUnit();
            Or         gate1  = new Or();
            Not        gate2  = new Not();
            OutputUnit output = new OutputUnit();
            Bus        bus1   = new Bus(input1, gate1);
            Bus        bus2   = new Bus(input2, gate1);
            Bus        bus3   = new Bus(gate1, gate2);
            Bus        bus4   = new Bus(gate2, output);

            gate1.AddInput(bus1, bus2);
            gate2.AddInput(bus3);
            gate1.AddOutput(bus3);
            gate2.AddOutput(bus4);
            input1.AddOutput(bus1);
            input2.AddOutput(bus2);
            output.AddInput(bus4);
            Circuit circuit = new Circuit();

            circuit.AddGates(gate1, gate2, input1, input2, output);
            circuit.AddBuses(bus1, bus2, bus3, bus4);
            if (circuit.IsValid())
            {
                circuit.Simulate();
                if (output.currentState == 1)
                {
                    picOutput2.ImageLocation = @"..\..\src\GUI\Images\OnBulb.jpg";
                }
                else
                {
                    picOutput2.ImageLocation = @"..\..\src\GUI\Images\OffBulb.jpg";
                }
            }
            else
            {
                picOutput2.ImageLocation = @"..\..\src\GUI\Images\InvalidCircuit.png";
            }
        }
Exemplo n.º 3
0
 public void IsNotValidWithOneInputAndNoOutput()
 {
     not.AddInput(GetBusInstance());
     Assert.IsFalse(not.IsValid());
 }