Skip to content

Commit

Permalink
Natural StringSorting Test
Browse files Browse the repository at this point in the history
  • Loading branch information
garora committed Mar 14, 2021
1 parent 87ec3e9 commit fa6f99d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
36 changes: 25 additions & 11 deletions src/TheNaturalStringSortingKata/NaturalStringSorting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,38 @@

namespace TDD_Katas_project.TheNaturalStringSortingKata
{
/// <summary>
/// Natural String Sorting
/// </summary>
public class NaturalStringSorting
{
#region Member variables
/// <summary>
///
/// </summary>
public enum SortOrder
{
Ascending, Descending
/// <summary>
/// The ascending
/// </summary>
Ascending,
/// <summary>
/// The descending
/// </summary>
Descending
}
#endregion

#region Public Methods

/// <summary>
/// Sorts the string.
/// </summary>
/// <param name="strItems">The string items.</param>
/// <returns></returns>
public List<string> SortString(string[] strItems) => SortString(strItems, SortOrder.Ascending);

/// <summary>
/// Sorts the string.
/// </summary>
/// <param name="strItems">The string items.</param>
/// <param name="order">The order.</param>
/// <returns></returns>
public List<string> SortString(string[] strItems, SortOrder order)
{
Func<string, object> Convert = str =>
Expand All @@ -38,9 +57,6 @@ public List<string> SortString(string[] strItems, SortOrder order)
return GetSortedList(strItems, order, Convert);

}
#endregion

#region Private Method

private static List<string> GetSortedList(IEnumerable<string> strItems, SortOrder order, Func<string, object> convert)
{
Expand All @@ -60,7 +76,5 @@ private static List<string> GetSortedList(IEnumerable<string> strItems, SortOrde
}
return sorted;
}

#endregion
}
}
27 changes: 17 additions & 10 deletions src/TheNaturalStringSortingKata/NaturalStringSortingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,49 @@

namespace TDD_Katas_project.TheNaturalStringSortingKata
{
/// <summary>
/// Natural StringSorting Test
/// </summary>
[TestFixture]
[Category("The Natural String Kata")]
public class NaturalStringSortingTest
{
#region Private Member Variables

private NaturalStringSorting _naturalStringSorting;
private string[] _strings;
#endregion

#region Setup/TearDown
/// <summary>
/// Setups this instance.
/// </summary>
[SetUp]
public void Setup()
{
_naturalStringSorting = new NaturalStringSorting();
_strings = new[] { "a1", "1", "3", "2", "b1", "1a", "b3", "23", "z 21", "21 1", "z22", "0" };
}
/// <summary>
/// Tears down.
/// </summary>
[TearDown]
public void TearDown()
{
_naturalStringSorting = null;
_strings = null;
}
#endregion

#region Test Methods

/// <summary>
/// Determines whether this instance [can sort string default order].
/// </summary>
[Test]
public void CanSortStringDefaultOrder()
{
var sortString = _naturalStringSorting.SortString(_strings);
string[] result = { "0", "1", "1a", "2", "3", "23", "21 1", "a1", "b1", "b3", "z 21", "z22" };
Assert.That(sortString, Is.EqualTo(ToList(result)));
}
/// <summary>
/// Determines whether this instance [can sort string DES order].
/// </summary>
[Test]
public void CanSortStringDesOrder()
{
Expand All @@ -47,11 +57,8 @@ public void CanSortStringDesOrder()
Assert.That(sortString, Is.EqualTo(ToList(result)));

}
#endregion

#region Private Methods

private static List<string> ToList(params string[] items) => items.ToList();

#endregion
}
}

0 comments on commit fa6f99d

Please sign in to comment.