From b606f763d280e6b29ccd5c7fa7911703d7c0222b Mon Sep 17 00:00:00 2001 From: scrubzz Date: Mon, 21 May 2018 21:10:34 +0200 Subject: [PATCH 1/7] Area Get method implemented Area Get tests implemented --- Tests/TwoDimension/AreaTests.cs | 23 ++++++++++++++++--- .../Implementation/TwoDimension/Area.cs | 8 +++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Tests/TwoDimension/AreaTests.cs b/Tests/TwoDimension/AreaTests.cs index fa861bb..d8c5341 100644 --- a/Tests/TwoDimension/AreaTests.cs +++ b/Tests/TwoDimension/AreaTests.cs @@ -170,9 +170,26 @@ public void PositionSet() [Test] public void PositionGet() { - // TODO: Issue 6 (https://github.com/Wizcorp/TileSystem/issues/6) - Assert.Fail(); - } + Area area = new Area(); + var mockLevel = new Mock(); + var mockPosition = new Mock(); + var mockTile = new Mock(); + var tilePosition = new Position2D(0, 0); + var tilePositionNotFound = new Position2D(1, 0); + + area.SetPosition(mockLevel.Object, mockPosition.Object); + mockTile.Object.SetPosition(area, tilePosition); + area.Add(mockTile.Object); + + // Test Nulls + Assert.That(() => area.Get(null), Throws.ArgumentNullException); + + // Test Same Tile + Assert.AreSame(mockTile.Object, area.Get(tilePosition)); + + // Test Tile Not Found + Assert.AreNotSame(mockTile.Object, area.Get(tilePositionNotFound)); + } [Test] public void PositionGetNeighbours() diff --git a/TileSystem/Implementation/TwoDimension/Area.cs b/TileSystem/Implementation/TwoDimension/Area.cs index 729705f..992c0f5 100644 --- a/TileSystem/Implementation/TwoDimension/Area.cs +++ b/TileSystem/Implementation/TwoDimension/Area.cs @@ -141,8 +141,12 @@ public virtual bool Remove(ITile tile) /// Tile instance or null public ITile Get(IPosition position) { - // TODO: Issue 6 (https://github.com/Wizcorp/TileSystem/issues/6) - throw new NotImplementedException(); + if (position == null) + { + throw new ArgumentNullException("position", "Position can not be null"); + } + + return tiles.Find(tile => tile.Position.CompareTo(position) == 0); } /// From 39e53990f100245f4102075b1cac9ba22d6e6c4b Mon Sep 17 00:00:00 2001 From: scrubzz Date: Mon, 21 May 2018 22:58:29 +0200 Subject: [PATCH 2/7] Implementing Area GetNeighbours Method Implementing Area GetNeighbours Tests --- Tests/TwoDimension/AreaTests.cs | 37 +++++++++++++++++-- .../Implementation/TwoDimension/Area.cs | 26 +++++++++++-- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/Tests/TwoDimension/AreaTests.cs b/Tests/TwoDimension/AreaTests.cs index d8c5341..956332e 100644 --- a/Tests/TwoDimension/AreaTests.cs +++ b/Tests/TwoDimension/AreaTests.cs @@ -194,8 +194,37 @@ public void PositionGet() [Test] public void PositionGetNeighbours() { - // TODO: Issue 6 (https://github.com/Wizcorp/TileSystem/issues/6) - Assert.Fail(); - } - } + Area area = new Area(); + var mockLevel = new Mock(); + var mockPosition = new Mock(); + var mockTile = new Mock(); + var tilePosition = new Position2D(0, 0); + var mockTileNotInArea = new Mock(); + var mockFirstNeighbourTile = new Mock(); + var firstNeighbourTilePosition = new Position2D(1, 0); + var mockSecondNeighbourTile = new Mock(); + var secondNeighbourTilePosition = new Position2D(1, 1); + + area.SetPosition(mockLevel.Object, mockPosition.Object); + mockTile.Object.SetPosition(area, tilePosition); + area.Add(mockTile.Object); + + // Test Nulls + Assert.That(() => area.GetNeighbours(null), Throws.ArgumentNullException); + + // Test Tile Not In Area + Assert.That(() => area.GetNeighbours(mockTileNotInArea.Object), Throws.ArgumentException); + + // Test No Neighbours + Assert.Null(area.GetNeighbours(mockTile.Object)); + + // Test One Or More Neighbours + mockFirstNeighbourTile.Object.SetPosition(area, firstNeighbourTilePosition); + area.Add(mockFirstNeighbourTile.Object); + Assert.IsTrue(area.GetNeighbours(mockTile.Object).Count == 1); + mockSecondNeighbourTile.Object.SetPosition(area, secondNeighbourTilePosition); + area.Add(mockSecondNeighbourTile.Object); + Assert.IsTrue(area.GetNeighbours(mockTile.Object).Count == 2); + } + } } diff --git a/TileSystem/Implementation/TwoDimension/Area.cs b/TileSystem/Implementation/TwoDimension/Area.cs index 992c0f5..dac0fde 100644 --- a/TileSystem/Implementation/TwoDimension/Area.cs +++ b/TileSystem/Implementation/TwoDimension/Area.cs @@ -156,9 +156,29 @@ public ITile Get(IPosition position) /// List of neighbours or null public List GetNeighbours(ITile tile) { - // TODO: Issue 6 (https://github.com/Wizcorp/TileSystem/issues/6) - throw new NotImplementedException(); - } + if (tile == null) + { + throw new ArgumentNullException("tile", "Tile can not be null"); + } + + if (tiles.Contains(tile) == false) + { + throw new ArgumentException("Tile not in Area", "tile"); + } + + List neigbourTiles = tiles.FindAll(t => + Math.Abs(((Position2D)t.Position).X - ((Position2D)tile.Position).X) == 1 || + Math.Abs(((Position2D)t.Position).Y - ((Position2D)tile.Position).Y) == 1); + + if (neigbourTiles.Count <= 0) + { + return null; + } + else + { + return neigbourTiles; + } + } /// /// Destroy this area and emit the event From 46354eb97126a5a199c102f34266335778753c53 Mon Sep 17 00:00:00 2001 From: scrubzz Date: Mon, 21 May 2018 23:07:02 +0200 Subject: [PATCH 3/7] Adding a test for Area GetNeighbours --- Tests/TwoDimension/AreaTests.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tests/TwoDimension/AreaTests.cs b/Tests/TwoDimension/AreaTests.cs index 956332e..c01ed1d 100644 --- a/Tests/TwoDimension/AreaTests.cs +++ b/Tests/TwoDimension/AreaTests.cs @@ -204,6 +204,8 @@ public void PositionGetNeighbours() var firstNeighbourTilePosition = new Position2D(1, 0); var mockSecondNeighbourTile = new Mock(); var secondNeighbourTilePosition = new Position2D(1, 1); + var mockNotANeighbourTile = new Mock(); + var notANeighbourTilePosition = new Position2D(4, 0); area.SetPosition(mockLevel.Object, mockPosition.Object); mockTile.Object.SetPosition(area, tilePosition); @@ -225,6 +227,9 @@ public void PositionGetNeighbours() mockSecondNeighbourTile.Object.SetPosition(area, secondNeighbourTilePosition); area.Add(mockSecondNeighbourTile.Object); Assert.IsTrue(area.GetNeighbours(mockTile.Object).Count == 2); + mockNotANeighbourTile.Object.SetPosition(area, notANeighbourTilePosition); + area.Add(mockNotANeighbourTile.Object); + Assert.IsTrue(area.GetNeighbours(mockTile.Object).Count == 2); } } } From 823cf8c1fe3c3a1373e12d60e1cc2bd0fc66d497 Mon Sep 17 00:00:00 2001 From: scrubzz Date: Mon, 28 May 2018 19:57:19 +0200 Subject: [PATCH 4/7] Fix : Replacing spaces for tabs for proper indentation --- Tests/TwoDimension/AreaTests.cs | 104 +++++++++--------- .../Implementation/TwoDimension/Area.cs | 54 ++++----- 2 files changed, 80 insertions(+), 78 deletions(-) diff --git a/Tests/TwoDimension/AreaTests.cs b/Tests/TwoDimension/AreaTests.cs index c01ed1d..ea2cf03 100644 --- a/Tests/TwoDimension/AreaTests.cs +++ b/Tests/TwoDimension/AreaTests.cs @@ -170,66 +170,68 @@ public void PositionSet() [Test] public void PositionGet() { - Area area = new Area(); - var mockLevel = new Mock(); - var mockPosition = new Mock(); - var mockTile = new Mock(); - var tilePosition = new Position2D(0, 0); - var tilePositionNotFound = new Position2D(1, 0); + Area area = new Area(); + var mockLevel = new Mock(); + var mockPosition = new Mock(); + var mockTile = new Mock(); + var tilePosition = new Position2D(0, 0); + var tilePositionNotFound = new Position2D(1, 0); - area.SetPosition(mockLevel.Object, mockPosition.Object); - mockTile.Object.SetPosition(area, tilePosition); - area.Add(mockTile.Object); + area.SetPosition(mockLevel.Object, mockPosition.Object); + mockTile.Object.SetPosition(area, tilePosition); + area.Add(mockTile.Object); - // Test Nulls - Assert.That(() => area.Get(null), Throws.ArgumentNullException); + // Test Nulls + Assert.That(() => area.Get(null), Throws.ArgumentNullException); - // Test Same Tile - Assert.AreSame(mockTile.Object, area.Get(tilePosition)); + // Test Same Tile + Assert.AreSame(mockTile.Object, area.Get(tilePosition)); - // Test Tile Not Found - Assert.AreNotSame(mockTile.Object, area.Get(tilePositionNotFound)); + // Test Tile Not Found + Assert.AreNotSame(mockTile.Object, area.Get(tilePositionNotFound)); } [Test] public void PositionGetNeighbours() { - Area area = new Area(); - var mockLevel = new Mock(); - var mockPosition = new Mock(); - var mockTile = new Mock(); - var tilePosition = new Position2D(0, 0); - var mockTileNotInArea = new Mock(); - var mockFirstNeighbourTile = new Mock(); - var firstNeighbourTilePosition = new Position2D(1, 0); - var mockSecondNeighbourTile = new Mock(); - var secondNeighbourTilePosition = new Position2D(1, 1); - var mockNotANeighbourTile = new Mock(); - var notANeighbourTilePosition = new Position2D(4, 0); - - area.SetPosition(mockLevel.Object, mockPosition.Object); - mockTile.Object.SetPosition(area, tilePosition); - area.Add(mockTile.Object); - - // Test Nulls - Assert.That(() => area.GetNeighbours(null), Throws.ArgumentNullException); - - // Test Tile Not In Area - Assert.That(() => area.GetNeighbours(mockTileNotInArea.Object), Throws.ArgumentException); - - // Test No Neighbours - Assert.Null(area.GetNeighbours(mockTile.Object)); - - // Test One Or More Neighbours - mockFirstNeighbourTile.Object.SetPosition(area, firstNeighbourTilePosition); - area.Add(mockFirstNeighbourTile.Object); - Assert.IsTrue(area.GetNeighbours(mockTile.Object).Count == 1); - mockSecondNeighbourTile.Object.SetPosition(area, secondNeighbourTilePosition); - area.Add(mockSecondNeighbourTile.Object); - Assert.IsTrue(area.GetNeighbours(mockTile.Object).Count == 2); - mockNotANeighbourTile.Object.SetPosition(area, notANeighbourTilePosition); - area.Add(mockNotANeighbourTile.Object); - Assert.IsTrue(area.GetNeighbours(mockTile.Object).Count == 2); + Area area = new Area(); + var mockLevel = new Mock(); + var mockPosition = new Mock(); + var mockTile = new Mock(); + var tilePosition = new Position2D(0, 0); + var mockTileNotInArea = new Mock(); + var mockFirstNeighbourTile = new Mock(); + var firstNeighbourTilePosition = new Position2D(1, 0); + var mockSecondNeighbourTile = new Mock(); + var secondNeighbourTilePosition = new Position2D(1, 1); + var mockNotANeighbourTile = new Mock(); + var notANeighbourTilePosition = new Position2D(4, 0); + + area.SetPosition(mockLevel.Object, mockPosition.Object); + mockTile.Object.SetPosition(area, tilePosition); + area.Add(mockTile.Object); + + // Test Nulls + Assert.That(() => area.GetNeighbours(null), Throws.ArgumentNullException); + + // Test Tile Not In Area + Assert.That(() => area.GetNeighbours(mockTileNotInArea.Object), Throws.ArgumentException); + + // Test No Neighbours + Assert.Null(area.GetNeighbours(mockTile.Object)); + + // Test One Or More Neighbours + mockFirstNeighbourTile.Object.SetPosition(area, firstNeighbourTilePosition); + area.Add(mockFirstNeighbourTile.Object); + Assert.IsTrue(area.GetNeighbours(mockTile.Object).Count == 1); + + mockSecondNeighbourTile.Object.SetPosition(area, secondNeighbourTilePosition); + area.Add(mockSecondNeighbourTile.Object); + Assert.IsTrue(area.GetNeighbours(mockTile.Object).Count == 2); + + mockNotANeighbourTile.Object.SetPosition(area, notANeighbourTilePosition); + area.Add(mockNotANeighbourTile.Object); + Assert.IsTrue(area.GetNeighbours(mockTile.Object).Count == 2); } } } diff --git a/TileSystem/Implementation/TwoDimension/Area.cs b/TileSystem/Implementation/TwoDimension/Area.cs index dac0fde..9684169 100644 --- a/TileSystem/Implementation/TwoDimension/Area.cs +++ b/TileSystem/Implementation/TwoDimension/Area.cs @@ -141,12 +141,12 @@ public virtual bool Remove(ITile tile) /// Tile instance or null public ITile Get(IPosition position) { - if (position == null) - { - throw new ArgumentNullException("position", "Position can not be null"); - } + if (position == null) + { + throw new ArgumentNullException("position", "Position can not be null"); + } - return tiles.Find(tile => tile.Position.CompareTo(position) == 0); + return tiles.Find(tile => tile.Position.CompareTo(position) == 0); } /// @@ -156,28 +156,28 @@ public ITile Get(IPosition position) /// List of neighbours or null public List GetNeighbours(ITile tile) { - if (tile == null) - { - throw new ArgumentNullException("tile", "Tile can not be null"); - } - - if (tiles.Contains(tile) == false) - { - throw new ArgumentException("Tile not in Area", "tile"); - } - - List neigbourTiles = tiles.FindAll(t => - Math.Abs(((Position2D)t.Position).X - ((Position2D)tile.Position).X) == 1 || - Math.Abs(((Position2D)t.Position).Y - ((Position2D)tile.Position).Y) == 1); - - if (neigbourTiles.Count <= 0) - { - return null; - } - else - { - return neigbourTiles; - } + if (tile == null) + { + throw new ArgumentNullException("tile", "Tile can not be null"); + } + + if (tiles.Contains(tile) == false) + { + throw new ArgumentException("Tile not in Area", "tile"); + } + + List neigbourTiles = tiles.FindAll(t => + Math.Abs(((Position2D)t.Position).X - ((Position2D)tile.Position).X) == 1 || + Math.Abs(((Position2D)t.Position).Y - ((Position2D)tile.Position).Y) == 1); + + if (neigbourTiles.Count <= 0) + { + return null; + } + else + { + return neigbourTiles; + } } /// From f3339ffc796fe8bcee7d155e2619f70529bbdecd Mon Sep 17 00:00:00 2001 From: scrubzz Date: Mon, 28 May 2018 19:58:24 +0200 Subject: [PATCH 5/7] Fix : Replacing spaces for tabs for proper indentation. --- Tests/TwoDimension/AreaTests.cs | 6 +++--- TileSystem/Implementation/TwoDimension/Area.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/TwoDimension/AreaTests.cs b/Tests/TwoDimension/AreaTests.cs index ea2cf03..4da4b9c 100644 --- a/Tests/TwoDimension/AreaTests.cs +++ b/Tests/TwoDimension/AreaTests.cs @@ -189,7 +189,7 @@ public void PositionGet() // Test Tile Not Found Assert.AreNotSame(mockTile.Object, area.Get(tilePositionNotFound)); - } + } [Test] public void PositionGetNeighbours() @@ -232,6 +232,6 @@ public void PositionGetNeighbours() mockNotANeighbourTile.Object.SetPosition(area, notANeighbourTilePosition); area.Add(mockNotANeighbourTile.Object); Assert.IsTrue(area.GetNeighbours(mockTile.Object).Count == 2); - } - } + } + } } diff --git a/TileSystem/Implementation/TwoDimension/Area.cs b/TileSystem/Implementation/TwoDimension/Area.cs index 9684169..5510e5b 100644 --- a/TileSystem/Implementation/TwoDimension/Area.cs +++ b/TileSystem/Implementation/TwoDimension/Area.cs @@ -178,7 +178,7 @@ public List GetNeighbours(ITile tile) { return neigbourTiles; } - } + } /// /// Destroy this area and emit the event From 919834438e554759e7dee75c1a7207657bd64da6 Mon Sep 17 00:00:00 2001 From: scrubzz Date: Mon, 28 May 2018 19:59:37 +0200 Subject: [PATCH 6/7] Fix : Missed spaces. --- TileSystem/Implementation/TwoDimension/Area.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/TileSystem/Implementation/TwoDimension/Area.cs b/TileSystem/Implementation/TwoDimension/Area.cs index 5510e5b..75595b4 100644 --- a/TileSystem/Implementation/TwoDimension/Area.cs +++ b/TileSystem/Implementation/TwoDimension/Area.cs @@ -143,7 +143,7 @@ public ITile Get(IPosition position) { if (position == null) { - throw new ArgumentNullException("position", "Position can not be null"); + throw new ArgumentNullException("position", "Position can not be null"); } return tiles.Find(tile => tile.Position.CompareTo(position) == 0); @@ -158,25 +158,25 @@ public List GetNeighbours(ITile tile) { if (tile == null) { - throw new ArgumentNullException("tile", "Tile can not be null"); + throw new ArgumentNullException("tile", "Tile can not be null"); } if (tiles.Contains(tile) == false) { - throw new ArgumentException("Tile not in Area", "tile"); + throw new ArgumentException("Tile not in Area", "tile"); } List neigbourTiles = tiles.FindAll(t => - Math.Abs(((Position2D)t.Position).X - ((Position2D)tile.Position).X) == 1 || - Math.Abs(((Position2D)t.Position).Y - ((Position2D)tile.Position).Y) == 1); + Math.Abs(((Position2D)t.Position).X - ((Position2D)tile.Position).X) == 1 || + Math.Abs(((Position2D)t.Position).Y - ((Position2D)tile.Position).Y) == 1); if (neigbourTiles.Count <= 0) { - return null; + return null; } else { - return neigbourTiles; + return neigbourTiles; } } From e1a7f63e15b2b4ede5c6af421b4db64d01f68733 Mon Sep 17 00:00:00 2001 From: scrubzz Date: Mon, 4 Jun 2018 22:00:33 +0200 Subject: [PATCH 7/7] Previous test for PositionGetNeighbours was not relevant. Changed to a more relevant test. --- Tests/TwoDimension/AreaTests.cs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/Tests/TwoDimension/AreaTests.cs b/Tests/TwoDimension/AreaTests.cs index 4da4b9c..fec1832 100644 --- a/Tests/TwoDimension/AreaTests.cs +++ b/Tests/TwoDimension/AreaTests.cs @@ -171,13 +171,10 @@ public void PositionSet() public void PositionGet() { Area area = new Area(); - var mockLevel = new Mock(); - var mockPosition = new Mock(); var mockTile = new Mock(); var tilePosition = new Position2D(0, 0); var tilePositionNotFound = new Position2D(1, 0); - area.SetPosition(mockLevel.Object, mockPosition.Object); mockTile.Object.SetPosition(area, tilePosition); area.Add(mockTile.Object); @@ -195,8 +192,6 @@ public void PositionGet() public void PositionGetNeighbours() { Area area = new Area(); - var mockLevel = new Mock(); - var mockPosition = new Mock(); var mockTile = new Mock(); var tilePosition = new Position2D(0, 0); var mockTileNotInArea = new Mock(); @@ -207,7 +202,6 @@ public void PositionGetNeighbours() var mockNotANeighbourTile = new Mock(); var notANeighbourTilePosition = new Position2D(4, 0); - area.SetPosition(mockLevel.Object, mockPosition.Object); mockTile.Object.SetPosition(area, tilePosition); area.Add(mockTile.Object); @@ -223,15 +217,16 @@ public void PositionGetNeighbours() // Test One Or More Neighbours mockFirstNeighbourTile.Object.SetPosition(area, firstNeighbourTilePosition); area.Add(mockFirstNeighbourTile.Object); - Assert.IsTrue(area.GetNeighbours(mockTile.Object).Count == 1); - mockSecondNeighbourTile.Object.SetPosition(area, secondNeighbourTilePosition); area.Add(mockSecondNeighbourTile.Object); - Assert.IsTrue(area.GetNeighbours(mockTile.Object).Count == 2); - mockNotANeighbourTile.Object.SetPosition(area, notANeighbourTilePosition); area.Add(mockNotANeighbourTile.Object); - Assert.IsTrue(area.GetNeighbours(mockTile.Object).Count == 2); + + var neighbourTiles = area.GetNeighbours(mockTile.Object); + + Assert.IsTrue(neighbourTiles.Contains(mockFirstNeighbourTile.Object)); + Assert.IsTrue(neighbourTiles.Contains(mockSecondNeighbourTile.Object)); + Assert.IsFalse(neighbourTiles.Contains(mockNotANeighbourTile.Object)); } } }