2009-05-19: Coding Dojo Results

Thanks to everyone that came out to the coding dojo; especially anyone who did some codin’!

It was the first time doing this for everyone and I thought we did rather well. We ended up with some pretty slick C# code for parsing Roman numerals:

using System;

namespace RomanNumeralsCodingDojo
{
  public class RomanNumerals
  {
    public long Value { get; private set; }

    public RomanNumerals(string value)
    {
      for (var i = 0; i < value.Length-1; i++)
      {
        var charValue = Parse(value[i]);
        var nextCharValue = Parse(value[i+1]);

        if (charValue >= nextCharValue)
          Value += charValue;
        else
          Value -= charValue;
      }
      Value += Parse(value[value.Length-1]);
    }

    private static int Parse(char romanCharacter)
    {
      return (int) Enum.Parse(typeof (RomanCharacters),
                        new string(new [] {romanCharacter}));
    }

    private enum RomanCharacters
    {
      I = 1,
      V = 5,
      X = 10,
      L = 50,
      C = 100,
      D = 500,
      M = 1000,
    }
  }
}

You can download the C# solution with unit tests here.
Advertisements
Explore posts in the same categories: agile, testing

Tags: , , ,

You can comment below, or link to this permanent URL from your own site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: