Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CICD 2022
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arthur Jacquin
CICD 2022
Commits
df3a9ee2
Commit
df3a9ee2
authored
2 years ago
by
Florentin Labelle
Browse files
Options
Downloads
Patches
Plain Diff
Correction
parent
a76e9d91
Branches
tp2-correction
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitlab-ci.yml
+10
-4
10 additions, 4 deletions
.gitlab-ci.yml
calculator/calculator.py
+3
-2
3 additions, 2 deletions
calculator/calculator.py
calculator/operators.py
+2
-2
2 additions, 2 deletions
calculator/operators.py
calculator/test_calculator.py
+18
-4
18 additions, 4 deletions
calculator/test_calculator.py
with
33 additions
and
12 deletions
.gitlab-ci.yml
+
10
−
4
View file @
df3a9ee2
...
...
@@ -4,7 +4,6 @@ stages:
-
dependencies
-
lint
-
test
-
deploy
download_dependencies
:
stage
:
dependencies
...
...
@@ -23,12 +22,19 @@ pylint:
-
download_dependencies
needs
:
-
download_dependencies
before_
script
:
script
:
-
source .venv/bin/activate
-
pip install pylint
script
:
-
pylint calculator --fail-on=error
# À toi de nous rajouter un petit job pour faire des tests unitaires
pytest
:
## Bon courage
stage
:
test
dependencies
:
-
download_dependencies
needs
:
-
download_dependencies
script
:
-
source .venv/bin/activate
-
pip install pytest
-
pytest calculator
This diff is collapsed.
Click to expand it.
calculator/calculator.py
+
3
−
2
View file @
df3a9ee2
...
...
@@ -52,9 +52,9 @@ class Calculator:
for
i
,
token
in
enumerate
(
tokens
):
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_index
=
i
...
...
@@ -66,4 +66,5 @@ class Calculator:
return
OperatorExpression
(
operator
,
self
.
parse
(
left
),
self
.
parse
(
right
))
def
__call__
(
self
,
expression
:
str
)
->
Term
:
# return 5
return
self
.
parse
(
self
.
tokenize
(
expression
))()
This diff is collapsed.
Click to expand it.
calculator/operators.py
+
2
−
2
View file @
df3a9ee2
...
...
@@ -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
),
}
This diff is collapsed.
Click to expand it.
calculator/test_calculator.py
+
18
−
4
View file @
df3a9ee2
...
...
@@ -25,7 +25,12 @@ def test_tokenizer(setup):
Test the tokenizer.
"""
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
):
...
...
@@ -33,12 +38,21 @@ def test_parser(setup):
Test the parser.
"""
plus
,
minus
,
times
,
divide
,
calc
=
setup
# À toi de tester la fonction parse de Calculator.
assert
repr
(
calc
.
parse
([
1
,
plus
,
2
]))
==
'
(1 + 2)
'
assert
repr
(
calc
.
parse
([
1
,
plus
,
2
,
times
,
3
])
)
==
'
(1 + (2 * 3))
'
assert
repr
(
calc
.
parse
(
[
1
,
plus
,
2
,
times
,
3
,
divide
,
4
]))
==
'
(1 + ((2 * 3) / 4))
'
assert
repr
(
calc
.
parse
([
1
,
plus
,
2
,
times
,
3
,
divide
,
4
,
minus
,
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment