コード例 #1
0
ファイル: OutputUnitTest.cs プロジェクト: gsp789/Projects
        public void DoesSimulateWork()
        {
            InputUnit  input  = new InputUnit();
            And        and    = new And();
            OutputUnit output = new OutputUnit();
            Bus        bus1   = new Bus(input, and, and);
            Bus        bus2   = new Bus(and, output);

            and.AddInput(bus1, bus1);
            and.AddOutput(bus2);
            output.AddInput(bus2);
            input.AddOutput(bus1);

            output.Simulate();
            Assert.AreEqual(1, output.nextState);
        }
コード例 #2
0
        private void btnSimulate1_Click(object sender, EventArgs e)
        {
            InputUnit  input1 = new InputUnit();
            InputUnit  input2 = new InputUnit();
            InputUnit  input3 = new InputUnit();
            And        gate1  = new And();
            And        gate2  = new And();
            OutputUnit output = new OutputUnit();
            Bus        bus1   = new Bus(input1, gate1);
            Bus        bus2   = new Bus(input2, gate1);
            Bus        bus3   = new Bus(input3, gate2);
            Bus        bus4   = new Bus(gate1, gate2);
            Bus        bus5   = new Bus(gate2, output);

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

            circuit.AddGates(gate1, gate2, input1, input2, input3, output);
            circuit.AddBuses(bus1, bus2, bus3, bus4, bus5);
            if (circuit.IsValid())
            {
                circuit.Simulate();
                if (output.currentState == 1)
                {
                    picOutput1.ImageLocation = @"..\..\src\GUI\Images\OnBulb.jpg";
                }
                else
                {
                    picOutput1.ImageLocation = @"..\..\src\GUI\Images\OffBulb.jpg";
                }
            }
            else
            {
                picOutput1.ImageLocation = @"..\..\src\GUI\Images\InvalidCircuit.png";
            }
        }
コード例 #3
0
ファイル: OutputUnitTest.cs プロジェクト: gsp789/Projects
 public void testOutputUnitWithOutputBusConnected()
 {
     output.AddInput(new Bus(new And(), new And()));
     Assert.IsTrue(output.IsValid());
 }