Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • admins
  • main
  • tp1
  • tp1-correction
  • tp2
  • tp2-correction
  • tp3
7 results

Target

Select target project
  • octolel/cicd
  • bruliette/cicd-2022-juju
  • desjardins/cicd
  • greets/cicd
  • 2022faureal/cicd
  • 2022flamama/cicd
  • 2022thirionma/cicd
  • siestetactique/cicd
  • 2021khlauthu/cicd
  • aubinx/cicd
  • 2022jacquinar/cicd
  • gravlax/cicd
12 results
Select Git revision
  • admins
  • main
  • tp1
  • tp1-correction
  • tp2
  • tp2-correction
  • tp3
7 results
Show changes

Commits on Source 2

......@@ -31,4 +31,13 @@ pylint:
# À toi de nous rajouter un petit job pour faire des tests unitaires
pytest:
## Bon courage
stage: test
dependencies:
- download_dependencies
needs:
- download_dependencies
before_script:
- source .venv/bin/activate
- pip install pytest
script:
- pytest calculator
......@@ -54,7 +54,7 @@ class Calculator:
#####################################################################
### 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_index = i
......
......@@ -21,6 +21,6 @@ class Operator:
STANDARD_OPERATORS = {
'+': 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),
}
......@@ -3,7 +3,7 @@ Test module for the calculator module.
"""
import pytest
from calculator.calculator import Calculator
from calculator.operators import Operator
from calculator.operators import STANDARD_OPERATORS, Operator
@pytest.fixture(scope="module", name="setup")
......@@ -11,20 +11,19 @@ def fixture_setup():
"""
Setup the test suite, by instantiating the calculator and the operators.
"""
plus = Operator('+', 1, lambda a, b: a + b)
minus = Operator('-', 1, lambda a, b: a - b)
times = Operator('*', 2, lambda a, b: a * b)
divide = Operator('/', 2, lambda a, b: a / b)
calculator = Calculator(
operators={'+': plus, '-': minus, '*': times, '/': divide})
plus = STANDARD_OPERATORS['+']
minus = STANDARD_OPERATORS['-']
times = STANDARD_OPERATORS['*']
divide = STANDARD_OPERATORS['/']
calculator = Calculator(STANDARD_OPERATORS)
yield plus, minus, times, divide, calculator
def test_tokenizer(setup):
"""
Test the tokenizer.
"""
plus, minus, times, divide, calc = setup
assert calc.tokenize("1 + 2 + 4 / 2") == [1,plus,2,plus,4,divide,2]
assert calc.tokenize("1 * 0 - 4 / 2") == [1,times,0,minus,4,divide,2]
# À toi de tester la fonction tokenize de Calculator.
......@@ -32,13 +31,23 @@ def test_parser(setup):
"""
Test the parser.
"""
plus, minus, times, divide, calc = setup
# À toi de tester la fonction parse de Calculator.
_, _, _, _, calc = setup
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):
"""
Test the evaluation.
"""
plus, minus, times, divide, calc = setup
# À toi de tester la fonction __call__ de Calculator.
_, _, _, _, calc = setup
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