Permalink
Browse files

Merge branch 'master' of https://github.com/davidarkemp/Inflector int…

…o davidarkemp-master
  • Loading branch information...
2 parents e7c2d44 + a7818f3 commit 5fd4c818dd172bbe276fb210f25c2e2ceaff019e @srkirkland committed Apr 7, 2011
Showing with 58 additions and 29 deletions.
  1. +0 −12 Inflector.Tests/Inflector.Tests.csproj
  2. +37 −2 Inflector.Tests/OrdinalizeTests.cs
  3. +19 −9 Inflector/Inflector.cs
  4. +2 −6 Inflector/Inflector.csproj
@@ -34,19 +34,7 @@
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.5.9.10348\lib\nunit.framework.dll</HintPath>
</Reference>
- <Reference Include="nunit.mocks">
- <HintPath>..\packages\NUnit.2.5.9.10348\lib\nunit.mocks.dll</HintPath>
- </Reference>
- <Reference Include="pnunit.framework">
- <HintPath>..\packages\NUnit.2.5.9.10348\lib\pnunit.framework.dll</HintPath>
- </Reference>
- <Reference Include="System" />
<Reference Include="System.Core" />
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="Microsoft.CSharp" />
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CapitalizeTests.cs" />
@@ -1,4 +1,7 @@
-using NUnit.Framework;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using NUnit.Framework;
namespace Inflector.Tests
{
@@ -14,6 +17,39 @@ public void Ordinalize()
}
}
+ [TestCase(0, "0th")]
+ [TestCase(1, "1st")]
+ [TestCase(2, "2nd")]
+ [TestCase(3, "3rd")]
+ [TestCase(4, "4th")]
+ [TestCase(5, "5th")]
+ [TestCase(6, "6th")]
+ [TestCase(7, "7th")]
+ [TestCase(8, "8th")]
+ [TestCase(9, "9th")]
+ [TestCase(10, "10th")]
+ [TestCase(11, "11th")]
+ [TestCase(12, "12th")]
+ [TestCase(13, "13th")]
+ [TestCase(14, "14th")]
+ [TestCase(20, "20th")]
+ [TestCase(21, "21st")]
+ [TestCase(22, "22nd")]
+ [TestCase(23, "23rd")]
+ [TestCase(24, "24th")]
+ [TestCase(100, "100th")]
+ [TestCase(101, "101st")]
+ [TestCase(102, "102nd")]
+ [TestCase(103, "103rd")]
+ [TestCase(104, "104th")]
+ [TestCase(110, "110th")]
+ [TestCase(1000, "1000th")]
+ [TestCase(1001, "1001st")]
+ public void OrdanizeNumbersTest(int number, string ordanized)
+ {
+ Assert.AreEqual(number.Ordinalize(), ordanized);
+ }
+
public OrdinalizeTests()
{
TestData.Add("0", "0th");
@@ -44,7 +80,6 @@ public OrdinalizeTests()
TestData.Add("110", "110th");
TestData.Add("1000", "1000th");
TestData.Add("1001", "1001st");
-
}
}
}
View
@@ -195,29 +195,39 @@ public static string Uncapitalize(this string word)
return word.Substring(0, 1).ToLower() + word.Substring(1);
}
- public static string Ordinalize(this string number)
+ public static string Ordinalize(this string numberString)
{
- int n = int.Parse(number);
- int nMod100 = n % 100;
+ return Ordanize(int.Parse(numberString), numberString);
+ }
+
+ public static string Ordinalize(this int number)
+ {
+ return Ordanize(number, number.ToString());
+ }
+
+ private static string Ordanize(int number, string numberString)
+ {
+ int nMod100 = number % 100;
if (nMod100 >= 11 && nMod100 <= 13)
{
- return number + "th";
+ return numberString + "th";
}
- switch (n % 10)
+ switch (number % 10)
{
case 1:
- return number + "st";
+ return numberString + "st";
case 2:
- return number + "nd";
+ return numberString + "nd";
case 3:
- return number + "rd";
+ return numberString + "rd";
default:
- return number + "th";
+ return numberString + "th";
}
}
+
public static string Dasherize(this string underscoredWord)
{
return underscoredWord.Replace('_', '-');
@@ -10,8 +10,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Inflector</RootNamespace>
<AssemblyName>Inflector</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
+ <TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -33,11 +34,6 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="Microsoft.CSharp" />
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Inflector.cs" />

0 comments on commit 5fd4c81

Please sign in to comment.