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; }
public void TestPesoIdeal() { RandomGenerator r = new RandomGenerator(); PesoIdeal c = new PesoIdeal(); var persons = Builder<Person>.CreateListOfSize(tests + tests). All().With(x => x.Age = r.Next(0, 110)) .And(x => x.Height = r.Next(tests, 260)) .And(x => x.Weight = r.Next(0, 200)) .And(x => x.IsMan = r.Next()) .Build(); foreach (Person p in persons) { float expected = 0.0f; if (p.Age >= 18) { expected = (float)((p.Weight) / (Math.Pow(p.Height / 100, 2))); } else { expected = (float)(((p.Weight) / (Math.Pow(p.Height, 2))) * 10000); } float value = c.doOperation(p); Assert.AreEqual(expected, value); } }