public void Test_GetEnumerator()
        {
            ParallelThread.Invoke(producer);
            var result = enumerable.Aggregate((x, y) => x + y);

            Assert.AreEqual(45, result);
        }
Example #2
0
        public void Test_SlowProducer()
        {
            int result = 0;

            producer = () =>
            {
                for (int i = 0; i < 10; i++)
                {
                    pipe.Writer.Write(i);
                    Thread.Sleep(5);
                }

                pipe.Writer.Close();
            };
            consumer = () =>
            {
                int item;

                while (pipe.Reader.Read(out item))
                {
                    result += item;
                }

                doneEvent.Set();
            };

            ParallelThread.Invoke(producer, consumer);
            doneEvent.WaitOne();

            Assert.AreEqual(45, result);
        }
Example #3
0
        public void Test_ReaderClosedFirst()
        {
            int result = 0;

            producer = () =>
            {
                for (int i = 0; i < 10; i++)
                {
                    pipe.Writer.Write(i);
                }

                pipe.Writer.Close();
                doneEvent.Set();
            };
            consumer = () =>
            {
                int item;

                for (int i = 0; i < 5; i++)
                {
                    if (!pipe.Reader.Read(out item))
                    {
                        break;
                    }

                    result += item;
                }

                pipe.Reader.Close();
            };

            ParallelThread.Invoke(producer, consumer);
            doneEvent.WaitOne();

            Assert.AreEqual(10, result);
        }