From 3850cc8873905f0a14af75b460405f74935a7569 Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Wed, 10 Apr 2024 19:31:26 +0200 Subject: [PATCH] optimized board class + added 1 test that fucking doesn't work --- Qwirkle/QwirkleClassLibrary/Board.cs | 12 +----------- Qwirkle/QwirkleClassLibrary/Cell.cs | 5 +++++ Qwirkle/TestBase/TestCell.cs | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 Qwirkle/TestBase/TestCell.cs diff --git a/Qwirkle/QwirkleClassLibrary/Board.cs b/Qwirkle/QwirkleClassLibrary/Board.cs index 55af03d..ea182d1 100644 --- a/Qwirkle/QwirkleClassLibrary/Board.cs +++ b/Qwirkle/QwirkleClassLibrary/Board.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -// ReSharper disable All namespace QwirkleClassLibrary { @@ -31,16 +30,7 @@ namespace QwirkleClassLibrary { if (this.Cells[i].GetX == x && this.Cells[i].GetY == y) { - if (Cells[i].IsFree == true) - { - return Cells[i].SetTile(tile); - - } - else - { - return false; - } - + return Cells[i].IsFree == false && Cells[i].SetTile(tile); } } return false; diff --git a/Qwirkle/QwirkleClassLibrary/Cell.cs b/Qwirkle/QwirkleClassLibrary/Cell.cs index 44e0535..9108fe5 100644 --- a/Qwirkle/QwirkleClassLibrary/Cell.cs +++ b/Qwirkle/QwirkleClassLibrary/Cell.cs @@ -11,6 +11,11 @@ public class Cell public Cell(int x, int y) { + if (this.x < 0 || this.y < 0) + { + throw new ArgumentException(""); + } + this.x = x; this.y = y; } diff --git a/Qwirkle/TestBase/TestCell.cs b/Qwirkle/TestBase/TestCell.cs new file mode 100644 index 0000000..07cc6a3 --- /dev/null +++ b/Qwirkle/TestBase/TestCell.cs @@ -0,0 +1,21 @@ +using QwirkleClassLibrary; +namespace TestBase; + +public class TestCell +{ + [Theory] + [InlineData(true, 10, 20, 10, 20)] + [InlineData(false, -10, 20, -10, 20)] + + public void Test_CellConstructor(bool isValid, int expectedX, int expectedY, int x, int y) + { + if (!isValid) + { + Assert.Throws(() => new Cell(x, y)); + } + + Cell c = new Cell(x, y); + Assert.Equal(expectedX, x); + Assert.Equal(expectedY, y); + } +} \ No newline at end of file