From 4dbb6c2a328e5a2592098f6df5bc897d3d1f17d7 Mon Sep 17 00:00:00 2001 From: "B.Spaqi.inf22" <b.spaqi.inf22@stud.bbbaden.ch> Date: Thu, 3 Apr 2025 09:49:51 +0000 Subject: [PATCH] Upload New File --- CasinoGameUnittests.cs | 117 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 CasinoGameUnittests.cs diff --git a/CasinoGameUnittests.cs b/CasinoGameUnittests.cs new file mode 100644 index 0000000..32d3bd4 --- /dev/null +++ b/CasinoGameUnittests.cs @@ -0,0 +1,117 @@ +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); + } + } +} -- GitLab