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 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 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; }