public void PositionNodesWithinNet_RowIndexCorrectlySetup_NodesReceiveCorrectPositions()
        {
            // arrange
            var net = HexagonNetTestHelper.GenerateTestNet3Rows(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);

            var expectedIndices = $" (0, 0) (0, 1) (0, 2) (0, 3) (0, 4) (0, 5){Environment.NewLine}" +
                                  $" (1, 0) (1, 1) (1, 2) (1, 3) (1, 4) (1, 5){Environment.NewLine}" +
                                  $" (2, 0) (2, 1) (2, 2) (2, 3) (2, 4) (2, 5){Environment.NewLine}";

            // act
            string actualIndices = "";
            int    nodeCounter   = 0;

            foreach (var node in net)
            {
                actualIndices += " ";
                actualIndices += node.Position;

                nodeCounter++;
                if (nodeCounter == 6)
                {
                    actualIndices += Environment.NewLine;
                    nodeCounter    = 0;
                }
            }

            // assert
            Assert.AreEqual(expectedIndices, actualIndices, $"Actual indices: {Environment.NewLine}{actualIndices}");
        }
Beispiel #2
0
        public void GameBoard_MergeBubbles_OneSimilarBubbleToTheRightValid()
        {
            // arrange
            var net = HexagonNetTestHelper.GenerateTestNet3Rows(3, 3, 3, 3, 3, 3,
                                                                3, 3, 1, 1, 3, 3,
                                                                3, 3, 3, 3, 3, 3);
            var gameBoard = new GameBoard(net);

            var startBubble = net.BottomRow.Nodes[2].GetNeighbour(Neighbours.UpperRight);

            // Make sure startBubble was chosen correctly
            Debug.Assert(3 == startBubble.GetNeighbour(Neighbours.Left).Value.Exponent);
            Debug.Assert(1 == startBubble.GetNeighbour(Neighbours.Right).Value.Exponent);

            var expectedNetToString =
                $" 3 3 3 3 3 3{Environment.NewLine}" +
                $" 3 3 2 null 3 3{Environment.NewLine}" +
                $" 3 3 3 3 3 3{Environment.NewLine}";

            // act
            gameBoard.MergeBubbles(startBubble);

            // assert

            Assert.AreEqual(expectedNetToString, net.ToString(), $"Actual HexagonNet as string: {Environment.NewLine}{net.ToString()}");
        }
        public void HexagonNet_ChangingNeighbours_ChangesNeighbourNodesInNet()
        {
            // arrange
            HexagonNet <Bubble> net = new HexagonNet <Bubble>();

            var bubblesForTopRow = new BubbleNode[]
            {
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(2).SetHexagonNet(net),
                new BubbleNode(3).SetHexagonNet(net),
                new BubbleNode(4).SetHexagonNet(net),
                new BubbleNode(5).SetHexagonNet(net)
            };
            var topRow = new HexagonNetRow <Bubble>(bubblesForTopRow);

            var bubblesForMiddleRow = new BubbleNode[]
            {
                new BubbleNode(6).SetHexagonNet(net),
                new BubbleNode(7).SetHexagonNet(net),
                new BubbleNode(8).SetHexagonNet(net),
                new BubbleNode(9).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(11).SetHexagonNet(net)
            };
            var middleRow = new HexagonNetRow <Bubble>(bubblesForMiddleRow);

            var bubblesForBottomRow = new BubbleNode[]
            {
                new BubbleNode(12).SetHexagonNet(net),
                new BubbleNode(13).SetHexagonNet(net),
                new BubbleNode(14).SetHexagonNet(net),
                new BubbleNode(15).SetHexagonNet(net),
                new BubbleNode(16).SetHexagonNet(net),
                new BubbleNode(17).SetHexagonNet(net)
            };
            var bottomRow = new HexagonNetRow <Bubble>(bubblesForBottomRow);

            net.AddTopRow(topRow);
            net.AddBottomRow(middleRow);
            net.AddBottomRow(bottomRow);

            var secondNodeMiddleRow = middleRow.Nodes[1];

            var expectedNet         = HexagonNetTestHelper.GenerateTestNet3Rows(0, 1, -1000, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
            var expectedNetToString = expectedNet.ToString();

            // act
            secondNodeMiddleRow.GetNeighbour(Neighbours.UpperRight).Value.Exponent = -1000;

            // assert
            Assert.AreEqual(expectedNetToString, net.ToString(), $"Actual HexagonNet as string: {Environment.NewLine}{net.ToString()}");
        }
        public void HexagonNet_RemoveTopRow_RemovesTheRowFromNet()
        {
            // arrange
            HexagonNet <Bubble> net = HexagonNetTestHelper.GenerateTestNet3Rows(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);

            var expectedNetToString = $" 6 7 8 9 10 11{Environment.NewLine}" +
                                      $" 12 13 14 15 16 17{Environment.NewLine}";

            // act
            net.RemoveTopRow();

            // assert
            Assert.AreEqual(expectedNetToString, net.ToString(), $"Actual HexagonNet as string: {Environment.NewLine}{net.ToString()}");
        }
Beispiel #5
0
        public void GameBoard_MergeBubbles_OneSimilarBubbleAtTheBottomValid()
        {
            // arrange
            var net = HexagonNetTestHelper.GenerateTestNet3Rows(3, 3, 3, 3, 3, 3,
                                                                3, 3, 1, 3, 3, 3,
                                                                3, 3, 3, 1, 3, 3);
            var gameBoard = new GameBoard(net);

            var startBubble = net.BottomRow.Nodes[2].GetNeighbour(Neighbours.UpperRight);

            var expectedNetToString =
                $" 3 3 3 3 3 3{Environment.NewLine}" +
                $" 3 3 2 3 3 3{Environment.NewLine}" +
                $" 3 3 3 null 3 3{Environment.NewLine}";

            // act
            gameBoard.MergeBubbles(startBubble);

            // assert

            Assert.AreEqual(expectedNetToString, net.ToString(), $"Actual HexagonNet as string: {Environment.NewLine}{net.ToString()}");
        }
        public void HexagonNet_RemoveBottomRow_ReassignsNeighbours()
        {
            // arrange
            HexagonNet <Bubble> net = HexagonNetTestHelper.GenerateTestNet3Rows(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);

            // act
            net.RemoveBottomRow();
            var bottomRowNodes = net.BottomRow.Nodes;

            // assert
            Assert.AreEqual(null, bottomRowNodes[0].GetNeighbour(Neighbours.LowerLeft));
            Assert.AreEqual(null, bottomRowNodes[0].GetNeighbour(Neighbours.LowerRight));
            Assert.AreEqual(null, bottomRowNodes[1].GetNeighbour(Neighbours.LowerLeft));
            Assert.AreEqual(null, bottomRowNodes[1].GetNeighbour(Neighbours.LowerRight));
            Assert.AreEqual(null, bottomRowNodes[2].GetNeighbour(Neighbours.LowerLeft));
            Assert.AreEqual(null, bottomRowNodes[2].GetNeighbour(Neighbours.LowerRight));
            Assert.AreEqual(null, bottomRowNodes[3].GetNeighbour(Neighbours.LowerLeft));
            Assert.AreEqual(null, bottomRowNodes[3].GetNeighbour(Neighbours.LowerRight));
            Assert.AreEqual(null, bottomRowNodes[4].GetNeighbour(Neighbours.LowerLeft));
            Assert.AreEqual(null, bottomRowNodes[4].GetNeighbour(Neighbours.LowerRight));
            Assert.AreEqual(null, bottomRowNodes[5].GetNeighbour(Neighbours.LowerLeft));
            Assert.AreEqual(null, bottomRowNodes[5].GetNeighbour(Neighbours.LowerRight));
        }