Code Kata 2: Judgement Day

All Terminator jokes aside, it is time for me to work in another Code Kata. As this is a free time exercise and the world is plum full of free time at the moment, I should get to work. So let’s take a look at Code Kata 2.

Hmmm, karate humor, maybe I should have made my joke about the Karate Kid. He got a sequel as I recall. Anyway we are chopping up bits for fun and profit.

The basics goals seem easy enough. Implement a bit search in 5 different ways. Here are the specifics:

  1. We need a chop function.
  2. This function will need parameters of int for number to seek and an array of numbers in which to seek.
  3. Returns integer which is the location index and -1 if not present. Of course this will assume only one of each number is present in the array. So not two 2’s or five 5’s in your list of numbers.
  4. He is kind enough to include some unit testing. While the code is in Ruby, it should be easy enough to bring it into C#.

So, lets give it a whirl.

What are the criteria for a successful execution of the Code Kata 2?

First, I want to build 5 iterations so there will be five days of Code Kata 2. Next, each iteration has to be significantly different implementation. By that, I mean that it has to use different loops, conditionals and logic to quality. If all I do is change the variable name and data type, that would technically qualify but that defeats the spirit of the challenge. Finally, the unit tests provided will be the final arbiter of the function’s success.

I am going to arrange the code into days so there will be a Day1Chop, Day2Chop, Day3Chop, Day4Chop and a Day5Chop. Each will have its own unit test object. While I doubt this is the best way to organize it, it is at least a clean and clear way.

I will program this in Visual Studio 2017. Before anyone starts the whole wailing and gnashing of teeth, I have not gotten around to installing 2019. I am running into resource issues on my dev station and don’t have enough room. Between a painfully awful Q4 in 2019 and the Great Commie Plague of 2020, money has been tight for upgrades. Besides, I would still be playing in C# 7.

My preferred unit testing framework is NUnit so no surprise when I say that is my chosen unit testing platform. If you have followed me for any time, you probably know I have a hate-love-hate relationship with unit testing but I am trying to reform my ways. As a result, I will be using Test Driven Development on this kata. I figure, they are giving me a bunch of tests that I have to translate from Ruby to C# so why not start with the tests. That is what I should be doing.

With all that out of the way, it is time to start the project.

Leave a Reply

Your email address will not be published.