Esempio n. 1
0
        public static void DbFunctions_RAND()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();


            {
                Console.WriteLine("Testing DbFunctions.RAND(Int32)...");

                int input = rnd.Next(Int32.MinValue, Int32.MaxValue);

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.RAND(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                Console.WriteLine("Expected results received: {0}", output);
            }

            {
                Console.WriteLine("Testing DbFunctions.RAND()...");

                List <DbValue>      args  = new List <DbValue>();
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.RAND(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                Console.WriteLine("Expected results received: {0}", output);
            }
        }
Esempio n. 2
0
        public static void DbFunctions_ROUND()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            //Double.
            {
                Console.WriteLine("Testing DbFunctions.ROUND(Double, Int32)...");

                double input = rnd.NextDouble();

                if (input < 0.5)
                {
                    input = input * -1d;
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input));
                args.Add(tools.AllocValue(3));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ROUND(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = Math.Round(input, 3);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ROUND(Double, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 3
0
        public static void DbFunctions_PI()
        {
            DbFunctionTools tools = new DbFunctionTools();
            {
                Console.WriteLine("Testing DbFunctions.PI()...");

                DbFunctionArguments fargs = new DbFunctionArguments();

                DbValue   valOutput = DbFunctions.PI(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = Math.PI;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.PI() has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 4
0
        public static void DbFunctions_SQUARE()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            //Double.
            {
                Console.WriteLine("Testing DbFunctions.SQUARE(Double)...");

                double input = rnd.NextDouble();

                if (input < 0.5)
                {
                    input = input * -1d;
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SQUARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = Math.Pow((double)input, 2);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SQUARE(Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.SQUARE(Int32)...");

                int input = rnd.Next(Int32.MinValue, Int32.MaxValue);

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SQUARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = Math.Pow((double)input, 2);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SQUARE(Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.SQUARE(Long)...");

                long input = DateTime.Now.Ticks;

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SQUARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = Math.Pow((double)input, 2);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SQUARE(Long) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 5
0
        public static void DbAggregators_LAST()
        {
            DbFunctionTools tools    = new DbFunctionTools();
            Random          rnd      = new Random();
            const int       rowcount = 20;

            //Double.
            {
                Console.WriteLine("Testing DbAggregators_LAST(Double)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                double expected             = 0;

                for (int i = 0; i < fargs.Length; i++)
                {
                    double input = rnd.NextDouble();
                    if (input < 0.5)
                    {
                        input = input * -1d;
                    }
                    if (i == fargs.Length - 1)
                    {
                        expected = input;
                    }

                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.LAST(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                if (expected != output)
                {
                    throw new Exception("DbAggregators_LAST(Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_LAST(Int32)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                int expected = Int32.MaxValue;

                for (int i = 0; i < fargs.Length; i++)
                {
                    int input = rnd.Next(Int32.MinValue, Int32.MaxValue);
                    if (i == fargs.Length - 1)
                    {
                        expected = input;
                    }
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.LAST(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                if (expected != output)
                {
                    throw new Exception("DbAggregators_LAST(Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_LAST(Int64)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                long expected = Int64.MaxValue;

                for (int i = 0; i < fargs.Length; i++)
                {
                    long input = DateTime.Now.Ticks;
                    if (input % 2 == 0)
                    {
                        input = input * -1;
                    }
                    if (i == fargs.Length - 1)
                    {
                        expected = input;
                    }
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.LAST(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                if (expected != output)
                {
                    throw new Exception("DbAggregators_LAST(Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_LAST(char(n))...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                string expected             = null;

                for (int i = 0; i < fargs.Length; i++)
                {
                    int     strlen = rnd.Next(1, 100);
                    mstring input  = Utils.GenString(strlen);
                    if (i == fargs.Length - 1)
                    {
                        expected = input.ToString();
                    }
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.LAST(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                if (expected != output.ToString())
                {
                    throw new Exception("DbAggregators_LAST(char(n)) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 6
0
        public static void DbAggregators_VAR_SAMP()
        {
            DbFunctionTools tools    = new DbFunctionTools();
            Random          rnd      = new Random();
            const int       rowcount = 20;

            double[] values = new double[rowcount];

            //Double.
            {
                Console.WriteLine("Testing DbAggregators_VAR_SAMP(Double)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                for (int i = 0; i < fargs.Length; i++)
                {
                    double input = rnd.NextDouble();
                    if (input < 0.5)
                    {
                        input = input * -1d;
                    }
                    values[i] = input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.VAR_SAMP(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);
                double    expected  = var(values, true);
                if (expected != output)
                {
                    throw new Exception("DbAggregators_VAR_SAMP(Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_VAR_SAMP(Int32)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                for (int i = 0; i < fargs.Length; i++)
                {
                    int input = rnd.Next(Int32.MinValue, Int32.MaxValue);
                    values[i] = (double)input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.VAR_SAMP(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);
                double    expected  = var(values, true);
                if (expected != output)
                {
                    throw new Exception("DbAggregators_VAR_SAMP(Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_VAR_SAMP(Int64)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                for (int i = 0; i < fargs.Length; i++)
                {
                    long input = DateTime.Now.Ticks;
                    if (input % 2 == 0)
                    {
                        input = input * -1;
                    }
                    values[i] = (double)input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.VAR_SAMP(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);
                double    expected  = var(values, true);
                if (expected != output)
                {
                    throw new Exception("DbAggregators_VAR_SAMP(Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 7
0
        public static void DbFunctions_ARITHMETIC()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            //Int32.
            {
                Console.WriteLine("Testing DbFunctions.ADD(Int32, Int32)...");

                int            input1 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                int            input2 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input1 + input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ADD(Int32, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.SUB(Int32, Int32)...");

                int            input1 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                int            input2 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SUB(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input1 - input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SUB(Int32, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.MUL(Int32, Int32)...");

                int            input1 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                int            input2 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MUL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input1 * input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MUL(Int32, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.DIV(Int32, Int32)...");

                int            input1 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                int            input2 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DIV(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input1 / input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DIV(Int32, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            // Int32, Int64
            {
                Console.WriteLine("Testing DbFunctions.ADD(Int32, Int64)...");

                int            input1 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                long           input2 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = input1 + input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ADD(Int32, Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            //Int64.
            {
                Console.WriteLine("Testing DbFunctions.ADD(Int64, Int64)...");

                long           input1 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                long           input2 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = input1 + input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ADD(Int64, Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.SUB(Int64, Int64)...");

                long           input1 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                long           input2 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SUB(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = input1 - input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SUB(Int64, Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.MUL(Int64, Int64)...");

                long           input1 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                long           input2 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MUL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = input1 * input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MUL(Int64, Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.DIV(Int64, Int64)...");

                long           input1 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                long           input2 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DIV(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = input1 / input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DIV(Int64, Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            // Int64, Int32
            {
                Console.WriteLine("Testing DbFunctions.SUB(Int64, Int32)...");

                long           input1 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                int            input2 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SUB(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = input1 - input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SUB(Int64, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            //double.
            {
                Console.WriteLine("Testing DbFunctions.ADD(double, double)...");

                double         input1 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                double         input2 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = input1 + input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ADD(double, double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.SUB(double, double)...");

                double         input1 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                double         input2 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SUB(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = input1 - input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SUB(double, double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.MUL(double, double)...");

                double         input1 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                double         input2 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MUL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = input1 * input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MUL(double, double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.DIV(double, double)...");

                double         input1 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                double         input2 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DIV(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = input1 / input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DIV(double, double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            // double, Int32
            {
                Console.WriteLine("Testing DbFunctions.MUL(double, Int32)...");

                double         input1 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                int            input2 = rnd.Next(int.MinValue, int.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MUL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = input1 * input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MUL(double, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            // Int64, double
            {
                Console.WriteLine("Testing DbFunctions.DIV(Int64, double)...");

                long           input1 = rnd.Next(int.MinValue, int.MaxValue) * rnd.Next();
                double         input2 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DIV(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = input1 / input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DIV(Int64, double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 8
0
        public static void DbAggregators_BIT_AND()
        {
            DbFunctionTools tools    = new DbFunctionTools();
            Random          rnd      = new Random();
            const int       rowcount = 20;

            //Double.
            {
                Console.WriteLine("Testing DbAggregators_BIT_AND(Double)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                double[] values             = new double[rowcount];

                for (int i = 0; i < fargs.Length; i++)
                {
                    double input = rnd.NextDouble();
                    if (input < 0.5)
                    {
                        input = input * -1d;
                    }
                    values[i] = input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.BIT_AND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);
                byte[]    expected  = bitop(values, 1);

                if (!compareBytes(expected, bs))
                {
                    throw new Exception("DbAggregators_BIT_AND(Double) has failed.");
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_BIT_AND(Int32)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                int[] values = new int[rowcount];

                for (int i = 0; i < fargs.Length; i++)
                {
                    int input = rnd.Next(Int32.MinValue, Int32.MaxValue);
                    values[i] = input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.BIT_AND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);
                byte[]    expected  = bitop(values, 1);
                if (!compareBytes(expected, bs))
                {
                    throw new Exception("DbAggregators_BIT_AND(Int32) has failed.");
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_BIT_AND(Int64)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                long[] values = new long[rowcount];

                for (int i = 0; i < fargs.Length; i++)
                {
                    long input = DateTime.Now.Ticks;
                    if (input % 2 == 0)
                    {
                        input = input * -1;
                    }
                    values[i] = input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.BIT_AND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);
                byte[]    expected  = bitop(values, 1);
                if (!compareBytes(expected, bs))
                {
                    throw new Exception("DbAggregators_BIT_AND(Int64) has failed.");
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_BIT_AND(char(n))...");

                DbFunctionArguments[] fargs  = new DbFunctionArguments[rowcount];
                mstring[]             values = new mstring[rowcount];

                for (int i = 0; i < fargs.Length; i++)
                {
                    int     strlen = 30;
                    mstring input  = Utils.GenString(strlen);
                    values[i] = input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.BIT_AND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);
                byte[]    expected  = bitop(values, 1);
                if (!compareBytes(expected, bs))
                {
                    throw new Exception("DbAggregators_BIT_AND(char(n)) has failed.");
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
        public static void DbAggregators_CHOOSERND()
        {
            DbFunctionTools tools    = new DbFunctionTools();
            Random          rnd      = new Random();
            const int       rowcount = 20;

            //Double.
            {
                Console.WriteLine("Testing DbAggregators_CHOOSERND(Double)...");

                DbFunctionArguments[]    fargs = new DbFunctionArguments[rowcount];
                Dictionary <double, int> dict  = new Dictionary <double, int>();

                for (int i = 0; i < fargs.Length; i++)
                {
                    double input = rnd.NextDouble();
                    if (input < 0.5)
                    {
                        input = input * -1d;
                    }
                    dict[input] = 1;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.CHOOSERND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                if (!dict.ContainsKey(output))
                {
                    throw new Exception("DbAggregators_CHOOSERND(Double) has failed.  Value not found: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_CHOOSERND(Int32)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                Dictionary <int, int> dict  = new Dictionary <int, int>();

                for (int i = 0; i < fargs.Length; i++)
                {
                    int input = rnd.Next(Int32.MinValue, Int32.MaxValue);
                    dict[input] = 1;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.CHOOSERND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                if (!dict.ContainsKey(output))
                {
                    throw new Exception("DbAggregators_CHOOSERND(Int32) has failed.  Value not found: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_CHOOSERND(Int64)...");

                DbFunctionArguments[]  fargs = new DbFunctionArguments[rowcount];
                Dictionary <long, int> dict  = new Dictionary <long, int>();

                for (int i = 0; i < fargs.Length; i++)
                {
                    long input = DateTime.Now.Ticks;
                    if (input % 2 == 0)
                    {
                        input = input * -1;
                    }
                    dict[input] = 1;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.CHOOSERND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                if (!dict.ContainsKey(output))
                {
                    throw new Exception("DbAggregators_CHOOSERND(Int64) has failed.  Value not found: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_CHOOSERND(char(n))...");

                DbFunctionArguments[]    fargs = new DbFunctionArguments[rowcount];
                Dictionary <string, int> dict  = new Dictionary <string, int>();

                for (int i = 0; i < fargs.Length; i++)
                {
                    int     strlen = rnd.Next(1, 100);
                    mstring input  = Utils.GenString(strlen);
                    dict[input.ToString()] = 1;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.CHOOSERND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                if (!dict.ContainsKey(output.ToString()))
                {
                    throw new Exception("DbAggregators_CHOOSERND(char(n)) has failed.  Value not found: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 10
0
        public static void DbFunctions_MOD()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            //Double.
            {
                Console.WriteLine("Testing DbFunctions.MOD(Double, Double)...");

                double input0 = rnd.NextDouble();
                double input1 = rnd.NextDouble();

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input0));
                args.Add(tools.AllocValue(input1));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MOD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = input0 % input1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MOD(Double, Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.MOD(Int32, Int32)...");

                int input0 = rnd.Next();
                int input1 = rnd.Next();

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input0));
                args.Add(tools.AllocValue(input1));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MOD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input0 % input1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MOD(Int32, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.MOD(Long, Long)...");

                long input0 = DateTime.Now.Ticks;
                long input1 = DateTime.Now.Ticks;

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input0));
                args.Add(tools.AllocValue(input1));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MOD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = input0 % input1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MOD(Long, Long) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.MOD(Int32, Double)...");

                int    input0 = rnd.Next();
                double input1 = rnd.NextDouble();

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input0));
                args.Add(tools.AllocValue(input1));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MOD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = (double)input0 % input1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MOD(Int32, Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.MOD(Int32, Long)...");

                int  input0 = rnd.Next();
                long input1 = DateTime.Now.Ticks;

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input0));
                args.Add(tools.AllocValue(input1));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MOD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = (long)input0 % input1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MOD(Int32, Long) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 11
0
        public static void DbFunctions_MONTHS_BETWEEN()
        {
            DbFunctionTools tools = new DbFunctionTools();

            {
                Console.WriteLine("Testing DbFunctions.MONTHS_BETWEEN...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(DateTime.Parse("1/31/2000 10:00:00 AM")));
                args.Add(tools.AllocValue(DateTime.Parse("1/3/2000 10:00:00 AM")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MONTHS_BETWEEN(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = (double)(31 - 3) / (double)31;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MONTHS_BETWEEN has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.MONTHS_BETWEEN...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(DateTime.Parse("1/31/2000 10:00:00 AM")));
                args.Add(tools.AllocValue(DateTime.Parse("4/30/1999 10:00:00 AM")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MONTHS_BETWEEN(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = 9;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MONTHS_BETWEEN has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.MONTHS_BETWEEN...");

                List <DbValue> args = new List <DbValue>();
                DateTime       d0   = DateTime.Parse("1/31/2000 10:00:00 AM");
                DateTime       d1   = DateTime.Parse("4/1/1999 10:00:00 AM");
                args.Add(tools.AllocValue(d0));
                args.Add(tools.AllocValue(d1));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MONTHS_BETWEEN(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                TimeSpan sp       = d0 - d1;
                double   expected = sp.TotalDays / 31d;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MONTHS_BETWEEN has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 12
0
        public static void DbFunctions_DATEDIFF()
        {
            DbFunctionTools tools = new DbFunctionTools();

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(year)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("year");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2010, 12, 2, 10, 0, 0);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2000, 9, 14, 12, 0, 0);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);
                double    expected  = -10;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(year) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(quarter)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("qq");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 0, 0);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 30, 12, 0, 0);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);
                double    expected  = 8;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(quarter) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(month)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("month");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 0, 0);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 15, 12, 0, 0);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);
                double    expected  = 25;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(month) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(day)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("d");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 0, 0);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 20, 12, 0, 0);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = 0;
                {
                    DateTime xstartdate = new DateTime(2000, 7, 1);
                    DateTime xenddate   = new DateTime(2002, 8, 20);
                    TimeSpan sp         = xenddate - xstartdate;
                    expected = sp.TotalDays;
                }

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(day) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(week)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("week");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 0, 0);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 20, 12, 0, 0);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = 0;
                {
                    DateTime xstartdate = new DateTime(2000, 7, 1);
                    DateTime xenddate   = new DateTime(2002, 8, 20);
                    TimeSpan sp         = xenddate - xstartdate;
                    expected = (int)sp.TotalDays / 7;
                }

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(week) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(hour)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("hh");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 30, 1);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 20, 12, 20, 3);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = 0;
                {
                    DateTime xstartdate = new DateTime(2000, 7, 1, 10, 0, 0);
                    DateTime xenddate   = new DateTime(2002, 8, 20, 12, 0, 0);
                    TimeSpan sp         = xenddate - xstartdate;
                    expected = sp.TotalHours;
                }

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(hour) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(minute)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("minute");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 30, 1);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 20, 12, 20, 3);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = 0;
                {
                    DateTime xstartdate = new DateTime(2000, 7, 1, 10, 30, 0);
                    DateTime xenddate   = new DateTime(2002, 8, 20, 12, 20, 0);
                    TimeSpan sp         = xenddate - xstartdate;
                    expected = sp.TotalMinutes;
                }

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(minute) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(second)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("ss");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 30, 1);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 20, 12, 20, 3);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = 0;
                {
                    DateTime xstartdate = new DateTime(2000, 7, 1, 10, 30, 1);
                    DateTime xenddate   = new DateTime(2002, 8, 20, 12, 20, 3);
                    TimeSpan sp         = xenddate - xstartdate;
                    expected = sp.TotalSeconds;
                }

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(second) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(millisecond)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("ms");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 30, 1, 2);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 20, 12, 20, 3, 5);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double   expected = 0;
                TimeSpan sp       = enddate - startdate;
                expected = sp.TotalMilliseconds;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(millisecond) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 13
0
        public static void DbFunctions_ATN2()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            //Double.
            {
                Console.WriteLine("Testing DbFunctions.ATN2(Double, Double)...");

                double y = rnd.NextDouble();
                if (y < 0.5)
                {
                    y = y * -1d;
                }
                double x = rnd.NextDouble();
                if (x < 0.5)
                {
                    x = x * -1d;
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(y));
                args.Add(tools.AllocValue(x));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ATN2(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = Math.Atan2(y, x);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ATN2(Double, Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.ATN2(Int32, Int32)...");

                int y = rnd.Next(Int32.MinValue, Int32.MaxValue);
                int x = rnd.Next(Int32.MinValue, Int32.MaxValue);

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(y));
                args.Add(tools.AllocValue(x));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ATN2(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = Math.Atan2((double)y, (double)x);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ATN2(Int32, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.ATN2(Long, Long)...");

                long y = DateTime.Now.Ticks;
                long x = DateTime.Now.Ticks;

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(y));
                args.Add(tools.AllocValue(x));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ATN2(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = Math.Atan2((double)y, (double)x);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ATN2(Long, Long) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }