コード例 #1
0
        public void BMIInMemoryTestA()
        {
            LogContext db = new LogContext(new DbContextOptionsBuilder <LogContext>()
                                           .UseInMemoryDatabase(databaseName: "BMIA")
                                           .Options);

            f.BMI(5, 11, 123, db);
            BMILog result = db.BMILogs.ToList()[0];

            Assert.AreEqual("17.57 Underweight", result.result);
        }
コード例 #2
0
        public string BMI(double heightFeet, double heightInches, double weight, LogContext db)
        {
            BMILog log = new BMILog(DateTime.Now, heightFeet, heightInches, weight, "");

            if (heightFeet < 0 || heightInches < 0 || weight <= 0 || (heightFeet == 0 && heightInches == 0))
            {
                log.result = "Impossible";
                goto skip;
            }
            weight       *= .45;
            heightInches += 12 * heightFeet;
            heightInches *= .025;
            heightInches *= heightInches;
            double ans = weight / heightInches;

            ans = Math.Round(ans, 2);
            string result;

            if (ans < 18.5)
            {
                result = ans.ToString() + " Underweight";
            }
            else if (ans >= 18.5 && ans < 25)
            {
                result = ans.ToString() + " Normal weight";
            }
            else if (ans >= 25 && ans < 30)
            {
                result = ans.ToString() + " Overweight";
            }
            else
            {
                result = ans.ToString() + " Obese";
            }
            log.result = result;
skip:
            db.BMILogs.Add(log);
            db.SaveChanges();
            return(log.result);
        }