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
be6e4e88
Commit
be6e4e88
authored
1 month ago
by
linopino
Browse files
Options
Downloads
Patches
Plain Diff
Umsetzung der Testszenarien von Feature4
parent
a1d73f82
No related branches found
No related tags found
2 merge requests
!7
Develop into main
,
!4
Feature4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/stringcalculator.py
+14
-8
14 additions, 8 deletions
src/stringcalculator.py
with
14 additions
and
8 deletions
src/stringcalculator.py
+
14
−
8
View file @
be6e4e88
...
@@ -7,17 +7,23 @@ class StringCalculator(IStringCalculator):
...
@@ -7,17 +7,23 @@ class StringCalculator(IStringCalculator):
if
not
numbers
:
if
not
numbers
:
return
0
return
0
# Prüfe auf das ungültige Format "1,\n"
if
numbers
.
startswith
(
"
//
"
):
if
"
,
\n
"
in
numbers
:
if
"
\n
"
not
in
numbers
:
raise
ValueError
(
"
Ungültiges Zahlenformat:
'
,
\\
n
'
ist nicht erlaubt
"
)
raise
ValueError
(
"
Ungültiges Format: Nicht vollständig
"
)
delimiter_end_index
=
numbers
.
index
(
"
\n
"
)
delimiter
=
numbers
[
2
:
delimiter_end_index
]
numbers
=
numbers
[
delimiter_end_index
+
1
:]
numbers
=
numbers
.
replace
(
delimiter
,
"
,
"
)
# Trenne Zahlen anhand von Komma oder Zeilenumbruch
numbers
=
numbers
.
replace
(
"
\n
"
,
"
,
"
)
tokens
=
re
.
split
(
r
"
,|\n
"
,
numbers
)
# Konvertiere zu Integern und finde negative Zahlen
# Split the string by commas, convert each value to an integer, and sum them up
numbers_list
=
list
(
map
(
int
,
tokens
))
try
:
negative_numbers
=
[
num
for
num
in
numbers_list
if
num
<
0
]
numbers_list
=
list
(
map
(
int
,
numbers
.
split
(
"
,
"
)))
except
ValueError
:
raise
ValueError
(
"
Ungültiges Zahlenformat: Enthält nicht-numerische Werte
"
)
negative_numbers
=
[
num
for
num
in
numbers_list
if
num
<
0
]
if
negative_numbers
:
if
negative_numbers
:
raise
ValueError
(
f
"
Negative nicht erlaubt:
{
negative_numbers
}
"
)
raise
ValueError
(
f
"
Negative nicht erlaubt:
{
negative_numbers
}
"
)
...
...
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