Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
StringCalculator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
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
Lasse Pikkemaat
StringCalculator
Commits
fcafdbfd
Commit
fcafdbfd
authored
1 month ago
by
linopino
Browse files
Options
Downloads
Patches
Plain Diff
Umsetzung der Testszenarien von Feature2
parent
b8ab3a4e
No related branches found
No related tags found
2 merge requests
!7
Develop into main
,
!2
Feature2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/stringcalculator.py
+7
-1
7 additions, 1 deletion
src/stringcalculator.py
tests/test_stringclaculator.py
+4
-0
4 additions, 0 deletions
tests/test_stringclaculator.py
with
11 additions
and
1 deletion
src/stringcalculator.py
+
7
−
1
View file @
fcafdbfd
from
src.interfaces
import
IStringCalculator
import
re
class
StringCalculator
(
IStringCalculator
):
def
add
(
self
,
numbers
:
str
)
->
int
:
if
not
numbers
:
return
0
return
sum
(
map
(
int
,
numbers
.
split
(
'
,
'
)))
\ No newline at end of file
# Erlaubt Kommas und Zeilenumbrüche als Trennzeichen
tokens
=
re
.
split
(
r
"
[,\n]
"
,
numbers
)
return
sum
(
map
(
int
,
tokens
))
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/test_stringclaculator.py
+
4
−
0
View file @
fcafdbfd
...
...
@@ -31,6 +31,10 @@ class TestStringCalculator(unittest.TestCase):
self
.
assertEqual
(
self
.
calculator
.
add
(
"
1,2,3
"
),
6
)
self
.
assertEqual
(
self
.
calculator
.
add
(
"
10,20,30,40
"
),
100
)
def
test_add_with_newline_separator
(
self
):
self
.
assertEqual
(
self
.
calculator
.
add
(
"
1
\n
2,3
"
),
6
)
self
.
assertEqual
(
self
.
calculator
.
add
(
"
10
\n
20
\n
30
"
),
60
)
if
__name__
==
"
__main__
"
:
unittest
.
main
()
...
...
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