Пример #1
0
        private void BtnResultClicked(object sender, RoutedEventArgs e)
        {
            LblResult.Content = string.Empty;
            int sideA, sideB, sideC;
            var aIsInteger = int.TryParse(TxtA.Text, out sideA) && sideA > 0;
            var bIsInteger = int.TryParse(TxtB.Text, out sideB) && sideB > 0;
            var cIsInteger = int.TryParse(TxtC.Text, out sideC) && sideC > 0;

            if (aIsInteger && bIsInteger && cIsInteger)
            {
                LblResult.Content = TriangleLogic.GetTriangleType(sideA, sideB, sideC).ToString();
            }
            else
            {
                var message = string.Empty;
                if (!aIsInteger)
                {
                    TxtA.Text = string.Empty;
                    message  += string.Format(ErrorInput, "A");
                    TxtA.Text = string.Empty;
                }
                if (!bIsInteger)
                {
                    TxtB.Text = string.Empty;
                    if (!string.IsNullOrWhiteSpace(message))
                    {
                        message += "\n";
                    }
                    message  += string.Format(ErrorInput, "B");
                    TxtB.Text = string.Empty;
                }
                if (!cIsInteger)
                {
                    TxtC.Text = string.Empty;
                    if (!string.IsNullOrWhiteSpace(message))
                    {
                        message += "\n";
                    }
                    message  += string.Format(ErrorInput, "C");
                    TxtC.Text = string.Empty;
                }

                MessageBox.Show(Application.Current.MainWindow, message);
            }
        }
Пример #2
0
 public void TestScalene()
 {
     Assert.AreEqual(TriangleLogic.GetTriangleType(5, 7, 8), TriangleType.Scalene);
 }
Пример #3
0
 public void TestEquilateral()
 {
     Assert.AreEqual(TriangleLogic.GetTriangleType(5, 5, 5), TriangleType.Equilateral);
 }
Пример #4
0
 public void TestIsosceles()
 {
     Assert.AreEqual(TriangleLogic.GetTriangleType(5, 2, 5), TriangleType.Isosceles);
 }
Пример #5
0
 public void TestNoTriangle()
 {
     Assert.AreEqual(TriangleLogic.GetTriangleType(5, 2, 1), TriangleType.NoTriangle);
 }