Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
0
06_FDD_Assignement
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
Alma Berisha
06_FDD_Assignement
Commits
ada72925
Commit
ada72925
authored
2 months ago
by
Alma Berisha
Browse files
Options
Downloads
Patches
Plain Diff
restore test_mars.py after accidental removal
parent
4b1a7db2
Branches
singleton
Branches containing commit
No related tags found
1 merge request
!3
Develop
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test_mars.py
+63
-0
63 additions, 0 deletions
test_mars.py
with
63 additions
and
0 deletions
test_mars.py
0 → 100644
+
63
−
0
View file @
ada72925
import
unittest
from
mars
import
Mars
from
plateau
import
Plateau
class
TestMarsSingleton
(
unittest
.
TestCase
):
"""
Testklasse für das Singleton-Verhalten der Mars-Klasse.
"""
def
test_mars_singleton
(
self
):
"""
Überprüft, ob zwei Mars-Instanzen tatsächlich dasselbe Objekt sind.
"""
# Erstelle zwei Mars-Instanzen
mars1
=
Mars
()
mars2
=
Mars
()
# Überprüfe, ob es sich um dasselbe Objekt handelt
self
.
assertIs
(
mars1
,
mars2
,
"
Mars sollte ein Singleton sein
"
)
# Überprüfe, ob Änderungen an einer Instanz auch die andere betreffen
plateau
=
Plateau
(
5
,
5
)
mars1
.
set_plateau
(
plateau
)
# Beide Instanzen sollten dasselbe Plateau haben
self
.
assertIs
(
mars1
.
get_plateau
(),
mars2
.
get_plateau
())
def
test_mars_singleton_reset
(
self
):
"""
Überprüft, ob das Singleton-Verhalten auch nach dem Zurücksetzen der Instanz funktioniert.
"""
# Erstelle eine Mars-Instanz
mars1
=
Mars
()
# Speichere eine Referenz auf die Instanz
mars_ref
=
mars1
# Setze ein Plateau
plateau1
=
Plateau
(
5
,
5
)
mars1
.
set_plateau
(
plateau1
)
# Zurücksetzen der Singleton-Instanz
Mars
.
_instance
=
None
# Erstelle eine neue Mars-Instanz mit einem anderen Plateau
plateau2
=
Plateau
(
10
,
10
)
mars2
=
Mars
(
plateau2
)
# Überprüfe, ob die neue Instanz ein anderes Objekt ist als die ursprüngliche Referenz
self
.
assertIsNot
(
mars_ref
,
mars2
,
"
Nach dem Zurücksetzen sollte eine neue Instanz erstellt werden
"
)
# Erstelle eine weitere Instanz
mars3
=
Mars
()
# Überprüfe, ob die neuen Instanzen dasselbe Objekt sind
self
.
assertIs
(
mars2
,
mars3
,
"
Neue Mars-Instanzen sollten dasselbe Objekt sein
"
)
# Überprüfe, ob beide das neue Plateau haben
self
.
assertIs
(
mars2
.
get_plateau
(),
plateau2
)
self
.
assertIs
(
mars3
.
get_plateau
(),
plateau2
)
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