示例#1
0
        public void ChargeTheNeutralThenConnectInputOrNuetral()
        {
            IInputEndpoint input          = new InputEndpoint();
            Int32          receivedSignal = 0;

            input.Receive += (sender, signal) =>
            {
                receivedSignal = signal;
            };
            INeutralEndpoint neutral = new NeutralEndpoint();
            Int32            neutralReceivedSignal = 0;

            neutral.Receive += (sender, signal) =>
            {
                neutralReceivedSignal = signal;
            };
            INeutralEndpoint neutralOut = new NeutralEndpoint();

            neutralOut.Produce(1);
            Assert.AreEqual(receivedSignal, 0);
            Assert.AreEqual(neutralReceivedSignal, 0);

            neutralOut.ConnectTo(input);
            Assert.AreEqual(receivedSignal, 1);
            Assert.AreEqual(neutralReceivedSignal, 0);

            neutralOut.ConnectTo(neutral);
            Assert.AreEqual(receivedSignal, 0);
            Assert.AreEqual(neutralReceivedSignal, 1);
        }
示例#2
0
        public void NeutralEndpointProduceToOutputWithNoResult()
        {
            IOutputEndpoint  output  = new OutputEndpoint();
            INeutralEndpoint neutral = new NeutralEndpoint(output);

            neutral.Produce(1);
        }
示例#3
0
        public void inputConnectToTheSameNeutralMoreThanOneTime()
        {
            IInputEndpoint input     = new InputEndpoint();
            Int32          callTimes = 0;

            input.Receive += (sender, signal) =>
            {
                callTimes++;
            };
            INeutralEndpoint neutral = new NeutralEndpoint();

            input.ConnectTo(neutral);
            Assert.AreEqual(callTimes, 1);

            input.ConnectTo(neutral);
            Assert.AreEqual(callTimes, 1);

            neutral.ConnectTo(input);
            Assert.AreEqual(callTimes, 1);

            neutral.ConnectTo(input);
            Assert.AreEqual(callTimes, 1);

            input.ConnectTo(neutral);
            Assert.AreEqual(callTimes, 1);

            neutral.ConnectTo(input);
            Assert.AreEqual(callTimes, 1);
        }
示例#4
0
        public void SendSignalBackAndForth()
        {
            INeutralEndpoint nuetral1        = new NeutralEndpoint();
            Int32            receivedSignal1 = 0;
            IEndpoint        senderPoint1    = null;

            nuetral1.Receive += (sdr, signal) =>
            {
                senderPoint1    = sdr;
                receivedSignal1 = signal;
            };

            INeutralEndpoint nuetral2        = new NeutralEndpoint();
            Int32            receivedSignal2 = 0;
            IEndpoint        senderPoint2    = null;

            nuetral2.Receive += (sdr, signal) =>
            {
                senderPoint2    = sdr;
                receivedSignal2 = signal;
            };

            Wire wire = new Wire(nuetral1, nuetral2);

            nuetral1.Produce(1);
            Assert.AreEqual(receivedSignal1, 0);
            Assert.AreEqual(receivedSignal2, 1);

            nuetral2.Produce(1);
            Assert.AreEqual(receivedSignal1, 1);
            Assert.AreEqual(receivedSignal2, 1);
        }
示例#5
0
        public void SendSignal()
        {
            IInputEndpoint input       = new InputEndpoint();
            Int32          inputSignal = 0;

            input.Receive += (sender, signal) => { inputSignal = signal; };
            IOutputEndpoint  output1       = new OutputEndpoint();
            IOutputEndpoint  output2       = new OutputEndpoint();
            INeutralEndpoint netrual       = new NeutralEndpoint();
            Int32            netrualSignal = 0;

            netrual.Receive += (sender, signal) => { netrualSignal = signal; };

            Nexus nexus = new Nexus(6, input, output1, output2, netrual);

            output1.Produce(1);
            Assert.AreEqual(inputSignal, 1);
            Assert.AreEqual(netrualSignal, 1);
            output2.Produce(0);
            Assert.AreEqual(inputSignal, 1);
            Assert.AreEqual(netrualSignal, 1);
            output1.Produce(0);
            Assert.AreEqual(inputSignal, 0);
            Assert.AreEqual(netrualSignal, 0);
            netrual.Produce(1);
            Assert.AreEqual(inputSignal, 1);
            Assert.AreEqual(netrualSignal, 0);
        }
