Ejemplo n.º 1
0
        public void Branch_moves_to_collision_free_location_instead_of_rotated_location_when_there_is_a_collision()
        {
            // Given
            CreateMockFactory();
            var collisionFreeLocation = new System.Windows.Point(999, 999);

            _mockCollisionDetector.Setup(m => m.GetNearestFreeLocation(It.IsAny <IslandShape>(),
                                                                       It.IsAny <IslandShape>())).Returns(collisionFreeLocation); // forcing a collision

            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var branch = new Branch("mr branch", unusedColour);

            branch.Distance = 50;
            islands.Add(branch);

            // When
            islands.MoveAll();

            // Then
            var branchCentre = branch.Shape.CentrePoint;

            Assert.AreEqual(collisionFreeLocation.X, branchCentre.X);
            Assert.AreEqual(collisionFreeLocation.Y, branchCentre.Y);
        }
Ejemplo n.º 2
0
        public void Moving_with_one_island_added_moves_the_island()
        {
            // Given
            var unused             = 0.0;
            var width              = 100;
            var height             = 200;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var newBranchName = "bob";
            var newBranch     = new Branch(newBranchName, unusedColour);

            islands.Add(newBranch);

            // the island has never been moved
            Assert.AreEqual(0.0, newBranch.Shape.CentrePoint.X);
            Assert.AreEqual(0.0, newBranch.Shape.CentrePoint.Y);

            // When
            islands.MoveAll();

            // Then
            Assert.AreNotEqual(0.0, newBranch.Shape.CentrePoint.X);
            Assert.AreNotEqual(0.0, newBranch.Shape.CentrePoint.Y);
        }
Ejemplo n.º 3
0
        public void Moving_multiple_islands_with_distances_set_does_not_set_their_positions_to_be_the_same()
        {
            // Given
            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var newBranchOne   = new Branch("bob", unusedColour);
            var newBranchTwo   = new Branch("ben", unusedColour);
            var newBranchThree = new Branch("bill", unusedColour);

            newBranchOne.Distance   = 10;
            newBranchTwo.Distance   = 20;
            newBranchThree.Distance = 30;

            islands.Add(newBranchOne);
            islands.Add(newBranchTwo);
            islands.Add(newBranchThree);

            // When
            islands.MoveAll();

            // Then
            List <Branch> islandArray = new List <Branch>(new Branch[]
            {
                newBranchOne,
                newBranchTwo,
                newBranchThree
            }
                                                          );

            foreach (var island in islandArray)
            {
                var otherIslands = islandArray.Where(b => b != island);

                foreach (var comparingIsland in otherIslands)
                {
                    Assert.AreNotEqual(comparingIsland.Shape.CentrePoint.X, island.Shape.CentrePoint.X);
                    Assert.AreNotEqual(comparingIsland.Shape.CentrePoint.Y, island.Shape.CentrePoint.Y);
                }
            }
        }
Ejemplo n.º 4
0
        public void Moving_with_multiple_islands_added_moves_the_islands()
        {
            // Given
            var unused             = 0.0;
            var width              = 100;
            var height             = 200;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var newBranchNameOne = "bob";
            var newBranchOne     = new Branch(newBranchNameOne, unusedColour);

            islands.Add(newBranchOne);
            var newBranchNameTwo = "ben";
            var newBranchTwo     = new Branch(newBranchNameTwo, unusedColour);

            islands.Add(newBranchTwo);
            var newBranchNameThree = "bill";
            var newBranchThree     = new Branch(newBranchNameThree, unusedColour);

            islands.Add(newBranchThree);

            Assert.AreEqual(0.0, newBranchOne.Shape.CentrePoint.X);
            Assert.AreEqual(0.0, newBranchOne.Shape.CentrePoint.Y);

            Assert.AreEqual(0.0, newBranchTwo.Shape.CentrePoint.X);
            Assert.AreEqual(0.0, newBranchTwo.Shape.CentrePoint.Y);

            Assert.AreEqual(0.0, newBranchThree.Shape.CentrePoint.X);
            Assert.AreEqual(0.0, newBranchThree.Shape.CentrePoint.Y);

            // When
            islands.MoveAll();

            // Then
            Assert.AreNotEqual(0.0, newBranchOne.Shape.CentrePoint.X);
            Assert.AreNotEqual(0.0, newBranchOne.Shape.CentrePoint.Y);

            Assert.AreNotEqual(0.0, newBranchTwo.Shape.CentrePoint.X);
            Assert.AreNotEqual(0.0, newBranchTwo.Shape.CentrePoint.Y);

            Assert.AreNotEqual(0.0, newBranchThree.Shape.CentrePoint.X);
            Assert.AreNotEqual(0.0, newBranchThree.Shape.CentrePoint.Y);
        }
