Skip to content
Snippets Groups Projects
Commit 9bc0aa8a authored by Florentin Labelle's avatar Florentin Labelle
Browse files

Correction

parent 33dd3c8f
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,6 @@ stages: ...@@ -4,7 +4,6 @@ stages:
- dependencies - dependencies
- lint - lint
- test - test
- deploy
download_dependencies: download_dependencies:
stage: dependencies stage: dependencies
...@@ -31,4 +30,13 @@ pylint: ...@@ -31,4 +30,13 @@ pylint:
# À toi de nous rajouter un petit job pour faire des tests unitaires # À toi de nous rajouter un petit job pour faire des tests unitaires
pytest: pytest:
## Bon courage stage: test
dependencies:
- download_dependencies
needs:
- download_dependencies
before_script:
- source .venv/bin/activate
script:
- pip install pytest
- pytest calculator
...@@ -52,9 +52,9 @@ class Calculator: ...@@ -52,9 +52,9 @@ class Calculator:
for i, token in enumerate(tokens): for i, token in enumerate(tokens):
if isinstance(token, Operator): if isinstance(token, Operator):
##################################################################### #####################################################################
### ATTENTION: Est-ce que c'est vraiment un < (non c'est un <=) ? ### ### ATTENTION: Est-ce que c'est vraiment un < ? (non c'est un <=) ###
##################################################################### #####################################################################
if operator is None or token.precedence < operator.precedence: if operator is None or token.precedence <= operator.precedence:
operator = token operator = token
operator_index = i operator_index = i
......
...@@ -22,5 +22,5 @@ STANDARD_OPERATORS = { ...@@ -22,5 +22,5 @@ STANDARD_OPERATORS = {
'+': Operator('+', 1, lambda a, b: a + b), '+': Operator('+', 1, lambda a, b: a + b),
'-': Operator('-', 1, lambda a, b: a - b), '-': Operator('-', 1, lambda a, b: a - b),
'*': Operator('×', 2, lambda a, b: a * b), '*': Operator('×', 2, lambda a, b: a * b),
'/': Operator('/', 2, lambda a, b: a % b), '/': Operator('/', 2, lambda a, b: a / b),
} }
...@@ -25,20 +25,34 @@ def test_tokenizer(setup): ...@@ -25,20 +25,34 @@ def test_tokenizer(setup):
Test the tokenizer. Test the tokenizer.
""" """
plus, minus, times, divide, calc = setup plus, minus, times, divide, calc = setup
# À toi de tester la fonction tokenize de Calculator. assert calc.tokenize("1 + 2") == [1, plus, 2]
assert calc.tokenize("1 + 2 * 3") == [1, plus, 2, times, 3]
assert calc.tokenize(
"1 + 2 * 3 / 4") == [1, plus, 2, times, 3, divide, 4]
assert calc.tokenize(
"1 + 2 * 3 / 4 - 5") == [1, plus, 2, times, 3, divide, 4, minus, 5]
def test_parser(setup): def test_parser(setup):
""" """
Test the parser. Test the parser.
""" """
plus, minus, times, divide, calc = setup _, _, _, _, calc = setup
# À toi de tester la fonction parse de Calculator. assert repr(calc.parse(calc.tokenize("1 + 2"))) == '(1 + 2)'
assert repr(calc.parse(calc.tokenize("1 + 2 * 3"))
) == '(1 + (2 * 3))'
assert repr(calc.parse(calc.tokenize(
"1 + 2 * 3 / 4"))) == '(1 + ((2 * 3) / 4))'
assert repr(calc.parse(calc.tokenize(
"1 + 2 * 3 / 4 - 5"))) == '((1 + ((2 * 3) / 4)) - 5)'
def test_evaluation(setup): def test_evaluation(setup):
""" """
Test the evaluation. Test the evaluation.
""" """
plus, minus, times, divide, calc = setup _, _, _, _, calc = setup
# À toi de tester la fonction __call__ de Calculator. assert calc("1 + 2") == 3
assert calc("1 + 2 * 3") == 7
assert calc("1 + 2 * 3 / 4") == 2.5
assert calc("1 + 2 * 3 / 4 - 5") == -2.5
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment