public void TestBoundingCirclePushBackLeft()
        {
            //Preconfig
            int radius = 20;
            Vector position = new Vector(100f, 100f);
            Vector ballPos = new Vector(90, 120);
            Vector hitPoint = new Vector(100, 120);

            Vector ballSpeed = hitPoint - ballPos;

            Vector expectedPushBack = (radius * 2 / 1.9f) * ((hitPoint - (position + new Vector(radius, radius)))).AsNormalized();

            Vector pushBackVec;

            //Creation
            Bumper parent = new Bumper();
            BoundingCircle bC2 = new BoundingCircle(radius, position);
            BoundingContainer bCont = new BoundingContainer(parent);
            bCont.AddBoundingBox(bC2);

            //Operation
            parent.Location = (new Vector(0, 0));
            pushBackVec = bC2.GetOutOfAreaPush(radius * 2, hitPoint, ballSpeed, ballPos);

            //Assertion
            Assert.AreEqual(expectedPushBack, pushBackVec);
        }
        public void addReferenceTwiceTest()
        {
            //Preconfig
            int radius1 = 20;
            Vector center1 = new Vector(0f, 0f);

            //Creation
            Bumper parent = new Bumper();
            BoundingContainer bCont = new BoundingContainer(parent);
            BoundingCircle bC1 = new BoundingCircle(radius1, center1);
            bCont.AddBoundingBox(bC1);

            BoundingField bf = new BoundingField(0, 0);

            //Operation
            bf.addReference(bC1);
            bf.addReference(bC1);

            int hit = 0;
            //Assertion
            foreach (IBoundingBox b in bf.getReferences())
            {
                if (b.Equals(bC1))
                {
                    hit++;
                }
            }

            if (hit == 1)
            {
                Assert.AreEqual(1, hit);
            }
        }
        public void TestReflection135Direction()
        {
            //Preconfig
            Vector position = new Vector(100f, 100f);
            Vector ballPos = new Vector(140f, 120f);
            int radius = 20;

            Vector ballSpeed = new Vector(-100, -100);

            Vector hitPoint = new Vector(120 + 14.1421f, 120 + 14.1421f);
            Vector expectedReflection = -ballSpeed;
            expectedReflection.Normalize();
            Vector reflection;

            //Creation
            Bumper parent = new Bumper();
            BoundingCircle bC2 = new BoundingCircle(radius, position);
            BoundingContainer bCont = new BoundingContainer(parent);
            bCont.AddBoundingBox(bC2);

            //Operation
            parent.Location = (new Vector(0, 0));

            reflection = bC2.Reflect(ballSpeed, hitPoint, ballPos);
            reflection.Normalize();

            //Assertion
            Assert.AreEqual(expectedReflection.X, reflection.X, 0.001f);
            Assert.AreEqual(expectedReflection.Y, reflection.Y, 0.001f);
        }
        public void TestIntersectIntersectBallSpeedZero()
        {
            //Preconfig
            int radius1 = 20;
            Vector center1 = new Vector(0f, 0f);
            int radius2 = 20;
            Vector center2 = new Vector(-19, 0f);
            Vector ballSpeed = new Vector(0, 0);

            Vector hitPoint;
            bool isIntersec = false;

            //Creation
            Bumper parent = new Bumper();
            Ball ball = new Ball();
            BoundingContainer bCont = new BoundingContainer(parent);
            BoundingContainer bCont2 = new BoundingContainer(ball);
            BoundingCircle bC1 = new BoundingCircle(radius1, center1);
            BoundingCircle bC2 = new BoundingCircle(radius2, center2);
            bCont.AddBoundingBox(bC1);
            bCont2.AddBoundingBox(bC2);
            ball.Velocity = ballSpeed;
            parent.Location = (new Vector(0, 0));
            parent.Width = 2 * radius1;
            parent.Height = 2 * radius1;

            //Operation
            isIntersec = bC1.Intersect(bC2, out hitPoint, ballSpeed);

            //Assertion
            Assert.IsTrue(isIntersec);
        }
        public void TakeOverBoundingContainerWithCircleBigCenter()
        {
            //preconfig
            int cols = 10;
            int rows = 10;
            int width = 100;
            int height = 100;

            int expectedFieldHeight = height / rows;
            int expectedFieldWidth = width / cols;

            int radius1 = 50;
            Vector position1 = new Vector(0, 0);

            //creation
            BoundingRaster br = new BoundingRaster(cols, rows, width, height);

            Bumper parent1 = new Bumper();
            BoundingCircle bC1 = new BoundingCircle(radius1, position1);
            BoundingContainer bCont1 = new BoundingContainer(parent1);
            bCont1.AddBoundingBox(bC1);
            parent1.Location = (new Vector(0, 0));

            //operation
            br.TakeOverBoundingContainer(bCont1);

            //assertion
            for (int x = 0; x < cols; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    if (x <= 9 && x >= 0 && y <= 9 && y >= 0)
                    {
                        bool found = false;
                        foreach (IBoundingBox b in br.GetBoundingField(x, y).getReferences())
                        {
                            Assert.AreEqual(bC1, b);
                            found = true;
                        }
                        if (!found)
                        {
                            Assert.Fail();
                        }
                    }
                    else
                    {
                        foreach (IBoundingBox b in br.GetBoundingField(x, y).getReferences())
                        {
                            if (bC1.Equals(b))
                            {
                                Assert.Fail();
                            }
                        }
                    }
                }
            }
        }
        public void ShouldCloneAllProperties()
        {
            // Arrange
            PinballElement element = new Bumper();
            float bounceFactor = 2;
            float scale        = 2;
            float rotation     = 90;

            // Act
            element.BounceFactor = bounceFactor;
            element.Scale = scale;
            element.BaseRotation = rotation;

            PinballElement clone = (PinballElement)element.Clone();

            // Assert
            Assert.AreEqual(bounceFactor, element.BounceFactor, 0.001);
            Assert.AreEqual(scale, element.Scale, 0.001);
            Assert.AreEqual(rotation, element.BaseRotation, 0.001);
        }
        public void TestIntersectNoIntersectTouch()
        {
            //Preconfig
            int radius1 = 20;
            Vector center1 = new Vector(0f, 0f);
            int radius2 = 20;
            Vector center2 = new Vector(40f, 0f);
            Vector ballSpeed = new Vector(-5, 0);

            Vector hitPoint;
            bool isIntersec = false;

            //Creation
            Bumper parent = new Bumper();
            Ball ball = new Ball();
            BoundingContainer bCont = new BoundingContainer(parent);
            BoundingContainer bCont2 = new BoundingContainer(ball);
            BoundingCircle bC1 = new BoundingCircle(radius1, center1);
            BoundingCircle bC2 = new BoundingCircle(radius2, center2);
            bCont.AddBoundingBox(bC1);
            bCont2.AddBoundingBox(bC2);
            ball.Velocity = ballSpeed;

            //Operation
            isIntersec = bC1.Intersect(bC2, out hitPoint);

            //Assertion
            Assert.IsFalse(isIntersec);
        }
        public void ShouldDeepCloneReferences()
        {
            var machine = new PinballMachine();
            var element = new Bumper();
            var entry = new HighscoreEntry("Simon", 1, DateTime.Now);

            machine.Add(element);
            machine.Highscores.Add(entry);
            var copy = machine.Clone() as PinballMachine;

            Assert.AreNotSame(copy, machine);
            Assert.AreNotSame(copy.Balls, machine.Balls);
            Assert.AreNotSame(copy.Highscores, machine.Highscores);
            Assert.AreNotSame(copy.Highscores.First(), machine.Highscores.First());
            Assert.AreNotSame(copy.Layout, machine.Layout);
        }