Пример #1
0
        /// <summary>
        ///     Toggles signal pickup failure.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event args</param>
        private void buttonSignalPickupFailure_Click(object sender, EventArgs e)
        {
            _selectedTrain = (Train)allTrainComboBox.SelectedItem;

            if (_selectedTrain != null)
            {
                if (_selectedTrain.SignalPickupFailure)
                {
                    _selectedTrain.SignalPickupFailure = false;
                    UpdateGUI();
                }
                else
                {
                    _selectedTrain.SignalPickupFailure = true;
                    UpdateGUI();
                    DisplayError("CRITICAL ERROR: Signal pickup failure for " + _selectedTrain.ToString());
                }
            }
        }
Пример #2
0
        /// <summary>
        ///     Updates the GUI with the information for the selected train.
        /// </summary>
        private void UpdateGUI()
        {
            if (InvokeRequired)
            {
                BeginInvoke(new Action(UpdateGUI));
                return;
            }

            // check if trains have been added or removed from list
            if (_numTrains != _allTrains.Count)
            {
                PopulateComboBox(_allTrains);
                _numTrains = _allTrains.Count;
            }

            if (_selectedTrain != null)
            {
                trainLabel.Text                 = _selectedTrain.ToString();
                trainInfoTextBox.Text           = _selectedTrain.InformationLog;
                trainInfoTextBox.SelectionStart = trainInfoTextBox.TextLength;
                trainInfoTextBox.ScrollToCaret();
                trainInfoTextBox.Focus();

                positionValueText.Text     = Math.Round(_selectedTrain.CurrentPosition, 3).ToString();
                velocityValueText.Text     = Math.Round(_selectedTrain.CurrentVelocity, 3).ToString();
                accelerationValueText.Text = Math.Round(_selectedTrain.CurrentAcceleration, 3).ToString();

                gradeValueText.Text = _selectedTrain.CurrentBlock.Grade.ToString();
                massValueText.Text  = Math.Round(_selectedTrain.TotalMass, 3).ToString();

                numPassengersValueText.Text = _selectedTrain.NumPassengers.ToString();
                numCrewValueText.Text       = _selectedTrain.NumCrew.ToString();

                brakeFailureLabel.Text        = _selectedTrain.BrakeFailure.ToString();
                engineFailureLabel.Text       = _selectedTrain.EngineFailure.ToString();
                signalPickupFailureLabel.Text = _selectedTrain.SignalPickupFailure.ToString();

                // sets text for emergency brake
                if (_selectedTrain.EmergencyBrakePulled)
                {
                    emergencyBrakeLabel.Text = "Toggled On";
                }
                else
                {
                    emergencyBrakeLabel.Text = "Toggled Off";
                }

                // set values for lights
                if (_selectedTrain.LightsOn)
                {
                    lightsValueText.Text = "On";
                }
                else
                {
                    lightsValueText.Text = "Off";
                }

                // set values for doors
                if (_selectedTrain.DoorsOpen)
                {
                    doorsValueText.Text = "Open";
                }
                else
                {
                    doorsValueText.Text = "Closed";
                }
            }
        }
        private bool TestTemperature(List<string> messages)
        {
            Train train = new Train(0, startBlock, _environment);
            train.Temperature = 70;

            if (train.Temperature != 70) // error
            {
                string error = train.ToString() + " did not set temperature correctly.";
                messages.Add(error);
                return false;
            }

            return true;
        }
