Exemplo n.º 1
0
        public void IsCoordinatesInRange_X_and_Y_In_Range()
        {
            int  x        = 100;
            int  y        = 50;
            bool expected = true;
            bool actual   = _testAsset.IsCoordinatesInRange(x, y);

            Assert.AreEqual(actual, expected);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculate Ball Future Coordinates in actual time system can responce
        /// </summary>
        /// <param name="currentCoordinates"><Current ball coordinates/param>
        /// <param name="actionTime">Actual system responce time</param>
        /// <returns>Ball Future coordinates</returns>
        public BallCoordinates FindBallFutureCoordinates(BallCoordinates currentCoordinates, DateTime actionTime)
        {
            if (currentCoordinates == null || !currentCoordinates.IsDefined)
            {
                throw new ArgumentException(String.Format(
                                                "[{0}] Unable to calculate ball future coordinates while current coordinates are null or undefined",
                                                MethodBase.GetCurrentMethod().Name));
            }

            if (actionTime < currentCoordinates.Timestamp)
            {
                throw new ArgumentException(String.Format(
                                                "[{0}] Unable to calculate ball future coordinates while action time is earlier than time stamp",
                                                MethodBase.GetCurrentMethod().Name));
            }

            BallCoordinates bfc;

            if (currentCoordinates.Vector == null || !currentCoordinates.Vector.IsDefined)
            {
                bfc        = new BallCoordinates(currentCoordinates.X, currentCoordinates.Y, actionTime);
                bfc.Vector = currentCoordinates.Vector;
                return(bfc);
            }

            bfc = currentCoordinates;
            try
            {
                TimeSpan deltaT = actionTime - currentCoordinates.Timestamp;

                int xfc = Convert.ToInt32(currentCoordinates.Vector.X * deltaT.TotalSeconds + currentCoordinates.X);
                int yfc = Convert.ToInt32(currentCoordinates.Vector.Y * deltaT.TotalSeconds + currentCoordinates.Y);

                if (_surveyor.IsCoordinatesInRange(xfc, yfc))
                {
                    bfc        = new BallCoordinates(xfc, yfc, actionTime);
                    bfc.Vector = currentCoordinates.Vector;
                }
                else
                {
                    BallCoordinates ricoshetCoordiantes = _ricochetCalc.Ricochet(currentCoordinates);
                    return(FindBallFutureCoordinates(ricoshetCoordiantes, actionTime));
                }
            }
            catch (Exception e)
            {
                Log.Print("Error: " + e.Message, eCategory.Error, LogTag.DECISION);
            }
            return(bfc);
        }
Exemplo n.º 3
0
        public void FindBallFutureCoordinates_VectorSpeedZero()
        {
            //arrange
            DateTime        now = DateTime.Now;
            BallCoordinates currentCoordinates = new BallCoordinates(100, 100, now);

            currentCoordinates.Vector = new Vector2D(0, 0);
            _surveyorMock.IsCoordinatesInRange(Arg.Any <int>(), Arg.Any <int>()).Returns(true);

            DateTime actionTime = now + TimeSpan.FromSeconds(5);

            //act
            BallCoordinates actualCoordinates = _testAsset.FindBallFutureCoordinates(currentCoordinates, actionTime);

            //assert
            Assert.AreEqual(currentCoordinates.X, actualCoordinates.X);
            Assert.AreEqual(currentCoordinates.Y, actualCoordinates.Y);
            Assert.AreEqual(actionTime, actualCoordinates.Timestamp);
            Assert.AreEqual(currentCoordinates.Vector.X, actualCoordinates.Vector.X);
            Assert.AreEqual(currentCoordinates.Vector.Y, actualCoordinates.Vector.Y);
        }