示例#1
0
        public OscillatorTest()
        {
            _oscillator10Hz = new Oscillator(50);
            _startPower     = new PowerSupplier();

            _oscillator10Hz.Start.ConnectTo(_startPower.Output);
        }
示例#2
0
        public void InvertRelayWithContactInput()
        {
            PowerSupplier  power1 = new PowerSupplier();
            PowerSupplier  power2 = new PowerSupplier();
            IndicatorLight light  = new IndicatorLight();
            Relay          relay  = new Relay(invert: true);

            relay.Input.ConnectTo(power1.Output);
            relay.InputOfContact.ConnectTo(power2.Output);
            relay.Output.ConnectTo(light.Input);

            Assert.IsFalse(light.Lighting);
            power1.On();
            power2.Off();
            Assert.IsFalse(light.Lighting);
            power1.On();
            power2.On();
            Assert.IsFalse(light.Lighting);
            power1.Off();
            power2.On();
            Assert.IsTrue(light.Lighting);
            power1.Off();
            power2.Off();
            Assert.IsFalse(light.Lighting);
        }
示例#3
0
        public void NOR()
        {
            PowerSupplier  power1  = new PowerSupplier();
            PowerSupplier  power2  = new PowerSupplier();
            NORGate        norGate = new NORGate();
            IndicatorLight light   = new IndicatorLight();

            norGate.Output.ConnectTo(light.Input);
            Assert.IsTrue(light.Lighting);

            norGate.Input1.ConnectTo(power1.Output);
            norGate.Input2.ConnectTo(power2.Output);
            Assert.IsTrue(light.Lighting);

            power1.On();
            power2.Off();
            Assert.IsFalse(light.Lighting);
            power1.Off();
            power2.On();
            Assert.IsFalse(light.Lighting);
            power1.On();
            power2.On();
            Assert.IsFalse(light.Lighting);
            power1.Off();
            power2.Off();
            Assert.IsTrue(light.Lighting);
        }
示例#4
0
        private void Init16BitsComplementor()
        {
            _cplmtor16   = new Complementor16Bits();
            _switches16  = new Switches(16);
            _invertPwr16 = new PowerSupplier();
            InitResult16BitsLights();

            _cplmtor16.Inputs.Connect(_switches16.Outputs);
            _cplmtor16.Invert.ConnectTo(_invertPwr16.Output);
            _cplmtor16.Outputs.Connect(_resultLights16.Select(l => l.Input as InputEndpoint));
        }
示例#5
0
        private void Init8BitsComplementor()
        {
            _cplmtor8  = new Complementor8Bits();
            _switches8 = new Switches(8);
            _invertPwr = new PowerSupplier();
            InitResult8BitsLights();

            _cplmtor8.Inputs.Connect(_switches8.Outputs);
            _cplmtor8.Invert.ConnectTo(_invertPwr.Output);
            _cplmtor8.Outputs.Connect(_resultLights8.Select(l => l.Input as InputEndpoint));
        }
示例#6
0
        public FlipFlopTest()
        {
            _powerSet   = new PowerSupplier();
            _powerClear = new PowerSupplier();
            _light      = new IndicatorLight();
            _flipFlop   = new FlipFlop();

            _flipFlop.Set.ConnectTo(_powerSet.Output);
            _flipFlop.Clear.ConnectTo(_powerClear.Output);
            _flipFlop.Output.ConnectTo(_light.Input);
        }
示例#7
0
        private void Init16BitsTest()
        {
            _16BitsNumber1Switches = new Switches(16);
            _16BitsNumber2Switches = new Switches(16);
            Init16BitsLights();
            _carryInPowerFor16Bits  = new PowerSupplier();
            _carryOutLightFor16Bits = new IndicatorLight();

            _16BitsAdder = new Adder16Bits();

            _16BitsAdder.Number1Inputs.Connect(_16BitsNumber1Switches.Outputs);
            _16BitsAdder.Number2Inputs.Connect(_16BitsNumber2Switches.Outputs);
            _16BitsAdder.CarryInput.ConnectTo(_carryInPowerFor16Bits.Output);
            _16BitsAdder.SumOutputs.Connect(_16BitsSumLights.Select(l => l.Input as InputEndpoint));
            _16BitsAdder.CarryOutput.ConnectTo(_carryOutLightFor16Bits.Input);
        }
示例#8
0
        public void InvertRelay()
        {
            PowerSupplier  power = new PowerSupplier();
            IndicatorLight light = new IndicatorLight();
            Relay          relay = new Relay(invert: true);

            relay.Input.ConnectTo(power.Output);
            relay.Output.ConnectTo(light.Input);

            power.On();
            Assert.IsFalse(light.Lighting);
            power.Off();
            Assert.IsTrue(light.Lighting);
            power.Toggle();
            Assert.IsFalse(light.Lighting);
            power.Toggle();
            Assert.IsTrue(light.Lighting);
        }
示例#9
0
        public void DefaultInvertor()
        {
            PowerSupplier  power    = new PowerSupplier();
            IndicatorLight light    = new IndicatorLight();
            Invertor       invertor = new Invertor();

            invertor.Input.ConnectTo(power.Output);
            invertor.Output.ConnectTo(light.Input);

            power.On();
            Assert.IsFalse(light.Lighting);
            power.Off();
            Assert.IsTrue(light.Lighting);
            power.Toggle();
            Assert.IsFalse(light.Lighting);
            power.Toggle();
            Assert.IsTrue(light.Lighting);
        }
