예제 #1
0
        public void TestIfItCanSortAnArray()
        {
            // Arrange
            int[] data     = new int[] { 1, 4, 3, 2 };
            int[] expected = data.OrderByDescending(n => n).ToArray();
            IEnumerable <PipeNode> nodes = GetConnectedPipes(4);
            ISocket  masterRecv          = TestHelper.GetSocket();
            ISocket  masterSend          = TestHelper.GetSocket();
            PipeNode firstPipe           = nodes.ElementAt(0);

            Connect(sender: masterSend, to: firstPipe.GetReceiverFromLeft());
            Connect(sender: firstPipe.GetSenderToLeft(), to: masterRecv);
            PipeMaster master = TestHelper.GetPipeMaster(masterSend, masterRecv);

            // Act
            int count = 0;

            nodes.ToList().ForEach(n => n.Start(count++, 4));
            int[] actual = master.Sort(data);

            // Assert
            Verify.That(actual).IsEqualTo(expected).Now();

            // Reset
        }
예제 #2
0
        public void TestIfItCanStartAndEndSort()
        {
            // Arrange
            ISocket sendSocket = TestHelper.GetSocket();
            ISocket recvSocket = TestHelper.GetSocket();

            PipeMaster target = TestHelper.GetPipeMaster(sendSocket, recvSocket);

            int[] input    = new int[] { 1, 6, 3, 4, 5, 2, 7 };
            int[] expected = input.OrderBy(n => n).ToArray();
            recvSocket.SetRecvData(expected);
            int[] actual = null;

            // Act
            actual = target.Sort(input);

            // Assert
            int[] actualSentData = sendSocket.GetSentIntArray();
            Verify.That(actual).IsEqualTo(expected).Now();
            Verify.That(actualSentData).IsEqualTo(input).Now();

            // Reset
        }