private void Calcular(object sender, RoutedEventArgs e)
        {
            const int SINVALOR = 0;

            string     strNum;
            StackPanel stkParam;
            StackPanel stkButton          = (sender as Button).Parent as StackPanel;
            StackPanel stkParentParentBtn = stkButton.Parent as StackPanel;
            Figura     figura             = (stkParentParentBtn.Parent as TabItem).Tag as Figura;
            List <int> args = new List <int>();

            foreach (UIElement item in stkParentParentBtn.Children)
            {
                stkParam = item as StackPanel;
                if ((bool)stkParam.Tag)
                {
                    strNum = (stkParam.Children[1] as TextBox).Text;
                    if (!string.IsNullOrEmpty(strNum))
                    {
                        args.Add(int.Parse(strNum));
                    }
                    else
                    {
                        args.Add(SINVALOR);
                    }
                }
            }
            (stkButton.Children[1] as Label).Content = $"Result: {figura.Area(args)}";
        }
Beispiel #2
0
            public int CompareTo(object obj)
            {
                Figura p = (Figura)obj;

                if (this.Area() < p.Area())
                {
                    return(-1);
                }
                else if (this.Area() == p.Area())
                {
                    return(0);
                }
                else
                {
                    return(1);
                }
            }
        void TestAreaFiguraGenerico(int figuraId, double resultEsperado, params int[] args)
        {
            const int DECIMALES = 2;

            Figura figura          = new Figura(figuraId);
            double resultCalculado = figura.Area(args);

            Assert.IsTrue(Math.Round(resultEsperado, DECIMALES) - Math.Round(resultCalculado, DECIMALES) == 0);
        }