示例#10
0
        public void Delayer999Milliseconds()
        {
            Int32          delayMilliseconds = 999;
            PowerSupplier  power             = new PowerSupplier();
            Delayer        delayer           = new Delayer(delayMilliseconds);
            IInputEndpoint input             = new InputEndpoint();
            Stopwatch      timer             = new Stopwatch();

            input.Receive += (s, sg) => { if (sg == 1)
                                          {
                                              timer.Stop();
                                          }
            };

            delayer.Input.ConnectTo(power.Output);
            delayer.Output.ConnectTo(input);

            timer.Start();
            power.On();

            var deltaMilliseconds = Math.Abs(timer.ElapsedMilliseconds - delayMilliseconds);

            Assert.IsTrue(deltaMilliseconds <= 2);
        }
示例#11
0
        public void DelayRelay()
        {
            Int32         delayMilliseconds = 50;
            PowerSupplier power             = new PowerSupplier();
            Relay         relay             = new Relay(delayMilliseconds: delayMilliseconds);
            InputEndpoint input             = new InputEndpoint();
            Stopwatch     timer             = new Stopwatch();

            input.Receive += (s, sg) => { if (sg == 1)
                                          {
                                              timer.Stop();
                                          }
            };

            relay.Input.ConnectTo(power.Output);
            relay.Output.ConnectTo(input);

            timer.Start();
            power.On();

            var deltaMilliseconds = Math.Abs(timer.ElapsedMilliseconds - delayMilliseconds);

            Assert.IsTrue(deltaMilliseconds <= 1);
        }
示例#12
0
        public void Oscillate25HzOnTime()
        {
            IOscillator   oscillator = new Oscillator(20);
            PowerSupplier power      = new PowerSupplier();

            power.Output.ConnectTo(oscillator.Start);

            _count = 0;
            Boolean        oscillating = false;
            IInputEndpoint input       = new InputEndpoint();

            input.ConnectTo(oscillator.Output);
            input.Receive += (sd, sgn) =>
            {
                Thread.Sleep(1);
                if ((Int32)_count >= 5)
                {
                    _startPower.Off();
                }
                else
                {
                    _count = (Int32)_count + 1;
                }
            };

            ThreadHelper.ExecuteThenSleepShortly(() => power.On(), 200);
            Assert.AreEqual(_count, 5);

            _count = 0;
            ThreadHelper.ExecuteThenSleepShortly(() => power.On(), 100);
            Assert.AreEqual(_count, 5);

            _count = 0;
            ThreadHelper.ExecuteThenSleepShortly(() => power.On(), 40);
            Assert.IsTrue((Int32)_count < 5);
        }
示例#13
0
        public void MultiOR()
        {
            PowerSupplier power1   = new PowerSupplier();
            PowerSupplier power2   = new PowerSupplier();
            PowerSupplier power3   = new PowerSupplier();
            PowerSupplier power4   = new PowerSupplier();
            PowerSupplier power5   = new PowerSupplier();
            MultiORGate   mtORGate = new MultiORGate(5);

            mtORGate.ConnectInputsWith(power1.Output, power2.Output, power3.Output, power4.Output, power5.Output);
            IndicatorLight light = new IndicatorLight();

            mtORGate.Output.ConnectTo(light.Input);
            Assert.IsFalse(light.Lighting);

            power1.On();
            power2.Off();
            power3.Off();
            power4.Off();
            power5.Off();
            Assert.IsTrue(light.Lighting);
            power1.On();
            power2.On();
            power3.Off();
            power4.Off();
            power5.Off();
            Assert.IsTrue(light.Lighting);
            power1.On();
            power2.On();
            power3.On();
            power4.Off();
            power5.Off();
            Assert.IsTrue(light.Lighting);
            power1.On();
            power2.On();
            power3.On();
            power4.On();
            power5.Off();
            Assert.IsTrue(light.Lighting);
            power1.On();
            power2.On();
            power3.On();
            power4.On();
            power5.On();
            Assert.IsTrue(light.Lighting);
            power1.Off();
            power2.On();
            power3.Off();
            power4.Off();
            power5.Off();
            Assert.IsTrue(light.Lighting);
            power1.Off();
            power2.On();
            power3.On();
            power4.Off();
            power5.Off();
            Assert.IsTrue(light.Lighting);
            power1.Off();
            power2.On();
            power3.On();
            power4.On();
            power5.Off();
            Assert.IsTrue(light.Lighting);
            power1.Off();
            power2.On();
            power3.On();
            power4.On();
            power5.On();
            Assert.IsTrue(light.Lighting);
            power1.Off();
            power2.Off();
            power3.On();
            power4.Off();
            power5.Off();
            Assert.IsTrue(light.Lighting);
            power1.Off();
            power2.Off();
            power3.On();
            power4.On();
            power5.Off();
            Assert.IsTrue(light.Lighting);
            power1.Off();
            power2.Off();
            power3.On();
            power4.On();
            power5.On();
            Assert.IsTrue(light.Lighting);
            power1.Off();
            power2.Off();
            power3.Off();
            power4.On();
            power5.Off();
            Assert.IsTrue(light.Lighting);
            power1.Off();
            power2.Off();
            power3.Off();
            power4.On();
            power5.On();
            Assert.IsTrue(light.Lighting);
            power1.Off();
            power2.Off();
            power3.Off();
            power4.Off();
            power5.On();
            Assert.IsTrue(light.Lighting);
            power1.Off();
            power2.Off();
            power3.Off();
            power4.Off();
            power5.Off();
            Assert.IsFalse(light.Lighting);
        }