Esempio n. 1
0
        /// <summary>
        /// Create a new engine for the boats.
        /// </summary>
        /// <param name="model">Unique model name for the <see cref="IBoatEngine"/>.</param>
        /// <param name="horsepower">Horsepower amount for the <see cref="IBoatEngine"/>.</param>
        /// <param name="displacement">Displacement amount for the <see cref="IBoatEngine"/>.</param>
        /// <param name="engineType"><see cref="EngineType"/> for the <see cref="IBoatEngine"/>.</param>
        /// <returns>Returns a string with information about the newly created <see cref="IBoatEngine"/>.</returns>
        public string CreateBoatEngine(string model, int horsepower, int displacement, EngineType engineType)
        {
            IBoatEngine engine;
            switch (engineType)
            {
                case EngineType.Jet:
                    engine = new JetEngine(model, horsepower, displacement);
                    break;
                case EngineType.Sterndrive:
                    engine = new SterndriveEngine(model, horsepower, displacement);
                    break;
                default:
                    throw new NotImplementedException();
            }

            this.Database.Engines.Add(engine);

            return string.Format(
                "Engine model {0} with {1} HP and displacement {2} cm3 created successfully.",
                model,
                horsepower,
                displacement);
        }
Esempio n. 2
0
        public void StartRace_AddedContestants_RaceProperlyFinished()
        {
            int distance = 1000;
            int windSpeed = 10;
            int oceanCurrentSpeed = 5;
            bool allowsMotorboats = true;

            var jetEngine = new JetEngine("GHP01", 250, 100);
            var sterndriveEngine = new SterndriveEngine("GHP01", 150, 150);

            var rowBoat = new RowBoat("Rower15", 450, 6);
            var powerBoat = new PowerBoat("PB150", 2200, new List<IBoatEngine> { jetEngine, sterndriveEngine });
            var sailBoat = new SailBoat("SailBoatPro", 200, 98);

            this.testController.OpenRace(distance, windSpeed, oceanCurrentSpeed, allowsMotorboats);
            this.testController.CurrentRace.AddParticipant(rowBoat);
            this.testController.CurrentRace.AddParticipant(powerBoat);
            this.testController.CurrentRace.AddParticipant(sailBoat);

            string result = this.testController.StartRace();
            string expectedResult = "First place: PowerBoat Model: PB150 Time: 2.85 sec" + Environment.NewLine
                                    + "Second place: RowBoat Model: Rower15 Time: 6.45 sec" + Environment.NewLine
                                    + "Third place: SailBoat Model: SailBoatPro Time: Did not finish!" + Environment.NewLine;

            Assert.AreEqual(expectedResult, result);
        }