Ejemplo n.º 1
0
        public void FindHypotenuseValidateInputs()
        {
            var error = false;

            try
            {
                // Make sure side 1 is valid
                Pythagorean.FindHypotenuse(0, 2);
                error = true;
            }
            catch
            {
                // ignored
            }

            try
            {
                // Make sure side 2 is valid
                Pythagorean.FindHypotenuse(2, 0);
                error = true;
            }
            catch
            {
                // ignored
            }

            Assert.IsFalse(error, "We should have thrown errors above");
        }
Ejemplo n.º 2
0
        public void FindHypotenuse()
        {
            var hypotenuse = Pythagorean.FindHypotenuse(3, 4);

            // Using pythagorean theorem, this hypotenuse is 5
            Assert.AreEqual(5, hypotenuse);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor with a <paramref name="rightTriangle"/>.
 /// </summary>
 /// <param name="rightTriangle">the right triangle.</param>
 public Triangle(RightTriangle rightTriangle)
 {
     _sideA  = rightTriangle.Length;
     _sideB  = rightTriangle.Height;
     _sideC  = Pythagorean.FindHypotenuse(_sideA, _sideB);
     _angleC = 90;
     _angleB = Math.Atan(_sideB / _sideA);
     _angleA = _angleB - 90;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructor with a <paramref name="length"/> and <paramref name="height"/>.
 /// </summary>
 /// <param name="length">The length.</param>
 /// <param name="height">The height.</param>
 public Triangle(double length, double height)
 {
     _sideA  = length;
     _sideB  = height;
     _sideC  = Pythagorean.FindHypotenuse(_sideA, _sideB);
     _angleC = 90;
     _angleB = Math.Atan(height / length);
     _angleA = _angleB - 90;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructor with a <paramref name="length"/> and <paramref name="height"/>.
        /// </summary>
        /// <param name="length">The length.</param>
        /// <param name="height">The height.</param>
        public RightTriangle(double length, double height)
        {
            _length = length < 0 ? 0 : length;
            _height = height < 0 ? 0 : height;

            if (_length > 0 && _height > 0)
            {
                Hypotenuse = Pythagorean.FindHypotenuse(_length, _height);
            }
        }