Skip to content

Instantly share code, notes, and snippets.

@yngwie74
Created January 17, 2012 01:13
Show Gist options
  • Save yngwie74/1623958 to your computer and use it in GitHub Desktop.
Save yngwie74/1623958 to your computer and use it in GitHub Desktop.
Pruebas unitarias para la roman.py y sus variaciones
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Pruebas unitarias para
- roman.py (https://gist.github.com/1623819),
- roman_single_func.py (https://gist.github.com/1623830), y
- roman_func.py (https://gist.github.com/1885963)
- roman_dict.py (https://gist.github.com/1623854)
https://gist.github.com/1623958
"""
from itertools import count, izip
from unittest import main, TestCase
import roman_func
import roman_dict
import roman_single_func
import roman
def specify_for_func(func, with_input, should_yield):
for (e, a) in izip(with_input, should_yield):
func(e, a)
class TestToRoman(TestCase):
ROMAN_FUNC = [roman.romanOf] # evitamos que lo guarde como "unbound method"
def theRomanFor(self, number, shouldBe):
result = self.ROMAN_FUNC[0](number)
message = 'The roman for %d should be %r but was %r' % (number, shouldBe, result)
self.assertEquals(shouldBe, result, message)
def test_0001_to_0100(self):
specify_for_func(self.theRomanFor,
with_input=range(1, 11) + [11, 14, 15, 25, 29, 31, 34, 40, 54, 55, 57, 58, 68, 75, 77, 85, 90, 92, 95, 99, 100],
should_yield=['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XIV', 'XV', 'XXV', 'XXIX', 'XXXI', 'XXXIV', 'XL', 'LIV', 'LV', 'LVII', 'LVIII', 'LXVIII', 'LXXV', 'LXXVII', 'LXXXV', 'XC', 'XCII', 'XCV', 'XCIX', 'C'],
)
def test_0100_to_1100(self):
specify_for_func(self.theRomanFor,
with_input=[101, 193, 210, 277, 283, 291, 329, 338, 374, 379, 635, 647, 670, 767, 818, 843, 921, 947, 998, 1016, 1026, 1099, 1100],
should_yield=['CI', 'CXCIII', 'CCX', 'CCLXXVII', 'CCLXXXIII', 'CCXCI', 'CCCXXIX', 'CCCXXXVIII', 'CCCLXXIV', 'CCCLXXIX', 'DCXXXV', 'DCXLVII', 'DCLXX', 'DCCLXVII', 'DCCCXVIII', 'DCCCXLIII', 'CMXXI', 'CMXLVII', 'CMXCVIII', 'MXVI', 'MXXVI', 'MXCIX', 'MC'],
)
def test_1999(self):
self.theRomanFor(1999, shouldBe='MCMXCIX')
def test_2000_to_3000(self):
specify_for_func(self.theRomanFor,
with_input=[2000, 2018, 2026, 2064, 2125, 2352, 2353, 2363, 2370, 2458, 2528, 2552, 2562, 2567, 2580, 2585, 2716, 2718, 2753, 2936, 2997, 3000],
should_yield=['MM', 'MMXVIII', 'MMXXVI', 'MMLXIV', 'MMCXXV', 'MMCCCLII', 'MMCCCLIII', 'MMCCCLXIII', 'MMCCCLXX', 'MMCDLVIII', 'MMDXXVIII', 'MMDLII', 'MMDLXII', 'MMDLXVII', 'MMDLXXX', 'MMDLXXXV', 'MMDCCXVI', 'MMDCCXVIII', 'MMDCCLIII', 'MMCMXXXVI', 'MMCMXCVII', 'MMM'],
)
class TestRomanSingleFunc(TestToRoman):
ROMAN_FUNC = [roman_single_func.romanOf]
class TestRomanDict(TestToRoman):
ROMAN_FUNC = [roman_dict.romanOf]
class TestRomanFunc(TestToRoman):
ROMAN_FUNC = [roman_func.romanOf]
if __name__ == '__main__':
main(verbosity=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment