예제 #1
0
        public void TestException() // make sure our exceptions work
        {
            try
            {
                bool x = Trigonometry.isPythagoreanTriple(Int32.MaxValue, Int32.MaxValue - 1, Int32.MaxValue - 2);

                // DllNotFoundException just used as a placeholder for something that is not ArgumentException
                throw new DllNotFoundException("Did not throw ArgumentException");
            }
            catch (ArgumentException)
            {
                TestContext.WriteLine("ArgumentException block."); // The arguments failed and ArgumentException was thrown
                Assert.IsTrue(true);
            }
            catch (DllNotFoundException)
            {
                TestContext.WriteLine("DllNotFoundException block"); // The arguments did not fail
                Assert.Fail();
            }
            catch (Exception ex) // The arguments failed, but a different exception was thrown
            {
                TestContext.WriteLine(ex.ToString() + "\r\n\r\n" + ex.Message);
                Assert.Fail();
            }
        }
예제 #2
0
        /// <summary>
        /// Converts an array into 3 ints, and then checks to see if they are equal.
        /// </summary>
        /// <param name="sides">Array of sides to check</param>
        /// <param name="arg">true for Assert.AreEqual, false for Assert.ArNotEqual</param>
        public void ArrToSides(int[] sides, bool arg)
        {
            if (sides.Count() != 3)
            {
                Assert.Fail();                     // This method is just for testing that the exact same numbers will pass in both methods.
            }
            int a = sides[0];
            int b = sides[1];
            int c = sides[2];

            try
            {
                if (arg)
                {
                    Assert.AreEqual(Trigonometry.isPythagoreanTriple(a, b, c), Trigonometry.isPythagoreanTriple(sides));
                }
                else
                {
                    Assert.AreNotEqual(Trigonometry.isPythagoreanTriple(a, b, c), Trigonometry.isPythagoreanTriple(sides));
                }
            }
            catch
            {
                TestContext.WriteLine(String.Format("ArrToSidesCheck: Params = {0} - {1} - {2} - Arg: " + arg.ToString(), a, b, c));
                TestContext.WriteLine(String.Format("ArrToSidesCheck: Params = Count: {0} - Max: {1} - Min: {2} - Arg: " + arg.ToString(), sides.Count(), sides.Max(), sides.Min()));
                Assert.Fail();
            }
        }
예제 #3
0
 /// <summary>
 /// Asserts whether a triple is valid or not. (Array)
 /// </summary>
 /// <param name="sides">Array of sides to check</param>
 /// <param name="arg">true for Assert.IsTrue, false for Assert.IsFalse</param>
 public void ArrCheck(int[] sides, bool arg)
 {
     try
     {
         if (arg)
         {
             Assert.IsTrue(Trigonometry.isPythagoreanTriple(sides));
         }
         else
         {
             Assert.IsFalse(Trigonometry.isPythagoreanTriple(sides));
         }
     }
     catch
     {
         TestContext.WriteLine(String.Format("ArrCheck: Params = Count: {0} - Max: {1} - Min: {2} - Arg: " + arg.ToString(), sides.Count(), sides.Max(), sides.Min()));
         Assert.Fail();
     }
 }
예제 #4
0
 /// <summary>
 /// Asserts whether a triple is valid or not. (Sides)
 /// </summary>
 /// <param name="a">One side of the triangle</param>
 /// <param name="b">One side of the triangle</param>
 /// <param name="c">One side of the triangle</param>
 /// <param name="arg">true for Assert.IsTrue, false for Assert.IsFalse</param>
 public void SidesCheck(int a, int b, int c, bool arg)
 {
     try
     {
         if (arg)
         {
             Assert.IsTrue(Trigonometry.isPythagoreanTriple(a, b, c));
         }
         else
         {
             Assert.IsFalse(Trigonometry.isPythagoreanTriple(a, b, c));
         }
     }
     catch
     {
         TestContext.WriteLine(String.Format("SidesCheck: Params = {0} - {1} - {2} - Arg: " + arg.ToString(), a, b, c));
         Assert.Fail();
     }
 }
예제 #5
0
 /// <summary>
 /// Compares results of the Sides method against the Array method.
 /// </summary>
 /// <param name="a">One side of the triangle</param>
 /// <param name="b">One side of the triangle</param>
 /// <param name="c">One side of the triangle</param>
 /// <param name="sides">Array of sides to check</param>
 /// <param name="arg">true for Assert.AreEqual, false for Assert.ArNotEqual</param>
 public void SidesVsArr(int a, int b, int c, int[] sides, bool arg)
 {
     try
     {
         if (arg)
         {
             Assert.AreEqual(Trigonometry.isPythagoreanTriple(a, b, c), Trigonometry.isPythagoreanTriple(sides));
         }
         else
         {
             Assert.AreNotEqual(Trigonometry.isPythagoreanTriple(a, b, c), Trigonometry.isPythagoreanTriple(sides));
         }
     }
     catch
     {
         TestContext.WriteLine(String.Format("SidesVsArrCheck: Params = {0} - {1} - {2} - Arg: " + arg.ToString(), a, b, c));
         TestContext.WriteLine(String.Format("SidesVsArrCheck: Params = Count: {0} - Max: {1} - Min: {2} - Arg: " + arg.ToString(), sides.Count(), sides.Max(), sides.Min()));
         Assert.Fail();
     }
 }