Ágiles@BsAs 20110208 - Randori Coding Dojo
Facilitador/es: Adrián Eidelman
Descripción de la charla
Un coding dojo es una sesión de codificación centrada alrededor de un desafío de programación. El desafío es sumamente pequeño en alcance y -en la versión Randori de un coding dojo- la totalidad de la audiencia participa para completarlo. Básicamente la solución se construye utilizando una única computadora y un proyector, en donde los desarrolladores van rotando de a pares cada una cantidad fija y acotada de tiempo, dejando lugar a que otras personas de la audiencia continúen. El objetivo es aprender, enseñar y mejorar nuestras habilidades de programación compartiendo con otros desarrolladores de software en un ambiente relajado.
En esta reunión el problema fue "Numeros romanos", el cual consiste en construir una función que reciba un número entero y retorne su representación en números romanos.
Video
Código
Este es el código resultante del dojo:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Moq;
using
NUnit.Framework;
using
NumerosRomanos;
namespace
NumerosRomanos.Tests
{
[TestFixture]
public
class
Tests
{
Conversor conversor;
Dictionary<int, string> valores;
[TestFixtureSetUp]
public
void
setUp()
{
conversor = new
Conversor();
valores = new
Dictionary<int, string>();
valores.Add(1, "I");
valores.Add(5, "V");
valores.Add(10, "X");
valores.Add(50, "L");
valores.Add(100, "C");
valores.Add(500, "D");
valores.Add(1000, "M");
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public
void
El0ArrojaExcepcion()
{
int
numeroArabigo = 0;
string
numeroRomano = conversor.ANumerosRomanos(numeroArabigo);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public
void
NumeroNegativoArrojaExcepcion()
{
int
numeroArabigo = -1;
string
numeroRomano = conversor.ANumerosRomanos(numeroArabigo);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public
void
El4000ArrojaExcepcion()
{
int
numeroArabigo = 4000;
string
numeroRomano = conversor.ANumerosRomanos(numeroArabigo);
}
[Test]
public
void
El1DeberiaDevolverI()
{
int
numeroArabigo = 1;
string
numeroRomano = conversor.ANumerosRomanos(numeroArabigo);
Assert.AreEqual("I", numeroRomano);
}
[Test]
public
void
El5DeberiaDevolverV()
{
int
numeroArabigo = 5;
string
numeroRomano = conversor.ANumerosRomanos(numeroArabigo);
Assert.AreEqual("V", numeroRomano);
}
[Test]
public
void
El10DeberiaDevolverX()
{
int
numeroArabigo =10;
string
numeroRomano = conversor.ANumerosRomanos(numeroArabigo);
Assert.AreEqual("X", numeroRomano);
}
[Test]
public
void
El2DeberiaDevolverII()
{
int
numeroArabigo = 2;
string
numeroRomano = conversor.ANumerosRomanos(numeroArabigo);
Assert.AreEqual("II", numeroRomano);
}
[Test]
public
void
El3DeberiaDevolverIII()
{
int
numeroArabigo = 3;
string
numeroRomano = conversor.ANumerosRomanos(numeroArabigo);
Assert.AreEqual("III", numeroRomano);
}
[Test]
public
void
El15DeberiaDevolverXV()
{
int
numeroArabigo = 15;
string
numeroRomano = conversor.ANumerosRomanos(numeroArabigo);
Assert.AreEqual("XV", numeroRomano);
}
[Test]
public
void
El4DeberiaDevolverIV()
{
int
numeroArabigo = 4;
string
numeroRomano = conversor.ANumerosRomanos(numeroArabigo);
Assert.AreEqual("IV", numeroRomano);
}
[Test]
public
void
El48DeberiaDevolverXLVIII()
{
int
numeroArabigo = 48;
string
numeroRomano = conversor.ANumerosRomanos(numeroArabigo);
Assert.AreEqual("XLVIII", numeroRomano);
}
[Test]
public
void
RetornaValoreConocidos()
{
foreach(var i in
valores.Keys)
Assert.AreEqual(valores[i], conversor.ANumerosRomanos(i));
}
}
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
NumerosRomanos
{
public
class
Conversor
{
List<int> valoresArabigos = new
List<int>
{1,4,5,9,10,40,50,90,100,400,500,900,1000};
List<string> valoresRomanos = new
List<string>
{"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
public
Conversor()
{
valoresArabigos.Reverse();
valoresRomanos.Reverse();
}
public
string
ANumerosRomanos(int
numeroArabigo)
{
if
(numeroArabigo<=0 || numeroArabigo>3999)
throw
new
ArgumentException();
string
resultado="";
while
(numeroArabigo > 0)
{
foreach
(var i in
valoresArabigos)
{
if
(i <= numeroArabigo)
{
resultado += valoresRomanos[valoresArabigos.IndexOf(i)];
numeroArabigo -= i;
}
}
}
return
resultado;
}
}
}