Permalink
Browse files

Teste do 2001 funcionando, ap�s a refatora��o

  • Loading branch information...
soaresbest committed Dec 13, 2011
1 parent bb0eec3 commit 4c050f7f6ac39b9917adcb42ac09bfdca9a71676
Showing with 52 additions and 20 deletions.
  1. +15 −15 Extenso.Teste/ExtensoTeste.cs
  2. +3 −0 Extenso/ClasseNumerica.cs
  3. +34 −5 Extenso/Extenso.cs
@@ -5,21 +5,21 @@ namespace Extenso.Teste
[TestFixture]
public class ExtensoTeste
{
- [TestCase((ulong)0, "zero")]
- [TestCase((ulong)1, "um")]
- [TestCase((ulong)10, "dez")]
- [TestCase((ulong)11, "onze")]
- [TestCase((ulong)19, "dezenove")]
- [TestCase((ulong)20, "vinte")]
- [TestCase((ulong)21, "vinte e um")]
- [TestCase((ulong)99, "noventa e nove")]
- [TestCase((ulong)100, "cem")]
- [TestCase((ulong)101, "cento e um")]
- [TestCase((ulong)110, "cento e dez")]
- [TestCase((ulong)111, "cento e onze")]
- [TestCase((ulong)999, "novecentos e noventa e nove")]
- [TestCase((ulong)2001, "dois mil e um")]
- public void Para_numero_retornar_por_extenso(ulong numero, string respostaEsperada)
+ [TestCase("0", "zero")]
+ [TestCase("1", "um")]
+ [TestCase("10", "dez")]
+ [TestCase("11", "onze")]
+ [TestCase("19", "dezenove")]
+ [TestCase("20", "vinte")]
+ [TestCase("21", "vinte e um")]
+ [TestCase("99", "noventa e nove")]
+ [TestCase("100", "cem")]
+ [TestCase("101", "cento e um")]
+ [TestCase("110", "cento e dez")]
+ [TestCase("111", "cento e onze")]
+ [TestCase("999", "novecentos e noventa e nove")]
+ [TestCase("2001", "dois mil e um")]
+ public void retornar_por_extenso(string numero, string respostaEsperada)
{
Assert.AreEqual(respostaEsperada, Extenso.Converter(numero));
}
@@ -7,6 +7,7 @@ public static class ClasseNumerica
public static string SufixoDe(Bloco bloco)
{
var centenaNum = bloco.Centena.ToInt();
+
if (centenaNum == 0)
{
return string.Empty;
@@ -16,6 +17,8 @@ public static string SufixoDe(Bloco bloco)
switch (bloco.Ordem)
{
+ case 1:
+ return string.Empty;
case 2:
return "mil";
case 3:
View
@@ -1,12 +1,41 @@
-namespace Extenso
+using System.Collections.Generic;
+using System.Text;
+using Extenso.Teste;
+
+namespace Extenso
{
public static class Extenso
{
- public static string Converter(ulong numero)
+ public static string Converter(string numero)
{
- string numeroTexto = numero.ToString();
- var centena = new Centena(numeroTexto);
- return centena.ToString();
+ var stringBuilder = new StringBuilder();
+
+ List<Bloco> blocos = FabricaBlocos.GerarBlocos(numero);
+
+ foreach (var bloco in blocos)
+ {
+ string sufixo = ClasseNumerica.SufixoDe(bloco);
+
+ if (sufixo == string.Empty && bloco.Ordem > 1)
+ {
+ continue;
+ }
+
+ if (stringBuilder.Length > 0)
+ {
+ stringBuilder.Append(" e ");
+ }
+
+ stringBuilder.Append(bloco.Centena);
+
+ if (sufixo != string.Empty)
+ {
+ stringBuilder.Append(" ");
+ stringBuilder.Append(sufixo);
+ }
+ }
+
+ return stringBuilder.ToString();
}
}
}

0 comments on commit 4c050f7

Please sign in to comment.