From 3d1ada6a3379e48f8da34971da8be22be39324e5 Mon Sep 17 00:00:00 2001 From: Paul McGuire Date: Sun, 30 Dec 2018 09:32:30 -0600 Subject: Update Travis-CI scripts to include examples; fix bug in runTests if postParse function returns None (or any non-str value) --- examples/romanNumerals.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'examples/romanNumerals.py') diff --git a/examples/romanNumerals.py b/examples/romanNumerals.py index 536fbb0..0f15ac8 100644 --- a/examples/romanNumerals.py +++ b/examples/romanNumerals.py @@ -52,17 +52,26 @@ def makeRomanNumeral(n): return ret tests = " ".join(makeRomanNumeral(i) for i in range(1,5000+1)) +roman_int_map = {} expected = 1 for t,s,e in romanNumeral.scanString(tests): + orig = tests[s:e] if t[0] != expected: - print("{} {} {}".format("==>", t, tests[s:e])) + print("{} {} {}".format("==>", t, orig)) + roman_int_map[orig] = t[0] expected += 1 -def test(rn): - print("{} -> {}".format(rn, romanNumeral.parseString(rn)[0])) -test("XVI") -test("XXXIX") -test("XIV") -test("XIX") -test("MCMLXXX") -test("MMVI") +def verify_value(s, tokens): + expected = roman_int_map[s] + if tokens[0] != expected: + raise Exception("incorrect value for {} ({}), expected {}".format(s, tokens[0], expected )) + +romanNumeral.runTests("""\ + XVI + XXXIX + XIV + XIX + MCMLXXX + MMVI + """, fullDump=False, + postParse=verify_value) \ No newline at end of file -- cgit v1.2.1