Saturday, May 26, 2012

Array.ConvertAll shows off the power of delegates.

I wonder if the Visitor Pattern more or less works in this manner. TryToGiveGermanNameForSingleDigit below is the same thing it is here save for the the method is public instead of private. This test passes:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Whatever.Models;
namespace Whatever.Tests
{
   [TestClass]
   public class ConvertAllTests
   {
      [TestMethod]
      public void Test()
      {
         Int16[] digits = new Int16[] {2, 7, 8, 9};
         string[] conversion = Array.ConvertAll(digits,
               Foo.TryToGiveGermanNameForSingleDigit);
         Assert.AreEqual(conversion.Length, 4);
         Assert.AreEqual(conversion[0], "zwei");
         Assert.AreEqual(conversion[1], "sieben");
         Assert.AreEqual(conversion[2], "acht");
         Assert.AreEqual(conversion[3], "neun");
      }
   }
}

No comments:

Post a Comment