Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LA_426_8054_GitLab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
B.Spaqi.inf22
LA_426_8054_GitLab
Commits
4dbb6c2a
Commit
4dbb6c2a
authored
2 weeks ago
by
B.Spaqi.inf22
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
1e3f2850
Branches
main
No related tags found
No related merge requests found
Pipeline
#5123
failed
2 weeks ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CasinoGameUnittests.cs
+117
-0
117 additions, 0 deletions
CasinoGameUnittests.cs
with
117 additions
and
0 deletions
CasinoGameUnittests.cs
0 → 100644
+
117
−
0
View file @
4dbb6c2a
using
System
;
namespace
CasinoGameTests
{
[
TestClass
]
public
class
CasinoGameUnitTests
{
private
class
TestObserver
:
IObserver
{
public
string
LastMessage
{
get
;
private
set
;
}
public
void
Update
(
string
message
)
=>
LastMessage
=
message
;
}
[
TestMethod
]
public
void
ObserverReceivesNotification
()
{
CasinoGame
game
=
new
CasinoGame
();
TestObserver
observer
=
new
TestObserver
();
game
.
Attach
(
observer
);
game
.
Notify
(
"Test Nachricht"
);
Assert
.
AreEqual
(
"Test Nachricht"
,
observer
.
LastMessage
);
}
[
TestMethod
]
public
void
ObserverCanBeDetached
()
{
CasinoGame
game
=
new
CasinoGame
();
TestObserver
observer
=
new
TestObserver
();
game
.
Attach
(
observer
);
game
.
Detach
(
observer
);
game
.
Notify
(
"Test Nachricht"
);
Assert
.
IsNull
(
observer
.
LastMessage
);
}
}
[
TestClass
]
public
class
BalanceManagerTests
{
[
TestMethod
]
public
void
InitialBalance_IsCorrect
()
{
Assert
.
AreEqual
(
1000
,
BalanceManager
.
Instance
.
Balance
);
}
[
TestMethod
]
public
void
BalanceCanBeModified
()
{
BalanceManager
.
Instance
.
Balance
=
500
;
Assert
.
AreEqual
(
500
,
BalanceManager
.
Instance
.
Balance
);
}
}
[
TestClass
]
public
class
RouletteTests
{
private
Casino
casino
;
[
TestInitialize
]
public
void
Setup
()
{
casino
=
new
Casino
();
}
[
TestMethod
]
public
void
IsWinningBet_CorrectlyIdentifiesWin
()
{
Assert
.
IsTrue
(
casino
.
IsWinningBet
(
"rot"
,
1
));
// 1 ist eine rote Zahl
Assert
.
IsFalse
(
casino
.
IsWinningBet
(
"schwarz"
,
1
));
// 1 ist nicht schwarz
}
[
TestMethod
]
public
void
CalculateWinnings_CorrectValues
()
{
Assert
.
AreEqual
(
3600
,
casino
.
CalculateWinnings
(
"0"
,
100
));
// 0 zahlt x36
Assert
.
AreEqual
(
3500
,
casino
.
CalculateWinnings
(
"5"
,
100
));
// Einzelzahl x35
Assert
.
AreEqual
(
300
,
casino
.
CalculateWinnings
(
"1-12"
,
100
));
// Drittel x3
Assert
.
AreEqual
(
200
,
casino
.
CalculateWinnings
(
"schwarz"
,
100
));
// 1:1 Wetten
}
}
[
TestClass
]
public
class
BlackjackTests
{
private
Casino
casino
;
[
TestInitialize
]
public
void
Setup
()
{
casino
=
new
Casino
();
}
[
TestMethod
]
public
void
GetHandValue_AceAdjustsCorrectly
()
{
List
<
int
>
hand
=
new
List
<
int
>
{
1
,
10
};
// Ass und 10
Assert
.
AreEqual
(
21
,
casino
.
GetHandValue
(
hand
));
hand
=
new
List
<
int
>
{
1
,
10
,
10
};
// Ass, 10, 10 -> Ass zählt als 1
Assert
.
AreEqual
(
21
,
casino
.
GetHandValue
(
hand
));
hand
=
new
List
<
int
>
{
1
,
1
,
8
};
// Zwei Asse und eine 8 -> Ass als 1
Assert
.
AreEqual
(
20
,
casino
.
GetHandValue
(
hand
));
}
[
TestMethod
]
public
void
DealerPlay_HitsUntilThreshold
()
{
List
<
int
>
dealerHand
=
new
List
<
int
>
{
2
,
3
};
// Summe 5
casino
.
DealerPlay
(
ref
dealerHand
);
Assert
.
IsTrue
(
casino
.
GetHandValue
(
dealerHand
)
>=
17
);
}
}
}
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