コード例 #1
0
        public void Calculate_NormalWeightBigBody_Return23Point46()
        {
            double heightInInches = 83.00;
            double weightInPounds = 230.00;

            double bmi = BmiCalculator.Calculate(heightInInches, weightInPounds);

            Assert.That(bmi, Is.EqualTo(23.46).Within(0.01));
        }
コード例 #2
0
        public void Calculate_NormalWeightSmallBody_Return18Point8()
        {
            double heightInInches = 58.00;
            double weightInPounds = 90.00;

            double bmi = BmiCalculator.Calculate(heightInInches, weightInPounds);

            Assert.That(bmi, Is.EqualTo(18.80).Within(0.01));
        }
コード例 #3
0
        public void CalculateExceptionTest()
        {
            var target = new BmiCalculator();

            // 身長
            // 0はダメ
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => target.Calculate(0, 1), "height 0");
            // マイナスもダメ
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => target.Calculate(-1, 1), "height -1");
            // 1〜はOK
            var h1 = target.Calculate(1, 1);
            var h2 = target.Calculate(160, 1);
            var h3 = target.Calculate(999, 1);

            //体重
            //0はダメ
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => target.Calculate(1, 0), "weight 0");
            // マイナスもダメ
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => target.Calculate(1, -1), "weight -1");
            // 1〜はOK
            var w1 = target.Calculate(1, 1);
            var w2 = target.Calculate(1, 50);
            var w3 = target.Calculate(1, 100);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("身長をセンチメートル単位で入力してください。例:170");
            string strHeight = System.Console.ReadLine();
            int    intHeight = int.Parse(strHeight);

            System.Console.WriteLine("体重をキログラム単位で入力してください。例:70");
            string        strWeight  = System.Console.ReadLine();
            int           intWeight  = int.Parse(strWeight);
            BmiCalculator calculator = new BmiCalculator();
            double        value      = calculator.Calculate(intHeight, intWeight);

            System.Console.WriteLine($"あなたのBMI指数は {value} です。");
            System.Console.ReadLine();
        }
コード例 #5
0
        public void CalculatTest()
        {
            // Arrange
            var testData = new List <(int heightCm, int weightKg, double expectedResult)>();

            testData.Add((100, 1, 1.0));
            testData.Add((150, 45, 20.0));
            testData.Add((200, 100, 25.0));
            var target = new BmiCalculator();

            foreach (var pattern in testData)
            {
                // Act
                double actual = target.Calculate(pattern.heightCm, pattern.weightKg);
                // Assert
                Assert.AreEqual(pattern.expectedResult, actual, $"height:{pattern.heightCm},weight:{pattern.weightKg},expected:{pattern.expectedResult},actual:{actual}");
            }
        }
コード例 #6
0
        public IActionResult Calculate(int?heightCm, int?weightKg)
        {
            //入力チェック(intとして無効な引数が渡された場合もnullになる)
            if (!heightCm.HasValue)
            {
                return(RedirectToAction("Index"));
            }
            if (!weightKg.HasValue)
            {
                return(RedirectToAction("Index"));
            }
            BmiCalculator calculator = new BmiCalculator();
            double        result     = calculator.Calculate(heightCm.Value, weightKg.Value);
            var           vm         = new CalculatorViewModel()
            {
                HeightCm = heightCm.Value, WeightKg = weightKg.Value, BmiIndex = result
            };

            return(View(vm));
        }
