Created
April 29, 2019 22:31
-
-
Save ReeceHub/5fac270c2ce0c1eef4b235851834e87b to your computer and use it in GitHub Desktop.
Roman Numerals
This file contains 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
from flask import Flask | |
from roman_numerals import add | |
app = Flask(__name__) | |
@app.route('/add/<a>/<b>') | |
def add_endpoint(a, b): | |
return f'Answer: {add(a, b)}' |
This file contains 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
def add(a, b): | |
expanded = { | |
'V': 'IIIII', | |
'IV': 'IIII', | |
} | |
expanded_a = expanded.get(a, a) | |
expanded_b = expanded.get(b, b) | |
combo = expanded_a + expanded_b | |
special_cases = { | |
'IIIIIIIIII': 'X', | |
'IIIIII': 'VI', | |
'IIIII': 'V', | |
'VV': 'X', | |
'XXXXX': 'L', | |
'LL': 'C', | |
} | |
result = special_cases.get(combo, combo) | |
return result |
This file contains 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
import requests | |
from roman_numerals import add | |
class TestUnit: | |
def test_add_one_and_one(self): | |
assert add('I', 'I') == 'II' | |
def test_make_five(self): | |
assert add('I', 'IIII') == 'V' | |
def test_make_ten(self): | |
assert add('V', 'V') == 'X' | |
def test_make_fifty(self): | |
assert add('XX', 'XXX') == 'L' | |
def test_make_one_hundred(self): | |
assert add('L', 'L') == 'C' | |
def test_make_six(self): | |
assert add('V', 'I') == 'VI' | |
assert add('I', 'V') == 'VI' | |
assert add('III', 'III') == 'VI' | |
def test_accept_four(self): | |
assert add('IV', 'I') == 'V' | |
class TestE2E: | |
def test_response(self): | |
r = requests.get('http://localhost:5000/add/I/I') | |
assert r.status_code == 200 | |
assert r.text == 'Answer: II' | |
def test_stringify(self): | |
r = requests.get('http://localhost:5000/add/5/5') | |
assert r.text == 'Answer: 55' | |
def test_vv(self): | |
r = requests.get('http://localhost:5000/add/v/v') | |
assert r.text == 'Answer: X' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment