public void StartRace_BoatWithNegativeTime_ShouldNotFinish() { var first = new RowBoat("rowboat1", 80, 4); var second = new RowBoat("rowboat2", 90, 4); var third = new SailBoat("sailboat1", 200, 98); this.controller.OpenRace(1000, 10, 5, false); this.controller.CurrentRace.AddParticipant(first); this.controller.CurrentRace.AddParticipant(second); this.controller.CurrentRace.AddParticipant(third); var distance = this.controller.CurrentRace.Distance; var firstTime = distance / first.CalculateRaceSpeed(this.controller.CurrentRace); var secondTime = distance / second.CalculateRaceSpeed(this.controller.CurrentRace); var thirdTime = distance / third.CalculateRaceSpeed(this.controller.CurrentRace); if (thirdTime <= 0) { thirdTime = double.PositiveInfinity; } var expected = new StringBuilder(); expected.AppendLine(string.Format( "First place: RowBoat Model: rowboat1 Time: {0} sec", firstTime.ToString("0.00"))); expected.AppendLine(string.Format( "Second place: RowBoat Model: rowboat2 Time: {0} sec", secondTime.ToString("0.00"))); expected.Append("Third place: SailBoat Model: sailboat1 Time: "); expected.Append(double.IsInfinity(thirdTime) ? "Did not finish!" : thirdTime.ToString("0.00")); var actual = this.controller.StartRace(); Assert.AreEqual(expected.ToString(), actual); }
public void OpenRace_GetParticipants_ShouldReturnCorrectParticipants() { var first = new SailBoat("model1", 100, 45); var second = new SailBoat("model2", 100, 45); var third = new SailBoat("model3", 100, 45); var expected = new List<IBoat> { first, second, third }; this.controller.OpenRace(500, 2, 1, false); this.controller.CurrentRace.AddParticipant(first); this.controller.CurrentRace.AddParticipant(second); this.controller.CurrentRace.AddParticipant(third); var actual = this.controller.CurrentRace.GetParticipants().ToList(); CollectionAssert.AreEqual(expected, actual); }
public void StartRace_FinishRace_ShouldRemoveCurrentRaceAfterFinish() { var first = new RowBoat("rowboat1", 80, 4); var second = new RowBoat("rowboat2", 90, 4); var third = new SailBoat("sailboat1", 200, 98); this.controller.OpenRace(1000, 10, 5, false); this.controller.CurrentRace.AddParticipant(first); this.controller.CurrentRace.AddParticipant(second); this.controller.CurrentRace.AddParticipant(third); this.controller.StartRace(); Assert.IsNull(this.controller.CurrentRace); }