Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the "twenties" in SpanishNumberToWordsConverter #228

Merged
merged 2 commits into from
Apr 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
###In Development
- [#217](https://github.com/Mehdik/Humanizer/pull/217): Changed OrdinalizeExtensions to better accommodate localisations. Added pt-BR and Spanish Ordinalize localisation.
- [#221](https://github.com/Mehdik/Humanizer/pull/221): Added Russian ordinalizer
- [#228](https://github.com/Mehdik/Humanizer/pull/228): Fixed the "twenties" in SpanishNumberToWordsConverter

[Commits](https://github.com/MehdiK/Humanizer/compare/v1.22.1...master)

Expand Down
12 changes: 7 additions & 5 deletions src/Humanizer.Tests/Localisation/es/NumberToWordsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public NumberToWordsTests() : base("es-ES") { }
[InlineData(1, "uno")]
[InlineData(10, "diez")]
[InlineData(11, "once")]
[InlineData(122, "ciento veinte dos")]
[InlineData(122, "ciento veintidós")]
[InlineData(3501, "tres mil quinientos uno")]
[InlineData(100, "cien")]
[InlineData(1000, "mil")]
Expand All @@ -28,17 +28,19 @@ public NumberToWordsTests() : base("es-ES") { }
[InlineData(11111111, "once millones ciento once mil ciento once")]
[InlineData(111111111, "ciento once millones ciento once mil ciento once")]
[InlineData(1111111111, "mil millones ciento once millones ciento once mil ciento once")]
[InlineData(123, "ciento veinte tres")]
[InlineData(123, "ciento veintitrés")]
[InlineData(1234, "mil doscientos treinta y cuatro")]
[InlineData(12345, "doce mil trescientos cuarenta y cinco")]
[InlineData(123456, "ciento veinte tres mil cuatrocientos cincuenta y seis")]
[InlineData(123456, "ciento veintitrés mil cuatrocientos cincuenta y seis")]
[InlineData(1234567, "millón doscientos treinta y cuatro mil quinientos sesenta y siete")]
[InlineData(12345678, "doce millones trescientos cuarenta y cinco mil seiscientos setenta y ocho")]
[InlineData(123456789, "ciento veinte tres millones cuatrocientos cincuenta y seis mil setecientos ochenta y nueve")]
[InlineData(123456789, "ciento veintitrés millones cuatrocientos cincuenta y seis mil setecientos ochenta y nueve")]
[InlineData(1234567890, "mil millones doscientos treinta y cuatro millones quinientos sesenta y siete mil ochocientos noventa")]
[InlineData(15, "quince")]
[InlineData(16, "dieciséis")]
[InlineData(25, "veinte cinco")]
[InlineData(20, "veinte")]
[InlineData(22, "veintidós")]
[InlineData(25, "veinticinco")]
[InlineData(35, "treinta y cinco")]
[InlineData(1999, "mil novecientos noventa y nueve")]
[InlineData(2014, "dos mil catorce")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace Humanizer.Localisation.NumberToWords
internal class SpanishNumberToWordsConverter : DefaultNumberToWordsConverter
{
private static readonly string[] HundredsMap = { "cero", "ciento", "doscientos", "trescientos", "cuatrocientos", "quinientos", "seiscientos", "setecientos", "ochocientos", "novecientos" };
private static readonly string[] UnitsMap = { "cero", "uno", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve", "diez", "once", "doce", "trece", "catorce", "quince", "dieciséis", "diecisiete", "dieciocho", "diecinueve" };
private static readonly string[] UnitsMap = { "cero", "uno", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve", "diez", "once", "doce",
"trece", "catorce", "quince", "dieciséis", "diecisiete", "dieciocho", "diecinueve", "veinte", "veintiuno",
"veintidós", "veintitrés", "veinticuatro", "veinticinco", "veintiséis", "veintisiete", "veintiocho", "veintinueve"};
private static readonly string[] TensMap = { "cero", "diez", "veinte", "treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", "noventa" };

private static readonly Dictionary<int, string> Ordinals = new Dictionary<int, string>
Expand Down Expand Up @@ -68,7 +70,7 @@ public override string Convert(int number)

if (number > 0)
{
if (number < 20)
if (number < 30)
parts.Add(UnitsMap[number]);
else if (number > 20 && number < 30) {
var lastPart = TensMap[number / 10];
Expand Down