From 2bab5561b624bc7223c7840d31bbea3fdb49b8f0 Mon Sep 17 00:00:00 2001 From: mathias <mathias.thirion@student-cs.fr> Date: Thu, 13 Oct 2022 18:29:27 +0200 Subject: [PATCH] test --- .gitlab-ci.yml | 10 ++++++++++ calculator/test_calculator.py | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4553ad3..98509b8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,4 +28,14 @@ pylint: # À toi de nous rajouter un petit job pour faire des tests unitaires pytest: + stage: test + dependencies: + - download_dependencies + needs: + - download_dependencies + script: + - source .venv/bin/activate + - pip install pytest + - pytest calculator + ## Bon courage diff --git a/calculator/test_calculator.py b/calculator/test_calculator.py index 32c87e1..f87d857 100644 --- a/calculator/test_calculator.py +++ b/calculator/test_calculator.py @@ -25,6 +25,9 @@ def test_tokenizer(setup): """ plus, minus, times, divide, calc = setup assert calc.tokenize("1 + 2") == [1, plus, 2] + assert calc.tokenize("6 * 7 / 2") == [6, times, 7, divide, 2] + assert calc.tokenize("6 + 7 * 3") == [6, plus, 7, times, 3] + assert calc.tokenize("6 * 7 - 2 / 2") == [6, times, 7, minus, 2, divide, 2] # À toi de tester la fonction tokenize de Calculator. # Essaie de tester tous les opérateurs. @@ -35,6 +38,9 @@ def test_parser(setup): """ plus, minus, times, divide, calc = setup assert repr(calc.parse([1, plus, 2])) == '(1 + 2)' + assert repr(calc.parse([6, times, 7, divide, 2])) == '(6 * 7 / 2)' + assert repr(calc.parse([6, plus, 7, times, 2])) == '(6 + 7 * 2)' + assert repr(calc.parse([6, times, 7, minus, 2, divide, 2])) == '(6 * 7 - 2 / 2)' # À toi de tester la fonction parse de Calculator. # Essaie de tester tous les opérateurs. @@ -45,5 +51,8 @@ def test_evaluation(setup): """ plus, minus, times, divide, calc = setup assert calc("1 + 2") == 3 + assert calc("6 * 7 / 2") == 21 + assert calc("6 + 7 * 2") == 20 + assert calc("6 * 7 - 2 / 2") == 41 # À toi de tester la fonction __call__ de Calculator. # Essaie de tester tous les opérateurs. -- GitLab