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
c3bc8a60
Commit
c3bc8a60
authored
1 month ago
by
Lasse Pikkemaat
Browse files
Options
Downloads
Plain Diff
Merge branch 'feature2' into 'develop'
Feature2 See merge request
!2
parents
231b9e4f
fcafdbfd
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
+8
-3
8 additions, 3 deletions
tests/test_stringclaculator.py
with
15 additions
and
4 deletions
src/stringcalculator.py
+
7
−
1
View file @
c3bc8a60
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
+
8
−
3
View file @
c3bc8a60
...
...
@@ -3,11 +3,12 @@
# Bei Eingabe einer 1 soll 1 ausgegeben werden
# Bei Eingabe einer 3,4 soll 7 ausgegeben werden
# Bei Eingabe einer 10,20 soll 30 ausgegeben werden
#Feature1
#Feature1
Längere Zahlenfolge
# Bei Eingabe einer 1,2,3 soll 6 ausgegeben werden
# Bei Eingabe einer 10,20,30,40 soll 100 ausgegeben werden
#Feature2
# Bei Eingabe einer
#Feature2 Neues Trennzeichen neben dem Komma
# Bei Eingabe von 1\n2,3 soll 6 ausgegeben werden
# Bei Eingabe von 10\n20\n30 soll 60 ausgegeben werden
import
unittest
from
src.interfaces
import
IStringCalculator
...
...
@@ -30,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