示例#1
0
        public void Bac(Ounces alcohol, Pounds weight, Gender gender, TimeSpan sinceDrink)
        {
            Debug.Assert(alcohol != null && alcohol.Total >= 0f);
            Debug.Assert(weight != null && weight.Total >= 0f);
            Debug.Assert(sinceDrink.Hours >= 0f);

            BacResults(CalculateBac(alcohol.Total, weight.Total, gender, sinceDrink));
        }
示例#2
0
            public void Legal_To_Drive()
            {
                var subject = new BloodAlcoholCalculator {
                    Output = new StringWriter()
                };

                subject.Bac(
                    alcohol: Ounces.FromOunces(4.4f),
                    weight: Pounds.FromPounds(180.0f),
                    gender: Gender.Female,
                    sinceDrink: TimeSpan.FromHours(3));

                Assert.That(subject.Output.ToString(), Is.StringContaining("You are legal to drive."));
            }
示例#3
0
            public void Illegal_To_Drive()
            {
                var subject = new BloodAlcoholCalculator {
                    Output = new StringWriter()
                };

                subject.Bac(
                    alcohol: Ounces.FromOunces(25.0f),
                    weight: Pounds.FromPounds(100.0f),
                    gender: Gender.Male,
                    sinceDrink: TimeSpan.FromHours(1));

                Assert.That(subject.Output.ToString(),
                            Is.StringContaining("It is not legal for you to drive."));
            }
示例#4
0
        public void Execute()
        {
            var alcohol         = Input.FloatParse(message: "Alcohol (ounces): ");
            var weight          = Input.FloatParse(message: "Weight (pounds): ");
            var genderInput     = Input.ParseStringMatching(message: "Gender Male/Female: ", expression: "(Male|Female)");
            var hoursSinceDrink = Input.ParseInt(message: "Hours Since Drink: ");

            var calculator = new BloodAlcoholCalculator();

            calculator.Bac(
                Ounces.FromOunces(alcohol),
                Pounds.FromPounds(weight),
                (Gender)Enum.Parse(typeof(Gender), genderInput, ignoreCase: true),
                TimeSpan.FromHours(hoursSinceDrink)
                );
        }