Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MehdiK committed Apr 12, 2014
1 parent 22d1df8 commit c82ecd4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 90 deletions.
1 change: 0 additions & 1 deletion src/Humanizer.Tests/Humanizer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
<Compile Include="Localisation\invariant\ToQuantityTests.cs" />
<Compile Include="Localisation\es\NumberToWordsTests.cs" />
<Compile Include="Localisation\nb-NO\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\NumberToWordsFactoryTests.cs" />
<Compile Include="Localisation\pl\DateHumanizeTests.cs" />
<Compile Include="Localisation\pl\NumberToWordsTests.cs" />
<Compile Include="Localisation\pl\TimeSpanHumanizeTests.cs" />
Expand Down
46 changes: 0 additions & 46 deletions src/Humanizer.Tests/Localisation/NumberToWordsFactoryTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public NumberToWordsTests() : base("pt-BR") { }
[InlineData(1999, "mil novecentos e noventa e nove")]
[InlineData(2014, "dois mil e quatorze")]
[InlineData(2048, "dois mil e quarenta e oito")]
public void ToWordsPortuguese(int number, string expected)
public void ToWords(int number, string expected)
{
Assert.Equal(expected, number.ToWords());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Humanizer.Localisation.NumberToWords;
using System;
using System;
using System.Collections.Generic;

namespace Humanizer.Localisation.NumberToWords
{
internal class BrazilianPortugueseNumberToWordsConverter : DefaultNumberToWordsConverter
{
private static readonly string[] portugueseUnitsMap = { "zero", "um", "dois", "três", "quatro", "cinco", "seis", "sete", "oito", "nove", "dez", "onze", "doze", "treze", "quatorze", "quinze", "dezesseis", "dezessete", "dezoito", "dezenove" };
private static readonly string[] portugueseTensMap = { "zero", "dez", "vinte", "trinta", "quarenta", "cinquenta", "sessenta", "setenta", "oitenta", "noventa" };
private static readonly string[] portugueseHundredsMap = { "zero", "cento", "duzentos", "trezentos", "quatrocentos", "quinhentos", "seiscentos", "setecentos", "oitocentos", "novecentos" };
private static readonly string[] PortugueseUnitsMap = { "zero", "um", "dois", "três", "quatro", "cinco", "seis", "sete", "oito", "nove", "dez", "onze", "doze", "treze", "quatorze", "quinze", "dezesseis", "dezessete", "dezoito", "dezenove" };
private static readonly string[] PortugueseTensMap = { "zero", "dez", "vinte", "trinta", "quarenta", "cinquenta", "sessenta", "setenta", "oitenta", "noventa" };
private static readonly string[] PortugueseHundredsMap = { "zero", "cento", "duzentos", "trezentos", "quatrocentos", "quinhentos", "seiscentos", "setecentos", "oitocentos", "novecentos" };

public override string Convert(int number)
{
Expand All @@ -22,57 +21,34 @@ public override string Convert(int number)

if ((number / 1000000000) > 0)
{
if (number / 1000000000 > 2)
{
parts.Add(string.Format("{0} bilhões", Convert(number / 1000000000)));
}
else
{
parts.Add(string.Format("{0} bilhão", Convert(number / 1000000000)));
}
parts.Add(number/1000000000 > 2
? string.Format("{0} bilhões", Convert(number/1000000000))
: string.Format("{0} bilhão", Convert(number/1000000000)));

number %= 1000000000;
}

if ((number / 1000000) > 0)
{
if (number / 1000000 > 2)
{
parts.Add(string.Format("{0} milhões", Convert(number / 1000000)));
}
else
{
parts.Add(string.Format("{0} milhão", Convert(number / 1000000)));
}
parts.Add(number/1000000 > 2
? string.Format("{0} milhões", Convert(number/1000000))
: string.Format("{0} milhão", Convert(number/1000000)));

number %= 1000000;
}

if ((number / 1000) > 0)
{
if (number / 1000 == 1)
parts.Add("mil");
else
parts.Add(string.Format("{0} mil", Convert(number / 1000)));

parts.Add(number/1000 == 1 ? "mil" : string.Format("{0} mil", Convert(number/1000)));
number %= 1000;
}

if ((number / 100) > 0)
{
if (number == 100)
{
if (parts.Count > 0)
{
parts.Add("e cem");
}
else
{
parts.Add("cem");
}
}
parts.Add(parts.Count > 0 ? "e cem" : "cem");
else
{
parts.Add(portugueseHundredsMap[(number / 100)]);
}
parts.Add(PortugueseHundredsMap[(number / 100)]);

number %= 100;
}
Expand All @@ -83,12 +59,12 @@ public override string Convert(int number)
parts.Add("e");

if (number < 20)
parts.Add(portugueseUnitsMap[number]);
parts.Add(PortugueseUnitsMap[number]);
else
{
var lastPart = portugueseTensMap[number / 10];
var lastPart = PortugueseTensMap[number / 10];
if ((number % 10) > 0)
lastPart += string.Format(" e {0}", portugueseUnitsMap[number % 10]);
lastPart += string.Format(" e {0}", PortugueseUnitsMap[number % 10]);

parts.Add(lastPart);
}
Expand Down

1 comment on commit c82ecd4

@akamud
Copy link
Contributor

@akamud akamud commented on c82ecd4 Apr 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks fine to me.

Please sign in to comment.