예제 #1
0
        public void test_Covariance_null_lists_throws_MathError()
        {
            /*If either of Covariance parameter lists are null, MathError should be thrown
             * with error "Parameter list cannot be a null item"*/

            MathError err = Assert.Throws <MathError>(() => Variance.Covariance(testList, null));

            Assert.AreEqual("Parameter list cannot be a null item", err.error);
        }
예제 #2
0
        public void test_BetaEstimate_null_list_throws_MathError()
        {
            /*If either of parameter lists are null, MathError should be thrown
             * with error "Parameter list cannot be a null item"*/

            MathError err = Assert.Throws <MathError>(() => Regression.BetaEstimate(testList, null));

            Assert.AreEqual("Parameter list cannot be a null item", err.error);
        }
예제 #3
0
        public void test_BetaEstimate_different_Counts()
        {
            /*MathError with error message "Variable lists not the same length" should be thrown.
             * Since only one list is of length 0 this should produce different lengths error */
            List <double> list1 = new List <double>();
            MathError     err   = Assert.Throws <MathError>(() => Regression.BetaEstimate(testList, list1));

            Assert.AreEqual("Variable lists not the same length", err.error);
        }
예제 #4
0
        public double Divide(double n1, double n2)
        {
            if (n2 == 0)
            {
                MathError error = new MathError("Divide", "Divide By Zero Exception");
                throw new FaultException <MathError>(error, new FaultReason("Parameters passed are not valid"));
            }
            var result = n1 / n2;

            return(result);
        }
예제 #5
0
        public void test_Covariance_different_Counts_throw_MathError()
        {
            /*MathError with error message "Variable lists not the same length" should be thrown.*/
            List <double> list1 = new List <double>();

            list1.Add(2.2);

            MathError err = Assert.Throws <MathError>(() => Variance.Covariance(testList, list1));

            Assert.AreEqual("Variable lists not the same length", err.error);
        }
 public double Divide(double x, double y)
 {
     if (y == 0)
     {
         MathError error = new MathError("Divide", "Divided by zero");
         throw new FaultException <MathError>(error,
                                              new FaultReason("Parameters passed are not valid"),
                                              new FaultCode("sender"));
     }
     return(x / y);
 }
예제 #7
0
        public void test_Covariance_0_Count_lists_throws_MathError()
        {
            /*If both list are of 0 length, MathError should be thrown with error "Parameter lists have 0 items"*/
            List <double> list1 = new List <double>();
            List <double> list2 = new List <double>();
            MathError     err   = Assert.Throws <MathError>(() => Variance.Covariance(list1, list2));

            Assert.AreEqual("Parameter lists have 0 items", err.error);

            list1 = null;
            list2 = null;
        }
예제 #8
0
        static void Main(string[] args)
        {
            ChannelFactory <ICalculator> calculatorFactory = new ChannelFactory <ICalculator>("defaultEndpoint");
            ICalculator calculator = calculatorFactory.CreateChannel();

            try
            {
                Console.WriteLine("Try to invoke Divide method");
                Console.WriteLine("x / y = {2} when x = {0} and y = {1}", 2, 0, calculator.Divide(2, 0));
            }
            catch (FaultException <MathError> ex)
            {
                MathError error = ex.Detail;
                Console.WriteLine("An Fault is thrown.\n\tFault code:{0}\n\tFault Reason:{1}\n\tOperation:{2}\n\tMessage:{3}", ex.Code, ex.Reason, error.Operation, error.ErrorMessage);
            }
            catch (Exception ex)
            {
                Console.WriteLine("An Exception is thrown.\n\tException Type:{0}\n\tError Message:{1}", ex.GetType(), ex.Message);
            }
            Console.Read();
        }