Exemplo n.º 1
0
Test_IFilter_To_sink()
{
    IStream< int > stream = Stream.Create( 1, 2, 3, 999, 999 );
    IFilter< int, int > f;
    ISink< int > sink;
    ICollection< int > c = new List< int >();

    Print( "Basic behaviour" );
    c.Clear();
    f = Filter.Create< int, int >( DoubleUp3FilterIterator );
    sink = f.To( c.AsSink() );
    while( sink.TryPush( stream.Pull() ) );
    Assert(
        c.SequenceEqual(
            new int[] { 1, 1, 2, 2, 3, 3 } ) );

    Print( "Immediate empty to sink on connect" );
    c.Clear();
    f = Filter.Create< int, int >( DoubleUp3FilterIterator );
    f.Give( 1 );
    sink = f.To( c.AsSink() );
    Assert(
        c.SequenceEqual(
            new int[] { 1, 1 } ) );
}
Exemplo n.º 2
0
Test_TextLineSplitter()
{
    Print( "Pull" );
    Assert(
        "\nline1\nline2\rline3\r\nline4\r\rline6\n\nline8\nline9"
            .AsStream()
            .To( new TextLineSplitter() )
            .SequenceEqual(
                Stream.Create(
                    "", "line1", "line2", "line3", "line4", "", "line6", "",
                    "line8", "line9" ) ) );
    Print( "Push" );
    var lines = new List< string >();
    var sink =
        new TextLineSplitter()
        .To( lines.AsSink() );
    "\nline1\nline2\rline3\r\nline4\r\rline6\n\nline8\nline9"
        .AsStream()
        .EmptyTo( sink );
    sink.Dispose();
    Assert(
        lines
            .AsStream()
            .SequenceEqual(
                Stream.Create(
                    "", "line1", "line2", "line3", "line4", "", "line6", "",
                    "line8", "line9" ) ) );
}
Exemplo n.º 3
0
Test_SystemCollection_AsSink()
{
    IEnumerable< int > from = new int[] { 1, 2, 3 };
    ICollection< int > to = new List< int >();
    from.AsStream().EmptyTo(
        to.AsSink() );
    Assert( to.SequenceEqual( from ) );
}