Ejemplo n.º 5
0
        public void Branch_moves_to_rotated_location_when_there_is_no_collision()
        {
            // Given
            CreateMockFactory();

            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var branch = new Branch("mr branch", unusedColour);

            branch.Distance = 50;
            islands.Add(branch);

            _mockCollisionDetector.Setup(m => m.GetNearestFreeLocation(It.IsAny <IslandShape>(),
                                                                       It.IsAny <IslandShape>())).Returns(
                (IslandShape possibleCollidingIslandShapeParameterPassedIn,
                 IslandShape releaseArchipelagoIslandShapeParameterPassedIn) =>
                possibleCollidingIslandShapeParameterPassedIn.CentrePoint);           // there is no collision, always returns given location

            // When
            islands.MoveAll();

            // Then
            var expectedRotatedLocation = new System.Windows.Point(
                (branch.Distance * viewControlData.PixelsPerArchipelagoUnitDistance) + viewControlData.CentrePoint.X,
                viewControlData.CentrePoint.Y);
            var branchCentre = branch.Shape.CentrePoint;

            Assert.AreEqual(expectedRotatedLocation.X, branchCentre.X);
            Assert.AreEqual(expectedRotatedLocation.Y, branchCentre.Y);
        }
Ejemplo n.º 6
0
        public void Moving_four_islands_with_distances_set_moves_each_island_to_a_corner()
        {
            // Given
            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var rightBranch  = new Branch("right", unusedColour);
            var bottomBranch = new Branch("bottom", unusedColour);
            var leftBranch   = new Branch("left", unusedColour);
            var topBranch    = new Branch("top", unusedColour);

            rightBranch.Distance  = 50;
            bottomBranch.Distance = 50;
            leftBranch.Distance   = 50;
            topBranch.Distance    = 50;

            // Locations are determinted by the order in which they're added, as we use the index of the
            //      underlying list.

            /*
             *  -------------------
             |        4        |
             |                 |
             |                 |
             | 3      C      1 |
             |                 |
             |                 |
             |        2        |
             |  -------------------
             */
            islands.Add(rightBranch);   // 1
            islands.Add(bottomBranch);  // 2
            islands.Add(leftBranch);    // 3
            islands.Add(topBranch);     // 4

            // When
            islands.MoveAll();

            // Then
            var centre            = viewControlData.CentrePoint;
            var rightBranchCentre = rightBranch.Shape.CentrePoint;

            rightBranchCentre.X = Math.Round(rightBranchCentre.X, 0, MidpointRounding.AwayFromZero);   // There may be some very small inaccuracy
            rightBranchCentre.Y = Math.Round(rightBranchCentre.Y, 0, MidpointRounding.AwayFromZero);   //   when we do the rotation.
            var isOnPositiveXRelativeToCentre = (rightBranchCentre.X > centre.X);
            var isOnEqualYToCentre            = (rightBranchCentre.Y == centre.Y);
            var rightBranchIsOnTheRight       = (isOnPositiveXRelativeToCentre && isOnEqualYToCentre);

            Assert.IsTrue(rightBranchIsOnTheRight, "rightBranchIsOnTheRight");

            var bottomBranchCentre = bottomBranch.Shape.CentrePoint;

            bottomBranchCentre.X = Math.Round(bottomBranchCentre.X, 0, MidpointRounding.AwayFromZero);
            bottomBranchCentre.Y = Math.Round(bottomBranchCentre.Y, 0, MidpointRounding.AwayFromZero);
            var isOnEqualXToCentre            = (bottomBranchCentre.X == centre.X);
            var isOnPositiveYRelativeToCentre = (bottomBranchCentre.Y > centre.Y);
            var bottomBranchIsOnTheBottom     = (isOnEqualXToCentre && isOnPositiveYRelativeToCentre);

            Assert.IsTrue(bottomBranchIsOnTheBottom, "bottomBranchIsOnTheBottom");

            var leftBranchCentre = leftBranch.Shape.CentrePoint;

            leftBranchCentre.X            = Math.Round(leftBranchCentre.X, 0, MidpointRounding.AwayFromZero);
            leftBranchCentre.Y            = Math.Round(leftBranchCentre.Y, 0, MidpointRounding.AwayFromZero);
            isOnPositiveXRelativeToCentre = (leftBranchCentre.X > centre.X);
            isOnEqualYToCentre            = (leftBranchCentre.Y == centre.Y);
            var leftBranchIsOnTheLeft = (!isOnPositiveXRelativeToCentre && isOnEqualYToCentre);

            Assert.IsTrue(leftBranchIsOnTheLeft, "leftBranchIsOnTheLeft");

            var topBranchCentre = topBranch.Shape.CentrePoint;

            topBranchCentre.X  = Math.Round(topBranchCentre.X, 0, MidpointRounding.AwayFromZero);
            topBranchCentre.Y  = Math.Round(topBranchCentre.Y, 0, MidpointRounding.AwayFromZero);
            isOnEqualXToCentre = (topBranchCentre.X == centre.X);
            var isOnNegativeYRelativeToCentre = (topBranchCentre.Y < centre.Y);
            var topBranchIsOnTheTop           = (isOnNegativeYRelativeToCentre && isOnEqualXToCentre);

            Assert.IsTrue(topBranchIsOnTheTop, "topBranchIsOnTheTop");
        }