From 0de20200f5432a0f79308e657ab757003eacc3e4 Mon Sep 17 00:00:00 2001 From: Martin Berg Alstad <600878@stud.hvl.no> Date: Thu, 13 Jul 2023 14:00:42 +0200 Subject: [PATCH] Merged interfaces to classes --- .../Controllers/GameControllerTests.cs | 6 ++---- BackendTests/Services/ActionServiceTests.cs | 1 - BackendTests/Services/GameGroupTests.cs | 2 +- .../Services/WebSocketServiceTests.cs | 7 ++++--- BackendTests/TestUtils/Players.cs | 3 +-- BackendTests/Utils/ExtensionsTests.cs | 10 ++++++++-- pac-man-board-game/Game/Interfaces/IBox.cs | 9 --------- pac-man-board-game/Game/Interfaces/IPellet.cs | 6 ------ pac-man-board-game/Game/Interfaces/IPlayer.cs | 19 ------------------- pac-man-board-game/Game/Items/Box.cs | 2 -- pac-man-board-game/Game/Items/Pellet.cs | 7 +++++-- pac-man-board-game/Game/Items/Player.cs | 18 ++++++++++++++++-- .../Interfaces/IWebSocketService.cs | 2 +- pac-man-board-game/Services/ActionService.cs | 1 - pac-man-board-game/Services/GameGroup.cs | 4 ++-- .../Services/WebSocketService.cs | 2 +- 16 files changed, 41 insertions(+), 58 deletions(-) delete mode 100644 pac-man-board-game/Game/Interfaces/IBox.cs delete mode 100644 pac-man-board-game/Game/Interfaces/IPellet.cs delete mode 100644 pac-man-board-game/Game/Interfaces/IPlayer.cs diff --git a/BackendTests/Controllers/GameControllerTests.cs b/BackendTests/Controllers/GameControllerTests.cs index 167c3f0..99dc3d2 100644 --- a/BackendTests/Controllers/GameControllerTests.cs +++ b/BackendTests/Controllers/GameControllerTests.cs @@ -1,6 +1,4 @@ namespace BackendTests.Controllers; -public class GameControllerTests -{ - -} +public class GameControllerTests // TODO +{ } diff --git a/BackendTests/Services/ActionServiceTests.cs b/BackendTests/Services/ActionServiceTests.cs index 279df64..bb43dda 100644 --- a/BackendTests/Services/ActionServiceTests.cs +++ b/BackendTests/Services/ActionServiceTests.cs @@ -3,7 +3,6 @@ using BackendTests.TestUtils; using Microsoft.Extensions.Logging; using NSubstitute; using pacMan.Game; -using pacMan.Game.Interfaces; using pacMan.Game.Items; using pacMan.Interfaces; using pacMan.Services; diff --git a/BackendTests/Services/GameGroupTests.cs b/BackendTests/Services/GameGroupTests.cs index b84518f..f9c2196 100644 --- a/BackendTests/Services/GameGroupTests.cs +++ b/BackendTests/Services/GameGroupTests.cs @@ -1,7 +1,7 @@ using BackendTests.TestUtils; using pacMan.Exceptions; using pacMan.Game; -using pacMan.Game.Interfaces; +using pacMan.Game.Items; using pacMan.Services; using pacMan.Utils; diff --git a/BackendTests/Services/WebSocketServiceTests.cs b/BackendTests/Services/WebSocketServiceTests.cs index 3066a38..8ac2819 100644 --- a/BackendTests/Services/WebSocketServiceTests.cs +++ b/BackendTests/Services/WebSocketServiceTests.cs @@ -9,7 +9,7 @@ using pacMan.Utils; namespace BackendTests.Services; -public class WebSocketServiceTests // TODO: Implement +public class WebSocketServiceTests { private IWebSocketService _service = null!; @@ -136,7 +136,7 @@ public class WebSocketServiceTests // TODO: Implement { var player = Players.Create("white"); var group = _service.AddPlayer(player); - + Assert.Multiple(() => { Assert.That(group.Players, Has.Count.EqualTo(1)); @@ -148,11 +148,12 @@ public class WebSocketServiceTests // TODO: Implement [Test] public void AddPlayer_ToFullGroup() { - for (int i = 0; i < 4; i++) + for (var i = 0; i < 4; i++) { var player = Players.Create(i.ToString()); _service.AddPlayer(player); } + var player5 = Players.Create("white"); var group = _service.AddPlayer(player5); diff --git a/BackendTests/TestUtils/Players.cs b/BackendTests/TestUtils/Players.cs index 3171be8..5a80657 100644 --- a/BackendTests/TestUtils/Players.cs +++ b/BackendTests/TestUtils/Players.cs @@ -1,10 +1,9 @@ using pacMan.Game; -using pacMan.Game.Interfaces; using pacMan.Game.Items; namespace BackendTests.TestUtils; -public class Players +internal static class Players { internal static IPlayer Create(string colour) => new Player diff --git a/BackendTests/Utils/ExtensionsTests.cs b/BackendTests/Utils/ExtensionsTests.cs index 86c5723..2d6f2bb 100644 --- a/BackendTests/Utils/ExtensionsTests.cs +++ b/BackendTests/Utils/ExtensionsTests.cs @@ -51,13 +51,19 @@ public class ExtensionsTests [Test] public void GetString_NegativeLength() { - Assert.Throws(typeof(ArgumentOutOfRangeException), () => _bytes.GetString(-1)); + Assert.Throws(() => _bytes.GetString(-1)); } [Test] public void GetString_LengthGreaterThanByteArrayLength() { - Assert.Throws(typeof(ArgumentOutOfRangeException), () => _bytes.GetString(_bytes.Length + 1)); + Assert.Throws(() => _bytes.GetString(_bytes.Length + 1)); + } + + [Test] + public void GetString_LengthShorterThanByteArrayLength() + { + Assert.That(_bytes.GetString(_bytes.Length / 2), Is.EqualTo("Hello ")); } #endregion diff --git a/pac-man-board-game/Game/Interfaces/IBox.cs b/pac-man-board-game/Game/Interfaces/IBox.cs deleted file mode 100644 index 6d2b03b..0000000 --- a/pac-man-board-game/Game/Interfaces/IBox.cs +++ /dev/null @@ -1,9 +0,0 @@ -using pacMan.Game.Items; - -namespace pacMan.Game.Interfaces; - -public interface IBox : IEnumerable -{ - int CountNormal { get; } - void Add(Pellet pellet); -} \ No newline at end of file diff --git a/pac-man-board-game/Game/Interfaces/IPellet.cs b/pac-man-board-game/Game/Interfaces/IPellet.cs deleted file mode 100644 index 39b8f34..0000000 --- a/pac-man-board-game/Game/Interfaces/IPellet.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace pacMan.Game.Interfaces; - -public interface IPellet -{ - bool IsPowerPellet { get; init; } -} \ No newline at end of file diff --git a/pac-man-board-game/Game/Interfaces/IPlayer.cs b/pac-man-board-game/Game/Interfaces/IPlayer.cs deleted file mode 100644 index d7c2611..0000000 --- a/pac-man-board-game/Game/Interfaces/IPlayer.cs +++ /dev/null @@ -1,19 +0,0 @@ -using pacMan.Game.Items; - -namespace pacMan.Game.Interfaces; - -public interface IPlayer -{ - string Name { get; init; } - Character PacMan { get; init; } - string Colour { get; init; } - Box Box { get; init; } - State State { get; set; } -} - -public enum State -{ - WaitingForPlayers, - Ready, - InGame -} \ No newline at end of file diff --git a/pac-man-board-game/Game/Items/Box.cs b/pac-man-board-game/Game/Items/Box.cs index e595fc7..3e3bf66 100644 --- a/pac-man-board-game/Game/Items/Box.cs +++ b/pac-man-board-game/Game/Items/Box.cs @@ -1,5 +1,3 @@ -using pacMan.Game.Interfaces; - namespace pacMan.Game.Items; public class Box : IEquatable diff --git a/pac-man-board-game/Game/Items/Pellet.cs b/pac-man-board-game/Game/Items/Pellet.cs index 69078f2..ed01bac 100644 --- a/pac-man-board-game/Game/Items/Pellet.cs +++ b/pac-man-board-game/Game/Items/Pellet.cs @@ -1,7 +1,10 @@ -using pacMan.Game.Interfaces; - namespace pacMan.Game.Items; +public interface IPellet +{ + bool IsPowerPellet { get; init; } +} + public class Pellet : IPellet, IEquatable { public bool Equals(Pellet? other) diff --git a/pac-man-board-game/Game/Items/Player.cs b/pac-man-board-game/Game/Items/Player.cs index 8cfb95b..ff909cc 100644 --- a/pac-man-board-game/Game/Items/Player.cs +++ b/pac-man-board-game/Game/Items/Player.cs @@ -1,7 +1,21 @@ -using pacMan.Game.Interfaces; - namespace pacMan.Game.Items; +public interface IPlayer +{ + string Name { get; init; } + Character PacMan { get; init; } + string Colour { get; init; } + Box Box { get; init; } + State State { get; set; } +} + +public enum State +{ + WaitingForPlayers, + Ready, + InGame +} + public class Player : IPlayer, IEquatable { public bool Equals(Player? other) diff --git a/pac-man-board-game/Interfaces/IWebSocketService.cs b/pac-man-board-game/Interfaces/IWebSocketService.cs index edd26fe..d8095b9 100644 --- a/pac-man-board-game/Interfaces/IWebSocketService.cs +++ b/pac-man-board-game/Interfaces/IWebSocketService.cs @@ -1,5 +1,5 @@ using System.Net.WebSockets; -using pacMan.Game.Interfaces; +using pacMan.Game.Items; using pacMan.Services; namespace pacMan.Interfaces; diff --git a/pac-man-board-game/Services/ActionService.cs b/pac-man-board-game/Services/ActionService.cs index d2ccffa..55128ae 100644 --- a/pac-man-board-game/Services/ActionService.cs +++ b/pac-man-board-game/Services/ActionService.cs @@ -1,7 +1,6 @@ using System.Text.Json; using Microsoft.CSharp.RuntimeBinder; using pacMan.Game; -using pacMan.Game.Interfaces; using pacMan.Game.Items; using pacMan.Interfaces; diff --git a/pac-man-board-game/Services/GameGroup.cs b/pac-man-board-game/Services/GameGroup.cs index 337975e..5dd1f48 100644 --- a/pac-man-board-game/Services/GameGroup.cs +++ b/pac-man-board-game/Services/GameGroup.cs @@ -1,7 +1,7 @@ using System.Collections; using pacMan.Exceptions; using pacMan.Game; -using pacMan.Game.Interfaces; +using pacMan.Game.Items; namespace pacMan.Services; @@ -10,7 +10,7 @@ public class GameGroup : IEnumerable private readonly Random _random = new(); public List Players { get; } = new(); - public IPlayer RandomPlayer => Players[_random.Next(Players.Count)]; + public IPlayer RandomPlayer => Players[_random.Next(Count)]; public int Count => Players.Count; public IEnumerator GetEnumerator() => Players.GetEnumerator(); diff --git a/pac-man-board-game/Services/WebSocketService.cs b/pac-man-board-game/Services/WebSocketService.cs index 7b13d7e..8f32d49 100644 --- a/pac-man-board-game/Services/WebSocketService.cs +++ b/pac-man-board-game/Services/WebSocketService.cs @@ -1,5 +1,5 @@ using System.Net.WebSockets; -using pacMan.Game.Interfaces; +using pacMan.Game.Items; using pacMan.Interfaces; using pacMan.Utils;