Sha256: 9d9099581efbf2e3a64127a388c4255692e8bf174e107902d651e1adde877d64

Contents?: true

Size: 1.76 KB

Versions: 64

Compression:

Stored size: 1.76 KB

Contents

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;

[TestFixture]
public class AccumulateTest
{
    [Test]
    public void Empty_accumulation_produces_empty_accumulation()
    {
        Assert.That(new int[0].Accumulate(x => x * x), Is.EqualTo(new int[0]));
    }

    [Ignore("Remove to run test")]
    [Test]
    public void Accumulate_squares()
    {
        Assert.That(new[] { 1, 2, 3 }.Accumulate(x => x * x), Is.EqualTo(new[] { 1, 4, 9 }));
    }

    [Ignore("Remove to run test")]
    [Test]
    public void Accumulate_upcases()
    {
        Assert.That(new List<string> { "hello", "world" }.Accumulate(x => x.ToUpper()),
            Is.EqualTo(new List<string> { "HELLO", "WORLD" }));
    }

    [Ignore("Remove to run test")]
    [Test]
    public void Accumulate_reversed_strings()
    {
        Assert.That("the quick brown fox etc".Split(' ').Accumulate(Reverse),
            Is.EqualTo("eht kciuq nworb xof cte".Split(' ')));
    }

    private static string Reverse(string value)
    {
        var array = value.ToCharArray();
        Array.Reverse(array);
        return new string(array);
    }

    [Ignore("Remove to run test")]
    [Test]
    public void Accumulate_within_accumulate()
    {
        var actual = new[] { "a", "b", "c" }.Accumulate(c =>
            string.Join(" ", new[] { "1", "2", "3" }.Accumulate(d => c + d)));
        Assert.That(actual, Is.EqualTo(new[] { "a1 a2 a3", "b1 b2 b3", "c1 c2 c3" }));
    }

    [Ignore("Remove to run test")]
    [Test]
    public void Accumulate_is_lazy()
    {
        var counter = 0;
        var accumulation = new[] { 1, 2, 3 }.Accumulate(x => x * counter++);

        Assert.That(counter, Is.EqualTo(0));
        accumulation.ToList();
        Assert.That(counter, Is.EqualTo(3));
    }
}

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
trackler-2.0.6.8 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.6.7 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.6.6 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.6.5 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.6.4 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.6.3 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.6.2 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.6.1 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.6.0 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.5.18 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.5.17 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.5.16 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.5.15 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.5.14 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.5.13 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.5.12 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.5.11 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.5.10 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.5.9 tracks/csharp/exercises/accumulate/AccumulateTest.cs
trackler-2.0.5.8 tracks/csharp/exercises/accumulate/AccumulateTest.cs