Exemplo n.º 1
0
        public void Concat()
        {
            var part1 = new InputPipe <List <int> >("part1");
            var part2 = new InputPipe <int[]>("part2");
            var concatWithPipeline = part1.ConcatWith(part2);
            var collector          = concatWithPipeline.Collect();

            PipelineApprovals.Verify(concatWithPipeline);

            // begin-snippet: ConcatWith_inputs
            var concat = new List <int> {
                1, 2
            };
            var with = new[] { 3, 4 };
            // end-snippet

            // begin-snippet: ConcatWith_outputs
            var result = "[1, 2, 3, 4]";
            // end-snippet

            var manualConcatWith =
                // begin-snippet: ConcatWith_manual
                part1.JoinTo(part2).ProcessFunction(t => t.Item1.Concat(t.Item2).ToList());
            // end-snippet
            var manualConcatWithResult = manualConcatWith.Collect();

            part1.Send(concat);
            part2.Send(with);
            Assert.AreEqual(result, collector.SingleResult.ToReadableString());

            Assert.AreEqual(
                manualConcatWithResult.SingleResult.ToReadableString(),
                collector.SingleResult.ToReadableString());
        }
Exemplo n.º 2
0
        public void MultipleBranchesPipe()
        {
            var input1           = new InputPipe <int>("input1");
            var input2           = new InputPipe <int>("input2");
            var joinedPipes      = input1.JoinTo(input2);
            var sumCollector     = joinedPipes.Process((a, b) => a + b).Collect();
            var productCollector = joinedPipes.Process((a, b) => a * b).Collect();

            var inputsAndOutputs = joinedPipes.GetInputs <int, int>().AndOutputs <int, int>();

            inputsAndOutputs.Send(3, 4);
            var(in1, in2, sum, product) = inputsAndOutputs.AsTuple();


            Assert.AreEqual(7, sum.SingleResult);
            Assert.AreEqual(12, product.SingleResult);

            var(in1_, in2_) = inputsAndOutputs.Inputs;
            Assert.AreEqual(in1_, in1);
            Assert.AreEqual(in2_, in2);

            var(out1_, out2_) = inputsAndOutputs.Outputs;
            Assert.AreEqual(out1_, sum);
            Assert.AreEqual(out2_, product);
        }
Exemplo n.º 3
0
        public void ApplyTo()
        {
            var prefix = new InputPipe <string>("prefix");
            var values = new InputPipe <int[]>("values");

            var applyToPipeline = prefix.ApplyTo(values);
            var collector       = applyToPipeline.Collect();

            PipelineApprovals.Verify(applyToPipeline);

            // begin-snippet: ApplyTo_inputs
            var apply = "#";
            var to    = new[] { 1, 2 };
            // end-snippet

            // begin-snippet: ApplyTo_outputs
            var result = "[(#, 1), (#, 2)]";
            // end-snippet

            var manualApplyTo =
                // begin-snippet: ApplyTo_manual
                prefix.JoinTo(values).ProcessFunction(t => t.Item2.Select(i => Tuple.Create(t.Item1, i)));
            // end-snippet
            var manualApplyToResult = manualApplyTo.Collect();

            prefix.Send(apply);
            values.Send(to);
            Assert.AreEqual(result, collector.SingleResult.ToReadableString());

            Assert.AreEqual(
                manualApplyToResult.SingleResult.ToReadableString(),
                collector.SingleResult.ToReadableString());
        }
Exemplo n.º 4
0
        public void JoinInputsSample()
        {
            // begin-snippet: joined_pipeline
            var input1 = new InputPipe <long>("value1");
            var input2 = new InputPipe <long>("value2");
            var join   = input1.JoinTo(input2);

            // end-snippet

            PipelineApprovals.Verify(join);
        }
Exemplo n.º 5
0
        public void MultipleParameters()
        {
            var input1    = new InputPipe <long>("value1");
            var input2    = new InputPipe <long>("value2");
            var join      = input1.JoinTo(input2);
            var collector = join.Process((a, b) => a + b).Collect();

            input1.Send(3);
            Assert.IsTrue(collector.IsEmpty);

            input2.Send(4);
            Assert.AreEqual(7, collector.SingleResult);

            PipelineApprovals.Verify(join);
        }
Exemplo n.º 6
0
        public void JoinInputs()
        {
            var input1    = new InputPipe <long>("value1");
            var input2    = new InputPipe <long>("value2");
            var join      = input1.JoinTo(input2);
            var collector = join.ProcessFunction(Echo).Collect();

            input1.Send(42);
            Assert.IsTrue(collector.IsEmpty);

            input2.Send(99);
            Assert.AreEqual("(42, 99)", collector.SingleResult.ToString());

            PipelineApprovals.Verify(join);
        }
Exemplo n.º 7
0
        public void JoinInputs()
        {
            var input1    = new InputPipe <long>("value1");
            var input2    = new InputPipe <long>("value2");
            var join      = input1.JoinTo(input2);
            var collector = join.Collect();

            input1.Send(42);
            Assert.IsTrue(collector.IsEmpty);

            input2.Send(99);
            Assert.AreEqual("(42, 99)", collector.SingleResult.ToString());

            // TODO:
            //Verify(join);
        }
Exemplo n.º 8
0
        public void MultipleBranchesPipe()
        {
            var input1           = new InputPipe <int>("input1");
            var input2           = new InputPipe <int>("input2");
            var joinedPipes      = input1.JoinTo(input2);
            var sumCollector     = joinedPipes.Process((a, b) => a + b).Collect();
            var productCollector = joinedPipes.Process((a, b) => a * b).Collect();

            var inputsAndOutputs = joinedPipes.GetInputsAndOutputs();

            ((InputPipe <int>)inputsAndOutputs.Inputs[0]).Send(3);
            ((InputPipe <int>)inputsAndOutputs.Inputs[1]).Send(4);

            Assert.AreEqual(7, ((CollectorPipe <int>)inputsAndOutputs.Outputs[0]).SingleResult);
            Assert.AreEqual(12, ((CollectorPipe <int>)inputsAndOutputs.Outputs[1]).SingleResult);
        }
Exemplo n.º 9
0
        public void Flatten()
        {
            var input1 = new InputPipe <long>("value1");
            var input2 = new InputPipe <long>("value2");
            var join   = input1.JoinTo(input2);
            var input3 = new InputPipe <long>("value3");

            Sender <Tuple <long, long, long> > all = join.JoinTo(input3).Flatten();
            var collector = all.Collect();

            input1.Send(1);
            input2.Send(2);
            input3.Send(3);

            Assert.AreEqual("(1, 2, 3)", collector.SingleResult.ToString());

            PipelineApprovals.Verify(collector);
        }