示例#6
0
        public void CreateNewNeutralPointWithConnectPoint()
        {
            INeutralEndpoint nuetral1 = new NeutralEndpoint();
            INeutralEndpoint neutral2 = new NeutralEndpoint(nuetral1);

            Assert.IsNotNull(nuetral1.ConnectedPoint);
            Assert.IsNotNull(neutral2.ConnectedPoint);
            Assert.AreSame(nuetral1.ConnectedPoint, neutral2);
            Assert.AreSame(neutral2.ConnectedPoint, nuetral1);
        }
示例#7
0
        public void CreateNewEndpoint()
        {
            IInputEndpoint   input   = new InputEndpoint();
            IOutputEndpoint  output  = new OutputEndpoint();
            INeutralEndpoint neutral = new NeutralEndpoint();

            Assert.IsNotNull(input);
            Assert.IsNotNull(output);
            Assert.IsNotNull(neutral);
        }
示例#8
0
        public void CreateNewWithInsufficientConnectionPoints()
        {
            IInputEndpoint   input   = new InputEndpoint();
            IOutputEndpoint  output  = new OutputEndpoint();
            INeutralEndpoint netrual = new NeutralEndpoint();

            Nexus nexus = new Nexus(6, input, output, netrual);

            Assert.IsNotNull(nexus);
        }
示例#9
0
        public void NeutralEndpointTransimit()
        {
            INeutralEndpoint newtral        = new NeutralEndpoint();
            Int32            receivedSignal = 0;

            newtral.Receive += (sender, signal) =>
            {
                receivedSignal = signal;
            };
            newtral.Transmit(1);

            Assert.AreEqual(receivedSignal, 1);
        }
示例#10
0
        public void CreateNewWithExcessiveConnectionPoints()
        {
            IInputEndpoint   input1   = new InputEndpoint();
            IInputEndpoint   input2   = new InputEndpoint();
            IOutputEndpoint  output1  = new OutputEndpoint();
            IOutputEndpoint  output2  = new OutputEndpoint();
            INeutralEndpoint netrual1 = new NeutralEndpoint();
            INeutralEndpoint netrual2 = new NeutralEndpoint();

            Nexus nexus = new Nexus(3, input1, input2, output1, output2, netrual1, netrual2);

            Assert.IsNotNull(nexus);
        }
示例#11
0
        public void CreateNew()
        {
            IInputEndpoint   input1   = new InputEndpoint();
            IInputEndpoint   input2   = new InputEndpoint();
            IOutputEndpoint  output1  = new OutputEndpoint();
            IOutputEndpoint  output2  = new OutputEndpoint();
            INeutralEndpoint netrual1 = new NeutralEndpoint();
            INeutralEndpoint netrual2 = new NeutralEndpoint();

            Nexus nexus = new Nexus(6, input1, input2, output1, output2, netrual1, netrual2);

            Assert.IsNotNull(nexus);
        }
示例#12
0
        public void NeutralEndpointProduceToNeutral()
        {
            INeutralEndpoint neutral1       = new NeutralEndpoint();
            Int32            receivedSignal = 0;

            neutral1.Receive += (sender, signal) =>
            {
                receivedSignal = signal;
            };
            INeutralEndpoint neutral2 = new NeutralEndpoint(neutral1);

            neutral2.Produce(1);

            Assert.AreEqual(receivedSignal, 1);
        }
示例#13
0
        public void OutputEndpointProduceToNeutral()
        {
            INeutralEndpoint neutral        = new NeutralEndpoint();
            Int32            receivedSignal = 0;

            neutral.Receive += (sender, signal) =>
            {
                receivedSignal = signal;
            };
            IOutputEndpoint output = new OutputEndpoint(neutral);

            output.Produce(1);

            Assert.AreEqual(receivedSignal, 1);
        }
