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 StartRace_BoatsWithEqualTime_ShouldDisplayInOrderOfAddition() { var first = new RowBoat("SecondAdded", 80, 2); var second = new RowBoat("FirstAdded", 80, 2); var third = new RowBoat("rowboat3", 100, 2); this.controller.OpenRace(5000, 10, 5, false); this.controller.CurrentRace.AddParticipant(second); this.controller.CurrentRace.AddParticipant(first); 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); var expected = new StringBuilder(); expected.AppendLine(string.Format( "First place: RowBoat Model: FirstAdded Time: {0} sec", secondTime.ToString("0.00"))); expected.AppendLine(string.Format( "Second place: RowBoat Model: SecondAdded Time: {0} sec", firstTime.ToString("0.00"))); expected.Append(string.Format( "Third place: RowBoat Model: rowboat3 Time: {0} sec", thirdTime.ToString("0.00"))); var actual = this.controller.StartRace(); Assert.AreEqual(expected.ToString(), actual); }
public void Initialize() { var engine = new SterndriveEngine("engine", 10, 100); var boat1 = new RowBoat("Rowboat1", 50, 1); var boat2 = new Yacht("Yacht1", 10, engine, 10); this.FakeBoats = new List<IBoat>() {boat1,boat2}; Mock<IBoatSimulatorDatabase> fakeDb = new Mock<IBoatSimulatorDatabase>(); fakeDb.Setup(x => x.Boats.GetItem("Test1")).Returns(boat1); fakeDb.Setup(x => x.Boats.GetItem("Test2")).Returns(boat2); Mock<IRace> fakeRace = new Mock<IRace>(); fakeRace.Setup(x => x.AllowsMotorboats).Returns(false); this.FakeDb = fakeDb; this.FakeRace = fakeRace; }
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); }
public void StartRace_InsufficientContestants_ShouldThrow() { var first = new RowBoat("rowboat1", 100, 4); var second = new RowBoat("rowboat2", 90, 4); this.controller.OpenRace(5000, 10, 5, false); this.controller.CurrentRace.AddParticipant(first); this.controller.CurrentRace.AddParticipant(second); this.controller.StartRace(); }