isdaviddong
3/16/2017 - 8:04 AM

BMIProcessor.cs

using Microsoft.VisualStudio.TestTools.UnitTesting;
using WebApplication1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WebApplication1.Tests
{
    [TestClass()]
    public class BMIProcessorTests
    {
        [TestMethod()]
        public void CalculateTest()
        {
            //arrange
            WebApplication1.BMIProcessor bmi = new BMIProcessor();

            bmi.Height = 170;
            bmi.Weight = 70;
            //act
            var result = bmi.Calculate();
            //assert
            Assert.AreEqual("24.22", result.ToString("00.00"));
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication1
{
    public class BMIProcessor
    {
        public int Weight { get; set; }
        public int Height { get; set; }
        public float BMI
        {
            get
            {
                return Calculate();
            }
        }


        public float Calculate()
        {
            float result = 0;
            //應該有錯
            float height = (int)Height / 100;
            result = Weight / (height * height);

            return result;
        }
    }
}