Пример #4
0
        /// <summary>
        ///     Toggles signal pickup failure.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event args</param>
        private void buttonSignalPickupFailure_Click(object sender, EventArgs e)
        {
            _selectedTrain = (Train)allTrainComboBox.SelectedItem;

            if (_selectedTrain != null)
            {
                if (_selectedTrain.SignalPickupFailure)
                {
                    _selectedTrain.SignalPickupFailure = false;
                    UpdateGUI();
                }
                else
                {
                    _selectedTrain.SignalPickupFailure = true;
                    UpdateGUI();
                    DisplayError("CRITICAL ERROR: Signal pickup failure for " + _selectedTrain.ToString());
                }
            }
        }
        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;
        }
        private bool TestRemovePassengers(List<string> messages)
        {
            bool result = true;

            Train train = new Train(0, startBlock, _environment);
            train.NumPassengers = 25;
            train.NumCrew = 10;

            // remove passengers
            train.NumPassengers = 10;
            train.NumCrew = 0;

            if ((train.NumPassengers != 10) || (train.NumCrew != 0)) // error
            {
                string error = train.ToString() + " did not remove";
                if (train.NumPassengers == -25)
                    error += " passengers,";
                if (train.NumCrew == -10)
                    error += " crew";

                error += " correctly.";
                messages.Add(error);
                result = false;
            }

            // reset
            train.NumPassengers = 0;
            train.NumCrew = 0;

            return result;
        }
        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;
        }
        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;
        }
        private bool TestLights(List<string> messages)
        {
            Train train = new Train(0, startBlock, _environment);
            train.LightsOn = true;

            if (train.LightsOn == false) // error
            {
                string error = train.ToString() + " did not turn the lights on correctly.";
                messages.Add(error);
                return false;
            }

            train.LightsOn = false;

            if (train.LightsOn == true) // error
            {
                string error = train.ToString() + " did not turn the lights off correctly.";
                messages.Add(error);
                return false;
            }

            return true;
        }
        private bool TestMass(List<string> messages)
        {
            bool result = true;

            double initialTrainMass = 40900; //kilograms
            double personMass = 90; //kilograms
            Random random = new Random();

            Train train = new Train(0, startBlock, _environment);

            int randomNum = random.Next(0, 223); // 0 to 222 passengers
            train.NumPassengers = randomNum;

            double compareMass = initialTrainMass + personMass * randomNum;

            if (compareMass != train.TotalMass) // error
            {
                string error = train.ToString() + " did not calculate mass correctly.";
                messages.Add(error);
                result = false;
            }

            train.NumPassengers = 0; // reset

            return result; // all passed
        }
        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;
        }
        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;
        }
        private bool TestDoors(List<string> messages)
        {
            Train train = new Train(0, startBlock, _environment);
            train.DoorsOpen = true;

            if (train.DoorsOpen == false) // error
            {
                string error = train.ToString() + " did not open doors correctly.";
                messages.Add(error);
                return false;
            }

            train.DoorsOpen = false;

            if (train.DoorsOpen == true) // error
            {
                string error = train.ToString() + " did not close doors correctly.";
                messages.Add(error);
                return false;
            }

            return true;
        }
        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;
        }
        private bool TestAddPassengers(List<string> messages)
        {
            bool result = true;

            Train train = new Train(0, startBlock, _environment);

            // correct add passengers
            train.NumPassengers = 25;
            train.NumCrew = 10;

            if ((train.NumPassengers != 25) || (train.NumCrew != 10)) // error
            {
                string error = train.ToString() + " did not add";
                if (train.NumPassengers != 25)
                    error += " passengers,";
                if (train.NumCrew != 10)
                    error += " crew";

                error += " correctly.";
                messages.Add(error);
                result = false;
            }

            // incorrect negative add passengers
            train.NumPassengers = -25;
            train.NumCrew = -10;

            if ((train.NumPassengers != 25) || (train.NumCrew != 10)) // error
            {
                string error = train.ToString() + " set";
                if (train.NumPassengers == -25)
                    error += " passengers,";
                if (train.NumCrew == -10)
                    error += " crew";

                error += " to negative number.";
                messages.Add(error);
                result = false;
            }

            // incorrect too many passengers
            train.NumPassengers = 500;
            train.NumCrew = 400;

            if ((train.NumPassengers != 25) || (train.NumCrew != 10)) // error
            {
                string error = train.ToString() + " set";
                if (train.NumPassengers == -25)
                    error += " passengers,";
                if (train.NumCrew == -10)
                    error += " crew";

                error += " over maximum capacity.";
                messages.Add(error);
                result = false;
            }

            // reset
            train.NumPassengers = 0;
            train.NumCrew = 0;

            return result;
        }