Exemplo n.º 1
0
        public void TestCalculatingHorsePower()
        {
            UnitDriver driver2 = new UnitDriver("Boris", new UnitCar("Mazda", 90, 1000));

            race.AddDriver(driver);
            race.AddDriver(driver2);
            double horsePower = race.CalculateAverageHorsePower();

            Assert.AreEqual(horsePower, 120);
        }
Exemplo n.º 2
0
        [Test]  // Judge don't check the message => the test is unnecessary !!!
        public void AddDriver_ReturnsCorrectMessage_WhenDriverIsValid()
        {
            UnitCar    car    = new UnitCar("Model", 100, 500);
            UnitDriver driver = new UnitDriver("Pesho", car);
            string     result = raceEntry.AddDriver(driver);

            Assert.That(result, Is.EqualTo("Driver Pesho added in race."));
            //Assert.AreEqual("Driver Pesho added in race.", result);  // It's correct
            //Assert.AreEqual(result, "Driver Pesho added in race.");  // It's also works
        }
Exemplo n.º 3
0
        public void AddExistDr()
        {
            RaceEntry  race   = new RaceEntry();
            UnitCar    car    = new UnitCar("model", 3000, 250);
            UnitDriver driver = new UnitDriver("name", car);

            race.AddDriver(driver);

            Assert.Throws <InvalidOperationException>(() => race.AddDriver(driver));
        }
        public void TestAddSameDriver()
        {
            UnitDriver test = new UnitDriver("driver", new UnitCar("CarTest", 10, 10));

            Assert.Throws <InvalidOperationException>(() =>
            {
                this.raceEntry.AddDriver(this.unitDriver);
                this.raceEntry.AddDriver(test);
            });
        }
Exemplo n.º 5
0
        public void CalculateAvgHorsePowerThrowsExceptionIfCountIsUnderMinParticipants()
        {
            UnitDriver ud1 = new UnitDriver("Name1", new UnitCar("model1", 100, 123));

            raceEntry.AddDriver(ud1);
            Assert.Throws <InvalidOperationException>(() =>
            {
                var hp = raceEntry.CalculateAverageHorsePower();
            });
        }
        public void AddDriverWork()
        {
            UnitCar    car    = new UnitCar("golf", 100, 2000);
            UnitDriver driver = new UnitDriver("gosho", car);
            RaceEntry  race   = new RaceEntry();

            race.AddDriver(driver);

            Assert.AreEqual(race.Counter, 1);
        }
        public void TestConstructorUnitDriveShouldCreateDriverCorectly()
        {
            UnitCar    car    = new UnitCar("A", 10, 10.5);
            UnitDriver driver = new UnitDriver("B", car);

            Assert.AreEqual("B", driver.Name);
            Assert.AreEqual("A", driver.Car.Model);
            Assert.AreEqual(10, driver.Car.HorsePower);
            Assert.AreEqual(10.5, driver.Car.CubicCentimeters);
        }
Exemplo n.º 8
0
        public void Setup()
        {
            this.race = new RaceEntry();

            this.sportCar  = new UnitCar(this.CarModel[0], this.CarHorsePower[0], this.CarCubicPower[0]);
            this.muscleCar = new UnitCar(this.CarModel[1], this.CarHorsePower[1], this.CarCubicPower[1]);

            this.firstDriver  = new UnitDriver(FirstDriverName, this.sportCar);
            this.secondDriver = new UnitDriver(SecondDriverName, this.muscleCar);
        }
Exemplo n.º 9
0
        public void CounterShouldWorkProperly()
        {
            UnitDriver driver   = new UnitDriver("asd", new UnitCar("asdddas", 123, 12));
            int        expected = 1;

            raceEntry.AddDriver(driver);
            int actual = raceEntry.Counter;

            Assert.AreEqual(1, actual);
        }
Exemplo n.º 10
0
        public void AddDriverShouldWorksCorrectly()
        {
            UnitCar    car    = new UnitCar("bmw", 12, 23);
            UnitDriver driver = new UnitDriver("vasko", car);

            var result = this.driver.AddDriver(driver);

            Assert.AreEqual(this.driver.Counter, 1);
            Assert.AreEqual(result, $"Driver {driver.Name} added in race.");
        }