示例#14
0
        public void NeutralEndpointProduceToInput()
        {
            IInputEndpoint input          = new InputEndpoint();
            Int32          receivedSignal = 0;

            input.Receive += (sender, signal) =>
            {
                receivedSignal = signal;
            };
            INeutralEndpoint neutral = new NeutralEndpoint(input);

            neutral.Produce(1);

            Assert.AreEqual(receivedSignal, 1);
        }
示例#15
0
        public void NeutralEndpointRecordLastReceivedSignal()
        {
            INeutralEndpoint neutral1       = new NeutralEndpoint();
            Int32            receivedSignal = 0;

            neutral1.Receive += (sender, signal) =>
            {
                receivedSignal = signal;
            };
            neutral1.Transmit(1);
            Assert.AreEqual(neutral1.LastReceivedSignal, 1);
            neutral1.Transmit(0);
            Assert.AreEqual(neutral1.LastReceivedSignal, 0);

            INeutralEndpoint neutral2 = new NeutralEndpoint();

            neutral2.Transmit(1);
            Assert.AreEqual(neutral2.LastReceivedSignal, 1);
            neutral2.Transmit(0);
            Assert.AreEqual(neutral2.LastReceivedSignal, 0);
        }
示例#16
0
        public void ConnectPostCreating()
        {
            IInputEndpoint input1       = new InputEndpoint();
            Int32          inputSignal1 = 0;

            input1.Receive += (sender, signal) => { inputSignal1 = signal; };
            IInputEndpoint input2       = new InputEndpoint();
            Int32          inputSignal2 = 0;

            input2.Receive += (sender, signal) => { inputSignal2 = signal; };
            IOutputEndpoint  output  = new OutputEndpoint();
            INeutralEndpoint netrual = new NeutralEndpoint();

            Nexus nexus = new Nexus(6, input1, output, netrual);

            output.Produce(1);
            Assert.AreEqual(inputSignal1, 1);
            Assert.AreEqual(inputSignal2, 0);

            nexus.ConnectAt(input2, 3);
            Assert.AreEqual(inputSignal1, 1);
            Assert.AreEqual(inputSignal2, 1);
        }
示例#17
0
        public void CreateDifferentPointWithConnectPoint()
        {
            IInputEndpoint   input1   = new InputEndpoint();
            IOutputEndpoint  output1  = new OutputEndpoint();
            INeutralEndpoint nuetral1 = new NeutralEndpoint();

            IInputEndpoint   input2   = new InputEndpoint(output1);
            IOutputEndpoint  output2  = new OutputEndpoint(nuetral1);
            INeutralEndpoint neutral2 = new NeutralEndpoint(input1);

            Assert.IsNotNull(input1.ConnectedPoint);
            Assert.IsNotNull(input2.ConnectedPoint);
            Assert.IsNotNull(output1.ConnectedPoint);
            Assert.IsNotNull(output2.ConnectedPoint);
            Assert.IsNotNull(nuetral1.ConnectedPoint);
            Assert.IsNotNull(neutral2.ConnectedPoint);

            Assert.AreSame(input1.ConnectedPoint, neutral2);
            Assert.AreSame(neutral2.ConnectedPoint, input1);
            Assert.AreSame(output1.ConnectedPoint, input2);
            Assert.AreSame(input2.ConnectedPoint, output1);
            Assert.AreSame(nuetral1.ConnectedPoint, output2);
            Assert.AreSame(output2.ConnectedPoint, nuetral1);
        }
示例#18
0
        public void NeutralProduceInvalidSignal255()
        {
            INeutralEndpoint neutral = new NeutralEndpoint();

            neutral.Produce(255);
        }
示例#19
0
        public void NeutralTransmitInvalidSignal255()
        {
            INeutralEndpoint neutral = new NeutralEndpoint();

            neutral.Transmit(255);
        }
示例#20
0
        public void NeutralEndpointConnectToSelf()
        {
            INeutralEndpoint point = new NeutralEndpoint();

            point.ConnectTo(point);
        }
示例#21
0
        public void NeutralEndpointTransimitWithoutHandler()
        {
            INeutralEndpoint neutral = new NeutralEndpoint();

            neutral.Transmit(1);
        }