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
d0480620
Commit
d0480620
authored
1 month ago
by
linopino
Browse files
Options
Downloads
Patches
Plain Diff
Erstellung der Klassen und Methoden, Unterscheidung von Calculator, Interface und Tests
parent
97042e0e
No related branches found
Branches containing commit
No related tags found
1 merge request
!7
Develop into main
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.idea/StringCalculator.iml
+8
-0
8 additions, 0 deletions
.idea/StringCalculator.iml
src/interfaces.py
+6
-0
6 additions, 0 deletions
src/interfaces.py
src/stringcalculator.py
+7
-0
7 additions, 0 deletions
src/stringcalculator.py
tests/test_stringclaculator.py
+24
-1
24 additions, 1 deletion
tests/test_stringclaculator.py
with
45 additions
and
1 deletion
.idea/StringCalculator.iml
0 → 100644
+
8
−
0
View file @
d0480620
<?xml version="1.0" encoding="UTF-8"?>
<module
type=
"PYTHON_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
>
<content
url=
"file://$MODULE_DIR$"
/>
<orderEntry
type=
"inheritedJdk"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/interfaces.py
+
6
−
0
View file @
d0480620
from
abc
import
ABC
,
abstractmethod
class
IStringCalculator
(
ABC
):
@abstractmethod
def
add
(
self
,
numbers
:
str
)
->
int
:
pass
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/stringcalculator.py
+
7
−
0
View file @
d0480620
from
src.interfaces
import
IStringCalculator
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
This diff is collapsed.
Click to expand it.
tests/test_stringclaculator.py
+
24
−
1
View file @
d0480620
...
@@ -2,4 +2,27 @@
...
@@ -2,4 +2,27 @@
# Bei Eingabe keiner Zahl soll eine 0 ausgegeben werden
# Bei Eingabe keiner Zahl soll eine 0 ausgegeben werden
# Bei Eingabe einer 1 soll 1 ausgegeben werden
# Bei Eingabe einer 1 soll 1 ausgegeben werden
# Bei Eingabe einer 3,4 soll 7 ausgegeben werden
# Bei Eingabe einer 3,4 soll 7 ausgegeben werden
# Bei Eingabe einer 10,20 soll 30 ausgegeben werden
# Bei Eingabe einer 10,20 soll 30 ausgegeben werden
\ No newline at end of file
import
unittest
from
src.interfaces
import
IStringCalculator
from
src.stringcalculator
import
StringCalculator
class
TestStringCalculator
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
calculator
:
IStringCalculator
=
StringCalculator
()
# Zugriff über das Interface
def
test_add_empty_string
(
self
):
self
.
assertEqual
(
self
.
calculator
.
add
(
""
),
0
)
def
test_add_single_number
(
self
):
self
.
assertEqual
(
self
.
calculator
.
add
(
"
1
"
),
1
)
def
test_add_two_numbers
(
self
):
self
.
assertEqual
(
self
.
calculator
.
add
(
"
10,20
"
),
30
)
if
__name__
==
"
__main__
"
:
unittest
.
main
()
# python -m unittest tests.test_stringcalculator
# python -m unittest discover -s tests
\ No newline at end of file
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