Select Git revision
download_server.py
test_calculator.py NaN GiB
"""
Test module for the calculator module.
"""
import pytest
from calculator.calculator import Calculator
from calculator.operators import STANDARD_OPERATORS, Operator
@pytest.fixture(scope="module", name="setup")
def fixture_setup():
"""
Setup the test suite, by instantiating the calculator and the operators.
"""
calculator = Calculator()
plus = STANDARD_OPERATORS["+"]
minus = STANDARD_OPERATORS["-"]
times = STANDARD_OPERATORS["*"]
divide = 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") == [1, plus, 2]
# À toi de tester la fonction tokenize de Calculator.
# Essaie de tester tous les opérateurs.
def test_parser(setup):
"""
Test the parser.
"""
plus, minus, times, divide, calc = setup
assert repr(calc.parse([1, plus, 2])) == '(1 + 2)'
# À toi de tester la fonction parse de Calculator.
# Essaie de tester tous les opérateurs.
def test_evaluation(setup):
"""
Test the evaluation.
"""
plus, minus, times, divide, calc = setup
assert calc("1 + 2") == 3
# À toi de tester la fonction __call__ de Calculator.
# Essaie de tester tous les opérateurs.