Created
December 11, 2010 22:13
-
-
Save sourcerebels/737692 to your computer and use it in GitHub Desktop.
Implementación en Python muy pobre de la cata "Caesar plays Lottery" <http://codingkata.org/katas/unit/caesar-lottery> con expresiones regulares y una tabla de conversión. El objetivo de este ejercicio fue: * Instalar el intérprete de Python.
* Config
This file contains hidden or 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
''' | |
Created on 11/12/2010 | |
@author: Eduardo Rodriguez Castillo <http://sourcerebels.com> | |
''' | |
import re | |
def convert(number=1): | |
conversionTable = ((50, "L"),(40, "XL"),(10, "X"),(9, "IX"),(5, "V"), (4, "IV")) | |
palitos = ""; | |
for i in range(0, number): | |
palitos = "I{}".format(palitos); | |
for i in range(len(conversionTable)): | |
numeroPalitos = conversionTable[i][0] | |
simboloPorElQueReemplazar = conversionTable[i][1] | |
expresionRegular = "I{" + str(numeroPalitos) + "}" | |
palitos = re.sub(expresionRegular, simboloPorElQueReemplazar, palitos) | |
return palitos | |
if __name__ == '__main__': | |
pass |
This file contains hidden or 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
''' | |
Created on 11/12/2010 | |
@author: Edu Rodriguez Castillo <http://sourcerebels.com> | |
''' | |
import unittest | |
import cpl | |
class Test(unittest.TestCase): | |
def setUp(self): | |
pass | |
def tearDown(self): | |
pass | |
def testCSL(self): | |
numbers = [ "I", "II", "III", "IV", "V", "VI", "VII", "VIII", | |
"IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI", | |
"XVII", "XVIII", "XIX", "XX", "XXI", "XXII", "XXIII", | |
"XXIV", "XXV", "XXVI", "XXVII", "XXVIII", "XXIX", "XXX", | |
"XXXI", "XXXII", "XXXIII", "XXXIV", "XXXV", "XXXVI", | |
"XXXVII", "XXXVIII", "XXXIX", "XL", "XLI", "XLII", | |
"XLIII", "XLIV", "XLV", "XLVI", "XLVII", "XLVIII", | |
"XLIX", "L"]; | |
for i in range(0, 49): | |
number = i + 1 | |
convertedNumber = cpl.convert(number) | |
self.assertTrue(convertedNumber == numbers[i]) | |
pass | |
if __name__ == "__main__": | |
#import sys;sys.argv = ['', 'Test.testName'] | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Un poco tristemente, después de leerme el capitulo 1 del libro "Begining game development with python and pygame" he visto que sería mucho más sencillo utilizar un "dictionary" en lugar de esa tupla de tuplas tan fea :-)