コード例 #7
0
        public IncomeProtectionV1QuestionSet()
        {
            var questionSpecs = new[]
            {
                Question("Have you been a resident in the UK for at least the last 3 years and is your income liable to UK tax?")
                .NoValidationWarning()
                .NoAdditionalStatement(),

                Question("Do you have a UK Bank or Building Society account?")
                .NoValidationWarning()
                .NoAdditionalStatement(),

                Question("Have you been registered with a UK medical practice for at least 36 months prior to this application?")
                .NoValidationWarning()
                .NoAdditionalStatement(),

                Question("Does any part of your paid or unpaid occupation(s) include any of the following?")
                .ValidationWarning("If yes, full underwriting",
                                   incomeProtection => incomeProtection.HasSpecifiedOccupation
                            ? ValidationResult.Underwriting
                            : ValidationResult.Valid)
                .AvailableStatements("Any branch of the Armed Forces",
                                     "Handling explosives",
                                     "Underwater duties",
                                     "Oil Rig or offshore work",
                                     "Professional or Semi Professional Sports Persons",
                                     "Nightclub Security Personnel, Bailiffs, or Bodyguards",
                                     "Work with animals",
                                     "Police Community Support Officers or Special Constables",
                                     "Fire-fighters, including reserve or retained Fire-fighters",
                                     "Working on board sea or ocean going vessels"),

                Question("Have you ever made an application to The Shepherds Friendly Society that has been postponed, declined, offered on special terms or cancelled?")
                .ValidationWarning("If yes, full underwriting",
                                   incomeProtection => incomeProtection.HasApplicationToShepherdsWithSpecifiedStatus
                            ? ValidationResult.Underwriting
                            : ValidationResult.Valid)
                .NoAdditionalStatement(),

                Question("Do any of the following statements apply to you?")
                .ValidationWarning("If yes, full underwriting",
                                   incomeProtection => incomeProtection.HasSpecifiedIllnessOrCondition
                            ? ValidationResult.Underwriting
                            : ValidationResult.Valid)
                .AvailableStatements("I am currently unable to work or am working reduced hours or on restricted duties due to sickness or accident.",
                                     "I have suffered from symptoms of chronic fatigue syndrome, ME or fibromyalgia in the last 3 years.",
                                     "I have suffered from cancer or malignant tumour which has been treated with radiotherapy or chemotherapy in the last 3 years.",
                                     "I am currently suffering from an illness for which I am being prescribed methotrexate or chemotherapy in the last 3 years.",
                                     "I am currently suffering from an illness for which I am being prescribed oral steroids or immunosuppressive treatment.",
                                     "I have had a Stroke or mini Stroke (also known as Transient Ischaemic attack)",
                                     "I have had a heart attack, or been diagnosed with angina or coronary disease.",
                                     "I have been diagnosed with a disease of the central nervous system such as multiple sclerosis, Parkinson’s disease, Alzheimer’s disease or dementia.",
                                     "I am suffering from paralysis, paraplegia or quadriplegia caused by damage to my spinal cord.",
                                     "I have suffered from or been diagnosed with diabetes (other than during pregnancy)",
                                     "I have been diagnosed with HIV or I am awaiting the results of a HIV test.",
                                     "I have undergone major organ transplant."),

                Question("Have you ever been referred to see a psychiatrist.")
                .ValidationWarning("If yes, full underwriting",
                                   incomeProtection => incomeProtection.HasBeenReferredToPsychiatrist
                            ? ValidationResult.Underwriting
                            : ValidationResult.Valid)
                .NoAdditionalStatement(),

                Question("Height and Weight for BMI")
                .ValidationWarning("If >35, full underwriting",
                                   incomeProtection => BmiCalculator.Calculate(incomeProtection.HeightInMeter, incomeProtection.WeightInKg) > 35
                            ? ValidationResult.Underwriting
                            : ValidationResult.Valid)
                .NoAdditionalStatement(),

                Question("How many cigarettes do you currently smoke per day?")
                .ValidationWarning("If >20pc, full underwriting",
                                   incomeProtection => incomeProtection.CigarettesPerDay > 20
                            ? ValidationResult.Underwriting
                            : ValidationResult.Valid)
                .NoAdditionalStatement(),

                Question("Do you consume more than 30 units of alcohol per week or have you ever been dependant on alcohol or been advised to reduce your intake?")
                .ValidationWarning("If yes, full underwriting",
                                   incomeProtection => incomeProtection.HasOrHadAlcoholDependency
                            ? ValidationResult.Underwriting
                            : ValidationResult.Valid)
                .NoAdditionalStatement(),

                Question("Have you used cannabis within the past year, or do you intend to begin using cannabis?")
                .ValidationWarning("If yes, full underwriting",
                                   incomeProtection => incomeProtection.HasUsedOrIntendToUseCannabis
                            ? ValidationResult.Underwriting
                            : ValidationResult.Valid)
                .NoAdditionalStatement(),

                Question("Other than cannabis, have you ever or do you intend to use any recreational or non prescription drugs (e.g. cannabis, ecstacy, cocaine, heroin, annabolic steroids etc?")
                .ValidationWarning("If yes, full underwriting",
                                   incomeProtection => incomeProtection.HasUsedOrIntendToUseAnyOtherReacreationalDrug
                            ? ValidationResult.Underwriting
                            : ValidationResult.Valid)
                .NoAdditionalStatement()
            };

            questionWithValidators = CreateQuestionWithValidations(questionSpecs);
        }