Пример #1
0
        public bool seleccionarCalculadora(String calculadora)
        {
            bool esValida = true;

            switch (calculadora)
            {
                case "1":
                    Calorias calorias = new Calorias();
                    Console.WriteLine("Calorias consumidas: " + calorias.doOperation(persona));
                    break;
                case "2":
                    Carbohidratos carbs = new Carbohidratos();
                    Console.WriteLine("Carbohidratos: "+carbs.doOperation(persona));
                    break;
                case "3":
                    PesoIdeal pesoIdeal = new PesoIdeal();
                    Console.WriteLine("BMI: " + pesoIdeal.doOperation(persona));
                    break;
                case "4":
                    GrasaCorporal grasaCorporal = new GrasaCorporal();
                    String temp;
                    try
                    {
                        temp=grasaCorporal.doOperation(persona)+"";
                    }
                    catch (NotSupportedException ex)
                    {
                        temp=ex.Message;
                    }
                    Console.WriteLine("Grasa Corporal: "+temp);
                    break;
                case "5":
                    estaActiva = false;
                    break;
                default:
                    esValida = false;
                    break;
            }

            return esValida;
        }
Пример #2
0
 public void TestGrasaCorporal()
 {
     RandomGenerator r = new RandomGenerator();
     GrasaCorporal c = new GrasaCorporal();
     var persons = Builder<Person>.CreateListOfSize(tests).
             All().With(x => x.Age = r.Next(2, 110))
                  .And(x => x.Height = r.Next(tests, 260))
                  .And(x => x.Weight = r.Next(0, 999))
                  .And(x => x.IsMan = r.Next())
                  .And(x => x.Hip = r.Next(20, 60))
                  .And(x => x.Waist = r.Next(20, 60))
                  .And(x => x.Neck = r.Next(10, 30))
            .Build();
     foreach (Person p in persons)
     {
         if (p.Age >= 18)
         {
             float expected;
             if (p.IsMan)
             {
                 expected = 495 / (float)(1.0324 - 0.19077 * (Math.Log10(p.Waist - p.Neck)) + 0.15456 * (Math.Log10(p.Height))) - 450;
             }
             else
             {
                 expected = 495 / (float)(1.29579 - 0.35004 * (Math.Log10((p.Hip + p.Waist) - p.Neck)) + 0.22100 * (Math.Log10(p.Height))) - 450;
             }
             float value = c.doOperation(p);
             Assert.AreEqual(expected, value);
         }
         else
         {
             try
             {
                 c.doOperation(p);
                 Assert.Fail("Debio dar error");
             }
             catch (NotSupportedException)
             {
                 Assert.IsTrue(true);
             }
         }
     }
 }