From 9ea98eaa90280b68061b08b21c1865ef4854ad50 Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Fri, 7 Jun 2024 17:38:12 +0200 Subject: [PATCH] Fixed code smell + added test --- Qwirkle/Files/Game.xml | 2 +- Qwirkle/QwirkleClassLibrary/Boards/Cell.cs | 4 ++-- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 2 +- Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs | 2 +- Qwirkle/TestBase/TestGame.cs | 17 +++++++++++++++++ 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Qwirkle/Files/Game.xml b/Qwirkle/Files/Game.xml index 1683161..c55059d 100644 --- a/Qwirkle/Files/Game.xml +++ b/Qwirkle/Files/Game.xml @@ -1 +1 @@ -false1714000102030405060708090100110120130140150161011121314151617181911011111211311411511620212223242526272829210211212213214215216303132333435363738393103113123133143153164041424344454647484941041141241341441541650515253545556575859510511512513514515516606162636465666768696106116126136146156167071727374757677787971071171271371471571680818283848586878889810811812813814815816909192939495969798999109119129139149159161001011021031041051061071081091010101110121013101410151016110111112113114115116117118119111011111112111311141115111612012112212312412512612712812912101211121212131214121512161301311321331341351361371381391310131113121313131413151316 \ No newline at end of file +false1714001020304050607080901001101201301401501600111213141516171819110111112113114115116102122232425262728292102112122132142152162031323334353637383931031131231331431531630414243444546474849410411412413414415416405152535455565758595105115125135145155165061626364656667686961061161261361461561660717273747576777879710711712713714715716708182838485868788898108118128138148158168091929394959697989991091191291391491591690101102103104105106107108109101010111012101310141015101610011111211311411511611711811911101111111211131114111511161101211221231241251261271281291210121112121213121412151216120131132133134135136137138139131013111312131313141315131613 \ No newline at end of file diff --git a/Qwirkle/QwirkleClassLibrary/Boards/Cell.cs b/Qwirkle/QwirkleClassLibrary/Boards/Cell.cs index 0f470dc..68deb01 100644 --- a/Qwirkle/QwirkleClassLibrary/Boards/Cell.cs +++ b/Qwirkle/QwirkleClassLibrary/Boards/Cell.cs @@ -61,7 +61,7 @@ public class Cell : INotifyPropertyChanged /// True if the cell is empty, false if the cell contains a tile. public bool IsFree { - get { return Tile == null; } + get { return Tile! == null!; } } @@ -72,7 +72,7 @@ public class Cell : INotifyPropertyChanged /// True if added succefully (if the cell didn't already contain a tile), false if there already was a tile in this cell. public bool SetTile(Tile addedTile) { - if (Tile == null) + if (Tile! == null!) { Tile = addedTile; diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index b4d8f61..2b1568e 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -559,7 +559,7 @@ namespace QwirkleClassLibrary.Games /// /// /// - private static bool CheckTileInCompletedLines(Tile? t1, ref int nbTiles, ref List checkdoubles) + public static bool CheckTileInCompletedLines(Tile? t1, ref int nbTiles, ref List checkdoubles) { if (t1! != null!) { diff --git a/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs b/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs index 4752c67..45bd8c6 100644 --- a/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs @@ -62,7 +62,7 @@ namespace QwirkleClassLibrary.Tiles { if (obj == null) { - throw new NullReferenceException(); + throw new NullReferenceException("The object is null."); } var otherTile = obj as Tile; diff --git a/Qwirkle/TestBase/TestGame.cs b/Qwirkle/TestBase/TestGame.cs index d479be3..ee641ba 100644 --- a/Qwirkle/TestBase/TestGame.cs +++ b/Qwirkle/TestBase/TestGame.cs @@ -381,6 +381,23 @@ public class TestGame } + [Fact] + public void Test_CheckTileInCompletedLines() + { + + int nbTiles = 0; + var checkdoubles = new List() + { + new(Shape.Club, Color.Blue), + new(Shape.Club, Color.Red), + new(Shape.Club, Color.Green), + }; + + var t1 = new Tile(Shape.Club, Color.Green); + + Assert.False(Game.CheckTileInCompletedLines(t1, ref nbTiles, ref checkdoubles)); + } + [Theory] [InlineData(3, 1, 4, 1, 5, 1, 5)] [InlineData(2, 2, 3, 2, 4, 2, 5)]