Exemplo n.º 11
0
        public void MethodAddDriverShouldThrowExceptionIfNullIsGiven()
        {
            //Arrange
            RaceEntry  raceEntry  = new RaceEntry();
            UnitDriver unitDriver = null;

            //Act - Assert
            Assert.Throws <InvalidOperationException>(()
                                                      => raceEntry.AddDriver(unitDriver));
        }
Exemplo n.º 12
0
        public void When_Adding_Null_Driver_Invalid_Operation_Exception_Should_Be_Thrown()
        {
            // Arange
            RaceEntry  raceEntry  = new RaceEntry();
            UnitDriver nullDriver = null;

            // Act - Assert
            Assert.Throws <InvalidOperationException>(() => raceEntry.AddDriver(nullDriver),
                                                      "Driver cannot be null.");
        }
Exemplo n.º 13
0
        public void RaceAddDriverException()
        {
            UnitCar car = new UnitCar("CZ", 100, 5.5);
            UnitDriver driver = new UnitDriver("A", car);
            RaceEntry race = new RaceEntry();
            race.AddDriver(driver);

            Assert.That(() => race.AddDriver(driver), Throws.InvalidOperationException.With.Message
                .EqualTo(string.Format("Driver {0} is already added.",driver.Name)));
        }
Exemplo n.º 14
0
        public void AddDriverShouldThrowExceptionWhenExsistingDriver()
        {
            var raceEntry = new RaceEntry();
            var driver    = new UnitDriver("pesho", new UnitCar("lada", 146, 86));

            raceEntry.AddDriver(driver);
            Assert.Throws <InvalidOperationException>(() =>
            {
                raceEntry.AddDriver(driver);
            });
        }
Exemplo n.º 15
0
        private UnitDriver CreateSimpleDriver(string name)
        {
            string model      = "Bora";
            int    horsePower = 130;
            double cubicCm    = 1900;

            UnitCar    car    = new UnitCar(model, horsePower, cubicCm);
            UnitDriver driver = new UnitDriver(name, car);

            return(driver);
        }
Exemplo n.º 16
0
        public void UnitDriver_Set_With_Null_Name_Throe_Message()
        {
            string name = null;

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() =>
            {
                UnitDriver nullNameDriver = new UnitDriver(name, testCar);
            });

            Assert.AreEqual(ex.Message, "Name cannot be null! (Parameter 'Name')");
        }
Exemplo n.º 17
0
 public void WhenAddingExistedDriver_ExceptionShouldBeTrown()
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         UnitCar car       = new UnitCar("Ferrari", 200, 300);
         UnitDriver driver = new UnitDriver("Pesho", car);
         RaceEntry raceEx  = new RaceEntry();
         raceEx.AddDriver(driver);
         raceEx.AddDriver(driver);
     });
 }
Exemplo n.º 18
0
        public void CalculateAverageHorsePower_ShouldThrowWhenNotEnoughtPeople()
        {
            var driver1 = new UnitDriver("Pesho", new UnitCar("bmw", 350, 520));

            var result = race.AddDriver(driver1);

            Assert.Throws <InvalidOperationException>(() =>
            {
                race.CalculateAverageHorsePower();
            });
        }
Exemplo n.º 19
0
        public void AddDriverMethod_ShouldAddDriverCorrectly()
        {
            var raceEntry = new RaceEntry();

            var    driver = new UnitDriver("Feri", new UnitCar("Nissan", 65, 60));
            string result = raceEntry.AddDriver(driver);


            Assert.AreEqual(result, $"Driver {driver.Name} added in race.");
            Assert.AreEqual(1, raceEntry.Counter);
        }
Exemplo n.º 20
0
        public void AddDriverIsWorkingProperly()
        {
            UnitDriver driver     = new UnitDriver("asd", new UnitCar("asdddas", 123, 12));
            UnitDriver driver1    = new UnitDriver("asd", new UnitCar("asdddas", 123, 12));
            UnitDriver driverNull = null;

            raceEntry.AddDriver(driver);

            Assert.Throws <InvalidOperationException>(() => raceEntry.AddDriver(driver1));
            Assert.Throws <InvalidOperationException>(() => raceEntry.AddDriver(driverNull));
        }
