public void GetAirSpeed_NotNailed_NorwegianBlueParrot_should_return_expectedSpeed(int voltage, int expectedSpeed)
        {
            // Arrange
            var sut = new BirdProperties()
            {
                Type = "NorwegianBlueParrot", Voltage = voltage, IsNailed = false
            };

            // Act
            var outcome = new FlightCalculator().GetAirSpeed(sut);

            // Assert
            outcome.Should().Be(expectedSpeed);
        }
        public void GetAirSpeed_AfricanSwallow_should_return_expectedSpeed(int numberOfCoconuts, int expectedSpeed)
        {
            // Arrange
            var sut = new BirdProperties()
            {
                Type = "AfricanSwallow", NumberOfCoconuts = numberOfCoconuts
            };

            // Act
            var outcome = new FlightCalculator().GetAirSpeed(sut);

            // Assert
            outcome.Should().Be(expectedSpeed);
        }
        public void GetAirSpeed_EuropeanSwallow_should_return_35()
        {
            // Arrange
            const int expected = 35;
            var       sut      = new BirdProperties()
            {
                Type = "EuropeanSwallow"
            };

            // Act
            var outcome = new FlightCalculator().GetAirSpeed(sut);

            // Assert
            outcome.Should().Be(expected);
        }
        public void GetAirSpeed_Unknown_type_should_return_0(string type)
        {
            // Arrange
            const int expected = 0;
            var       sut      = new BirdProperties()
            {
                Type = type
            };

            // Act
            var outcome = new FlightCalculator().GetAirSpeed(sut);

            // Assert
            outcome.Should().Be(expected);
        }
        public void GetAirSpeed_Nailed_NorwegianBlueParrot_should_return_0()
        {
            // Arrange
            const int expected = 0;
            var       sut      = new BirdProperties()
            {
                Type = "NorwegianBlueParrot", IsNailed = true
            };

            // Act
            var outcome = new FlightCalculator().GetAirSpeed(sut);

            // Assert
            outcome.Should().Be(expected);
        }
Example #6
0
        /*
         * 1. Create factory function
         * 2. Move conditional code to superclass
         * 3. Take a subclass, create override
         * 4. Repeat for every conditional
         * 5. Adjust function is superclass (consider making superclass abstract)
         */
        public int GetAirSpeed(BirdProperties properties)
        {
            switch (properties.Type)
            {
            case "EuropeanSwallow":
                return(35);

            case "AfricanSwallow":
                return(40 - 2 * properties.NumberOfCoconuts);

            case "NorwegianBlueParrot":
                return(properties.IsNailed ? 0 : 10 + properties.Voltage / 10);

            default:
                return(0);
            }
        }