Hands on Test Driven Development Katas

In these days, Test Driven Development (TDD) is one of the most growing things in the technical world. Most of us are following Agile methodology where we would like to test our code within code.In this article, we will discuss all about TDD Katas and how we can get hands-on with

C# (10.0 MB)
 
 
 
 
 
5 Star
(1)
222 times
Add to favorites
12/24/2015
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C#
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace TDD_Katas_project.The_CalcStats_Kata
{
    public class CalcStat
    {
        #region Members
        public enum CalcStatKeys
        {
            Minimum = 1, Maximum = 2, ElementCount = 3, Average = 4
        }
        #endregion

        #region Public Methods
        public static string NumberStats(IList<int> numbers, CalcStatKeys keys)
        {
            switch (keys)
            {
                case CalcStatKeys.Minimum:
                    return GetMinimumValue(numbers);
                case CalcStatKeys.Maximum:
                    return GetMaximumValue(numbers);
                case CalcStatKeys.ElementCount:
                    return GetElementCount(numbers);
                case CalcStatKeys.Average:
                    return GetSeriesAverage(numbers);
            }
            return null;
        }
        #endregion

        #region Private Methods

        private static string GetMinimumValue(IEnumerable<int> numbers)
        {
            return numbers == null
                       ? null
                       : numbers.Min().ToString(CultureInfo.InvariantCulture);
        }
        private static string GetMaximumValue(IEnumerable<int> numbers)
        {
            return numbers == null
                       ? null
                       : numbers.Max().ToString(CultureInfo.InvariantCulture);
        }
        private static string GetElementCount(IEnumerable<int> numbers)
        {
            return numbers == null
                       ? null
                       : numbers.Count().ToString(CultureInfo.InvariantCulture);
        }
        private static string GetSeriesAverage(IEnumerable<int> numbers)
        {
            return numbers == null
                       ? null
                       : numbers.Average().ToString(CultureInfo.InvariantCulture);
        }
        #endregion
    }
}