Exemplo n.º 21
0
        public void When_Drivers_Count_Is_Under_2_Invalid_Operation_Exception_Should_Be_Thrown()
        {
            // Arange
            RaceEntry  raceEntry  = new RaceEntry();
            UnitCar    unitCar    = new UnitCar("Test 5000", 420, 69);
            UnitDriver unitDriver = new UnitDriver("Test", unitCar);

            // Act - Arrange
            Assert.Throws <InvalidOperationException>(() => raceEntry.CalculateAverageHorsePower(),
                                                      "The race cannot start with less than 2 participants.");
        }
Exemplo n.º 22
0
        public void CalculateAverageHorsePowerShouldThrowExceptionWhenNotEnoughDrivers()
        {
            var raceEntry = new RaceEntry();
            var driver    = new UnitDriver("pesho", new UnitCar("lada", 146, 86));

            raceEntry.AddDriver(driver);
            Assert.Throws <InvalidOperationException>(() =>
            {
                raceEntry.CalculateAverageHorsePower();
            });
        }
Exemplo n.º 23
0
        public void AddDriverShouldWork()
        {
            UnitCar unitCar = new UnitCar("Unit", 150, 2000.0d);

            RaceEntry  drivers = new RaceEntry();
            UnitDriver driver  = new UnitDriver("Driver", unitCar);

            drivers.AddDriver(driver);

            Assert.AreEqual(1, drivers.Counter);
        }
 public void CalcAverageDriverIsLess2()
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         UnitCar car       = new UnitCar("golf", 100, 2000);
         UnitDriver driver = new UnitDriver("gosho", car);
         RaceEntry race    = new RaceEntry();
         race.AddDriver(driver);
         race.CalculateAverageHorsePower();
     });
 }
Exemplo n.º 25
0
        public void ShouldCountLess_WhenParticipantsLessThenCounter()
        {
            var car1    = new UnitCar("model1", 100, 1000);
            var driver1 = new UnitDriver("Sena", car1);

            race.AddDriver(driver1);

            var count = race.Counter;

            Assert.That(count, Is.LessThan(2));
        }
Exemplo n.º 26
0
        public void AddDriver_IncreasesCount_WhenAddingValidDriver()
        {
            string     name   = "Stancho";
            UnitDriver driver = CreateSimpleDriver(name);

            testEntry.AddDriver(driver);

            int predicted = 1;

            Assert.AreEqual(predicted, testEntry.Counter);
        }
Exemplo n.º 27
0
 public void WhenCalculateAverageHorsePowerDriverCountIsLessThanMinParticipiants_ShouldThrowWxceptionk()
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         UnitCar car1       = new UnitCar("Ferrari", 20, 30);
         UnitDriver driver3 = new UnitDriver("Tania", car1);
         RaceEntry raceEx   = new RaceEntry();
         var result         = raceEx.AddDriver(driver3);
         raceEx.CalculateAverageHorsePower();
     });
 }
Exemplo n.º 28
0
        public void RaceEntry_Add_UnitDriver_With_Null_Driver_Throe_And_Message()
        {
            UnitDriver nullDriver = null;

            InvalidOperationException ex = Assert.Throws <InvalidOperationException>(() =>
            {
                testEntry.AddDriver(nullDriver);
            });

            Assert.AreEqual(ex.Message, "Driver cannot be null.");
        }
        public void AddDriver_ShouldThrowExeption_WhenDriverAlreadyExists()
        {
            UnitDriver driver = new UnitDriver("Gosho", car);

            race.AddDriver(driver);

            Assert.Throws <InvalidOperationException>(() =>
            {
                race.AddDriver(driver);
            }, $"Driver {driver.Name} is already added.");
        }
 public void AddDriverDriverExist()
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         UnitCar car       = new UnitCar("golf", 100, 2000);
         UnitDriver driver = new UnitDriver("gosho", car);
         RaceEntry race    = new RaceEntry();
         race.AddDriver(driver);
         race.AddDriver(driver);
     });
 }