public void TestIfTileConstructorReturnsValidStateOfPosition()
 {
     var tile = new Tile("2", 2, TileType.Number);
     var actual = tile.Position;
     var expected = 2;
     Assert.AreEqual(actual, expected);
 }
 public void TestIfTileConstructorReturnsValidStateOfLabel()
 {
     var tile = new Tile("1", 1, TileType.Number);
     var actual = tile.Label;
     var expected = "1";
     Assert.AreEqual(actual, expected);
 }
 public void TestIfCompareToMethodReturnsNegativeValueWhenFirstTileIsBeforeSecond()
 {
     var firstTile = new Tile("1", 1, TileType.Number);
     var secondTile = this.CloneTile(firstTile, "2", 2);
     var actual = firstTile.CompareTo(secondTile);
     var expected = -1;
     Assert.AreEqual(actual, expected);
 }
        public void TestTileGetTextRepresentationOfEmptyTile()
        {
            var tile = new Tile(string.Empty, 0, TileType.Empty);

            var actual = tile.GetTextRepresentation();
            var expected = " ";
            Assert.AreEqual(actual, expected);
        }
 public void TestIfCompareToMethodReturnZeroWhenTilesHaveTheSameValues()
 {
     var firstTile = new Tile("3", 3, TileType.Number);
     var secondTile = this.CloneTile(firstTile, "3", 3);
     var actual = firstTile.CompareTo(secondTile);
     var expected = 0;
     Assert.AreEqual(actual, expected);
 }
 public void TestIfCompareToMethodReturnsPositiveValueWhenSecondTileIsBeforeFirst()
 {
     var firstTile = new Tile("5", 5, TileType.Number);
     var secondTile = this.CloneTile(firstTile, "3", 3);
     var actual = firstTile.CompareTo(secondTile);
     var expected = 1;
     Assert.AreEqual(actual, expected);
 }
        public void TestAddTileMethodToRetturnAccurateValue()
        {
            var grid = new Grid();
            for (int i = 0; i < 5; i++)
            {
                var tile = new Tile(string.Empty + i + string.Empty, i, TileType.Number);
                grid.AddTile(tile);
            }

            var actual = grid.TilesCount;
            var expected = 5;
            Assert.AreEqual(actual, expected);
        }
        /// <summary>
        /// Fills grid with tiles.
        /// </summary>
        /// <param name="grid">The empty grid.</param>
        public void InitilizeGrid(IGrid grid)
        {
            var emptyTile = new Tile(string.Empty, GlobalConstants.TotalTilesCount - 1, TileType.Empty);

            for (int i = 0; i < GlobalConstants.TotalTilesCount - 1; i++)
            {
                Tile tile = emptyTile.CloneMemberwise();
                tile.Label = (i + 1).ToString();
                tile.Position = i;
                tile.Type = TileType.Number;
                grid.AddTile(tile);
            }

            grid.AddTile(emptyTile);
        }
        public void TestCanSwapMethodToReturnFalseValueWhenCurrentTileCannotBeSwapped()
        {
            var grid = new Grid();
            for (int i = 0; i < 5; i++)
            {
                var tile = new Tile(string.Empty + i + string.Empty, i, TileType.Number);
                grid.AddTile(tile);
            }

            var emptyTile = new Tile(string.Empty, GlobalConstants.TotalTilesCount - 1, TileType.Empty);
            grid.AddTile(emptyTile);
            var tileToTest = grid.GetTileFromLabel("1");
            var actual = grid.CanSwap(tileToTest);
            var expected = false;
            Assert.AreEqual(expected, actual);
        }
        public void TestCanSwapMethodToReturnFalseValueWhenCurrentTileCanBeSwapped()
        {
            var grid = new Grid();
            for (int i = 0; i < 5; i++)
            {
                var tile = new Tile(i.ToString(), i, TileType.Number);
                grid.AddTile(tile);
            }

            var emptyTile = new Tile(string.Empty, 5, TileType.Empty);
            grid.AddTile(emptyTile);
            var tileToTest = grid.GetTileFromLabel("4");
            var actual = grid.CanSwap(tileToTest);
            var expected = true;
            Assert.AreEqual(expected, actual);
        }
        public void TestCheckIfSortedWhenGridIsNotSorted()
        {
            var grid = new Grid();
            var emptyTile = new Tile(string.Empty, 0, TileType.Empty);
            grid.AddTile(emptyTile);

            for (int i = GlobalConstants.TotalTilesCount - 1; i > 0; i--)
            {
                Tile tile = emptyTile.CloneMemberwise();
                tile.Label = (i + 1).ToString();
                tile.Position = i;
                tile.Type = TileType.Number;
                grid.AddTile(tile);
            }

            bool actual = grid.IsSorted;
            var expected = false;
            Assert.AreEqual(expected, actual);
        }
 public void TestWheatherTilesAreAddedCorrectly()
 {
     var fakeGrid = new Mock<IGrid>();
     var tile = new Tile("1", 1, TileType.Number);
     fakeGrid.Setup(g => g.AddTile(tile));
     fakeGrid.Object.AddTile(tile);
     fakeGrid.Verify(g => g.AddTile(tile), Times.AtLeastOnce());
     fakeGrid.Setup(g => g.TilesCount).Returns(1);
     Assert.AreEqual(1, fakeGrid.Object.TilesCount);
 }
 public void TestGetTileAtPositionMethodToReturnValidPositionOfTile()
 {
     var grid = new Grid();
     var tile = new Tile("3", 3, TileType.Number);
     var anotherTile = new Tile("4", 4, TileType.Number);
     grid.AddTile(tile);
     grid.AddTile(anotherTile);
     var actual = grid.GetTileAtPosition(1);
     var expected = anotherTile;
     Assert.AreEqual(expected, actual);
 }
        public void TestSwapTiles()
        {
            var grid = new Grid();

            var emptyTile = new Tile(string.Empty, 0, TileType.Empty);
            grid.AddTile(emptyTile);

            Tile tile = emptyTile.CloneMemberwise();
            tile.Label = "1";
            tile.Position = 1;
            tile.Type = TileType.Number;
            grid.AddTile(tile);

            grid.SwapTiles(tile);

            var actual = tile.Position;
            var expected = 0;

            Assert.AreEqual(expected, actual);
        }
 public void TestWheatherTileAtPositionMethodReturnsCorrectValues()
 {
     var fakeGrid = new Mock<IGrid>();
     var tile = new Tile("1", 1, TileType.Number);
     fakeGrid.Setup(g => g.GetTileAtPosition(1)).Returns(new Tile("1", 1, TileType.Number));
     var exp = fakeGrid.Object.GetTileAtPosition(1);
     Assert.AreEqual(tile.Position, exp.Position);
 }
        public void TestMementoToReturnValidObjectState()
        {
            var grid = new Grid();
            var tile = new Tile("1", 1, TileType.Number);
            var emptyTile = new Tile(string.Empty, GlobalConstants.TotalTilesCount - 1, TileType.Empty);
            var anotherTile = new Tile("2", 2, TileType.Number);
            grid.AddTile(tile);
            grid.AddTile(emptyTile);
            Memento memento = grid.SaveMemento();

            grid.AddTile(anotherTile);
            grid.RestoreMemento(memento);

            var actual = grid.TilesCount;
            var expected = 2;
            Assert.AreEqual(expected, actual);
        }
        public void TestTileGetTextRepresentationOfNumberedTile()
        {
            var tile = new Tile("1", 0, TileType.Empty);

            var actual = tile.GetTextRepresentation();
            var expected = "1";
            Assert.AreEqual(actual, expected);
        }
 public void TestGetTileFromLabelMethodToReturnValidTile()
 {
     var grid = new Grid();
     var tile = new Tile("1", 1, TileType.Number);
     var anotherTile = new Tile("2", 2, TileType.Number);
     grid.AddTile(tile);
     grid.AddTile(anotherTile);
     var actual = grid.GetTileFromLabel("2");
     var expected = anotherTile;
     Assert.AreEqual(expected, actual);
 }
 public void TestClearMethodToRetturnZeroValue()
 {
     var grid = new Grid();
     var tile = new Tile("1", 1, TileType.Number);
     grid.AddTile(tile);
     grid.Clear();
     var actual = grid.TilesCount;
     var expected = 0;
     Assert.AreEqual(actual, expected);
 }
        public void TestGetEnumerator()
        {
            var grid = new Grid();

            var emptyTile = new Tile(string.Empty, 0, TileType.Empty);
            grid.AddTile(emptyTile);

            Tile tile = emptyTile.CloneMemberwise();
            tile.Label = "1";
            tile.Position = 1;
            tile.Type = TileType.Number;
            grid.AddTile(tile);

            foreach (Tile item in grid)
            {
                item.Label = "test";
            }

            var actual = emptyTile.Label;
            var expected = "test";

            Assert.AreEqual(expected, actual);
        }
 public void TestGetTileAtPositionMethodToThrowWhenNoValidPositionIsProvided()
 {
     var grid = new Grid();
     var tile = new Tile("3", 3, TileType.Number);
     var anotherTile = new Tile("4", 4, TileType.Number);
     grid.AddTile(tile);
     grid.AddTile(anotherTile);
     var actual = grid.GetTileAtPosition(2);
     var expected = anotherTile;
     Assert.AreEqual(expected, actual);
 }
 public void TestGetTileFromLabelMethodToReturnNullWhenNoValidDataIsProvided()
 {
     var grid = new Grid();
     var tile = new Tile("1", 1, TileType.Number);
     var anotherTile = new Tile("2", 2, TileType.Number);
     grid.AddTile(tile);
     grid.AddTile(anotherTile);
     var actual = grid.GetTileFromLabel("3");
     Assert.AreEqual(null, actual);
 }
        private bool IsValidMove(Tile tile)
        {
            if (!this.IsValidTileLabel(int.Parse(tile.Label)))
            {
                return false;
            }

            return this.grid.CanSwap(tile);
        }
        /// <summary>
        /// Helper method for tile comparison when two tiles are identical.
        /// </summary>
        /// <param name="tile">Tile to be cloned.</param>
        /// <param name="newLabel">String Value of the Label property for the new Tile.</param>
        /// <param name="newPosition">String Value of the Position property for the new Tile.</param>
        /// <param name="newType">Enumeration TileType specifies the type of the new cloned Tile.Default is TileType.Number.</param>
        /// <returns>New Tile with the specified input values.</returns>
        private Tile CloneTile(Tile tile, string newLabel, int newPosition, TileType newType = TileType.Number)
        {
            var newTile = tile.CloneMemberwise();
            newTile.Label = newLabel;
            newTile.Position = newPosition;
            newTile.Type = newType;

            return newTile;
        }