コード例 #1
0
        private bool TestMovement_PositiveGrade(List<string> messages)
        {
            bool result = true;

            Block oldStart = startBlock;
            startBlock = new Block(0, StateEnum.Healthy, 0, 0, 0.01, new[] { 0, 0 }, 100000, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);
            blocks[0] = startBlock;
            Train train = new Train(0, startBlock, _environment);

            train.ChangeMovement(200);
            train.updateMovement(); // should be less than 0.5

            if (train.CurrentAcceleration >= 0.5) // error
            {
                string error = train.ToString() + " did not lose any acceleration due to slope.";
                messages.Add(error);
                result = false;
            }

            // reset
            blocks[0] = oldStart;
            startBlock = oldStart;

            return result;
        }
コード例 #2
0
        private bool TestMovement_NoGrade(List<string> messages)
        {
            Train train = new Train(0, startBlock, _environment);

            train.ChangeMovement(200); // defaults to 0.5 because of zero grade
            train.updateMovement();

            if (train.CurrentAcceleration != 0.5) // error
            {
                string error = train.ToString() + " acceleration did not default to 0.5.";
                messages.Add(error);
                return false;
            }
            return true;
        }
コード例 #3
0
        private bool TestMovement_NegativeGrade(List<string> messages)
        {
            bool result = true;

            Block oldStart = startBlock;
            startBlock = new Block(0, StateEnum.Healthy, 0, 0, -0.01, new[] { 0, 0 }, 100000, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);
            blocks[0] = startBlock;
            Train train = new Train(1, startBlock, _environment);

            train.ChangeMovement(200);

            // allow 10 iterations of update movement
            for (int i = 0; i < 8; i++)
            {
                train.updateMovement();
            }

            train.EmergencyBrake();
            train.updateMovement(); // should be greater than -2.73

            if (train.CurrentAcceleration == -2.73) // error
            {
                string error = train.ToString() + " did not gain any acceleration due to slope.";
                messages.Add(error);
                result = false;
            }

            // reset
            blocks[0] = oldStart;
            startBlock = oldStart;

            return result;
        }
コード例 #4
0
        private bool TestEngineFailureMovement(List<string> messages)
        {
            bool result = true;

            Train train = new Train(0, startBlock, _environment);
            train.EngineFailure = true;
            if (train.ChangeMovement(200)) // error, changed movement during engine failure
            {
                string error = train.ToString() + " applied power during engine failure.";
                messages.Add(error);
                result = false;
            }

            if (train.ChangeMovement(-200)) // error, able to brake during engine failure
            {
                string error = train.ToString() + " applied brake during engine failure.";
                messages.Add(error);
                result = false;
            }

            train.EngineFailure = false; // reset

            return result;
        }
コード例 #5
0
        private bool TestEmergencyBrake(List<string> messages)
        {
            Train train = new Train(0, startBlock, _environment);

            train.ChangeMovement(200);

            // allow 10 iterations of update movement
            for (int i = 0; i < 10; i++)
            {
                train.updateMovement();
            }

            train.EmergencyBrake();
            train.updateMovement();

            if (train.CurrentAcceleration != -2.73) // error
            {
                string error = train.ToString() + " emergency brake did not set maximum deceleration correctly.";
                messages.Add(error);
                return false;
            }
            return true;
        }
コード例 #6
0
        private bool TestBrakeFailureMovement(List<string> messages)
        {
            bool result = true;

            Train train = new Train(0, startBlock, _environment);
            train.BrakeFailure = true;
            if (train.ChangeMovement(-200)) // error, braked during brake failure
            {
                string error = train.ToString() + " applied brakes during brake failure.";
                messages.Add(error);
                result = false;
            }

            if (!train.ChangeMovement(200)) // error, unable to supply power during brake failure
            {
                string error = train.ToString() + " was not able to accelerate during brake failure.";
                messages.Add(error);
                result = false;
            }

            train.BrakeFailure = false; // reset

            return result;
        }