-
Notifications
You must be signed in to change notification settings - Fork 965
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from hazzik/billions
NumberToWordsExtension.ToWords add ability to convert billions
- Loading branch information
Showing
2 changed files
with
37 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,41 @@ | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace Humanizer.Tests | ||
{ | ||
public class NumberToWordsTests | ||
{ | ||
[Fact] | ||
public void ToWords() | ||
[InlineData(1, "one")] | ||
[InlineData(10, "ten")] | ||
[InlineData(11, "eleven")] | ||
[InlineData(122, "one hundred and twenty-two")] | ||
[InlineData(3501, "three thousand five hundred and one")] | ||
[InlineData(100, "one hundred")] | ||
[InlineData(1000, "one thousand")] | ||
[InlineData(100000, "one hundred thousand")] | ||
[InlineData(1000000, "one million")] | ||
[InlineData(10000000, "ten million")] | ||
[InlineData(100000000, "one hundred million")] | ||
[InlineData(1000000000, "one billion")] | ||
[InlineData(111, "one hundred and eleven")] | ||
[InlineData(1111, "one thousand one hundred and eleven")] | ||
[InlineData(111111, "one hundred and eleven thousand one hundred and eleven")] | ||
[InlineData(1111111, "one million one hundred and eleven thousand one hundred and eleven")] | ||
[InlineData(11111111, "eleven million one hundred and eleven thousand one hundred and eleven")] | ||
[InlineData(111111111, "one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] | ||
[InlineData(1111111111, "one billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] | ||
[InlineData(123, "one hundred and twenty-three")] | ||
[InlineData(1234, "one thousand two hundred and thirty-four")] | ||
[InlineData(12345, "twelve thousand three hundred and forty-five")] | ||
[InlineData(123456, "one hundred and twenty-three thousand four hundred and fifty-six")] | ||
[InlineData(1234567, "one million two hundred and thirty-four thousand five hundred and sixty-seven")] | ||
[InlineData(12345678, "twelve million three hundred and forty-five thousand six hundred and seventy-eight")] | ||
[InlineData(123456789, "one hundred and twenty-three million four hundred and fifty-six thousand seven hundred and eighty-nine")] | ||
[InlineData(1234567890, "one billion two hundred and thirty-four million five hundred and sixty-seven thousand eight hundred and ninety")] | ||
[Theory] | ||
public void Test(int number, string expected) | ||
{ | ||
Assert.Equal("one", 1.ToWords()); | ||
Assert.Equal("ten", 10.ToWords()); | ||
Assert.Equal("eleven", 11.ToWords()); | ||
Assert.Equal("one hundred and twenty-two", 122.ToWords()); | ||
Assert.Equal("three thousand five hundred and one", 3501.ToWords()); | ||
} | ||
|
||
[Fact] | ||
public void RoundNumbersHaveNoSpaceAtTheEnd() | ||
{ | ||
Assert.Equal("one hundred", 100.ToWords()); | ||
Assert.Equal("one thousand", 1000.ToWords()); | ||
Assert.Equal("one hundred thousand", 100000.ToWords()); | ||
Assert.Equal("one million", 1000000.ToWords()); | ||
Assert.Equal(expected, number.ToWords()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters