Example #1
0
        public static void DbFunctions_POWER()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

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

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

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

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

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

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

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

                double input = rnd.NextDouble();
                double pow   = rnd.NextDouble();

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

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

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

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

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

                long input = DateTime.Now.Ticks;
                long pow   = DateTime.Now.Ticks;

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

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

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

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

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

                int  input = rnd.Next(Int32.MinValue, Int32.MaxValue);
                long pow   = DateTime.Now.Ticks;

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

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

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

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

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

                int    input = rnd.Next();
                double pow   = rnd.NextDouble();

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

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

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

                if (expected != output)
                {
                    throw new Exception("DbFunctions.POWER(Int32, Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Example #2
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.");
                }
            }
        }
Example #3
0
        public static void DbFunctions_RADIANS()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            //Double.
            {
                Console.WriteLine("Testing DbFunctions_RADIANS(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.RADIANS(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = ((double)input * Math.PI) / 180d;

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

            {
                Console.WriteLine("Testing DbFunctions_RADIANS(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.RADIANS(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = ((double)input * Math.PI) / 180d;

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

            {
                Console.WriteLine("Testing DbFunctions_RADIANS(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.RADIANS(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = ((double)input * Math.PI) / 180d;

                if (expected != output)
                {
                    throw new Exception("DbFunctions_RADIANS(Long) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Example #4
0
        public static void DbFunctions_NOTEQUAL()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            {
                Console.WriteLine("Testing DbFunctions.EQUAL(char(n), char(n))...");

                mstring s1 = Utils.GenString(rnd.Next(1, 200));
                mstring s2 = Utils.GenString(rnd.Next(1, 200));

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

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

                int expected = (s1.ToString().CompareTo(s2.ToString()) != 0 ? 1 : 0);

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

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

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

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

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

                int expected = (x != y ? 1 : 0);

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

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

                double x = rnd.NextDouble();
                double y = rnd.NextDouble();

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

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

                int expected = (x != y ? 1 : 0);

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

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

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

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

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

                int expected = (x != y ? 1 : 0);

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

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

                double x = rnd.NextDouble();
                int    y = rnd.Next();

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

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

                int expected = (x != y ? 1 : 0);

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

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

                double x = rnd.NextDouble();
                long   y = DateTime.Now.Ticks;

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

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

                int expected = (x != y ? 1 : 0);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.NOTEQUAL(Double, Long) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Example #5
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.");
                }
            }
        }
Example #6
0
        public static void DbAggregators_SUM()
        {
            DbFunctionTools tools    = new DbFunctionTools();
            Random          rnd      = new Random();
            const int       rowcount = 20;

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

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

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

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

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                int sum = 0;

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

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

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                long sum = 0;

                for (int i = 0; i < fargs.Length; i++)
                {
                    long input = DateTime.Now.Ticks;
                    if (input % 2 == 0)
                    {
                        input = input * -1;
                    }
                    sum += input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.SUM(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);
                long      expected  = sum;
                if (expected != output)
                {
                    throw new Exception("DbAggregators_SUM(Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Example #7
0
        public static void DbFunctions_IIF()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            // int
            {
                Console.WriteLine("Testing DbFunctions.IIF(1, 'First', 'Second')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(1));
                args.Add(tools.AllocValue(mstring.Prepare("First")));
                args.Add(tools.AllocValue(mstring.Prepare("Second")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.IIF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                mstring expected = mstring.Prepare("First");

                if (expected != output)
                {
                    throw new Exception("DbFunctions.IIF(1, 'First', 'Second') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.IIF(0, 'First', 'Second')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(0));
                args.Add(tools.AllocValue(mstring.Prepare("First")));
                args.Add(tools.AllocValue(mstring.Prepare("Second")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.IIF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                mstring expected = mstring.Prepare("Second");

                if (expected != output)
                {
                    throw new Exception("DbFunctions.IIF(0, 'First', 'Second') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.IIF(42, 'First', 'Second')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(42));
                args.Add(tools.AllocValue(mstring.Prepare("First")));
                args.Add(tools.AllocValue(mstring.Prepare("Second")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.IIF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                mstring expected = mstring.Prepare("First");

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

            // NULL
            {
                Console.WriteLine("Testing DbFunctions.IIF(NULL, 'First', 'Second')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocNullValue());
                args.Add(tools.AllocValue(mstring.Prepare("First")));
                args.Add(tools.AllocValue(mstring.Prepare("Second")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.IIF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                mstring expected = mstring.Prepare("Second");

                if (expected != output)
                {
                    throw new Exception("DbFunctions.IIF(NULL, 'First', 'Second') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Example #8
0
        public static void DbFunctions_RPAD()
        {
            DbFunctionTools tools = new DbFunctionTools();

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

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("hello")));
                int len = 11;
                args.Add(tools.AllocValue(len));
                args.Add(tools.AllocValue(mstring.Prepare("xy")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.RPAD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                mstring expected = mstring.Prepare("helloxyxyxy");

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

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

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("hello")));
                int len = 10;
                args.Add(tools.AllocValue(len));
                args.Add(tools.AllocValue(mstring.Prepare("xy")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.RPAD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                mstring expected = mstring.Prepare("helloxyxyx");

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

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

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("hello")));
                int len = 5;
                args.Add(tools.AllocValue(len));
                args.Add(tools.AllocValue(mstring.Prepare("xy")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.RPAD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                mstring expected = mstring.Prepare("hello");

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

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("hello")));
                int len = 3;
                args.Add(tools.AllocValue(len));
                args.Add(tools.AllocValue(mstring.Prepare("xy")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.RPAD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                mstring expected = mstring.Prepare("hel");

                if (expected != output)
                {
                    throw new Exception("DbFunctions.RPAD(String,Int32, String) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Example #9
0
        public static void DbAggregators_COUNTDISTINCT()
        {
            DbFunctionTools tools    = new DbFunctionTools();
            Random          rnd      = new Random();
            const int       rowcount = 20;

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

                DbFunctionArguments[]      fargs = new DbFunctionArguments[rowcount];
                Dictionary <double, short> dict  = new Dictionary <double, short>();
                double repeat = 0;
                for (int i = 0; i < fargs.Length; i++)
                {
                    double input = rnd.NextDouble();
                    if (input < 0.5)
                    {
                        input = input * -1d;
                    }
                    if (i == 0)
                    {
                        repeat = input;
                    }

                    if (i % 3 == 1)
                    {
                        input = repeat;
                    }

                    dict[input] = 0;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.COUNTDISTINCT(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                int       output    = (int)tools.GetLong(bs);
                int       expected  = dict.Count;
                if (expected != output)
                {
                    throw new Exception("DbAggregators_COUNTDISTINCT(Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

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

                DbFunctionArguments[]   fargs = new DbFunctionArguments[rowcount];
                Dictionary <int, short> dict  = new Dictionary <int, short>();
                int repeat = 0;
                for (int i = 0; i < fargs.Length; i++)
                {
                    int input = rnd.Next(Int32.MinValue, Int32.MaxValue);
                    if (i == 0)
                    {
                        repeat = input;
                    }

                    if (i % 3 == 1)
                    {
                        input = repeat;
                    }
                    dict[input] = 0;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.COUNTDISTINCT(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                int       output    = (int)tools.GetLong(bs);
                int       expected  = dict.Count;
                if (expected != output)
                {
                    throw new Exception("DbAggregators_COUNTDISTINCT(Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

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

                DbFunctionArguments[]    fargs = new DbFunctionArguments[rowcount];
                Dictionary <long, short> dict  = new Dictionary <long, short>();
                long repeat = 0;
                for (int i = 0; i < fargs.Length; i++)
                {
                    long input = DateTime.Now.Ticks;
                    if (input % 2 == 0)
                    {
                        input = input * -1;
                    }
                    if (i == 0)
                    {
                        repeat = input;
                    }

                    if (i % 3 == 1)
                    {
                        input = repeat;
                    }
                    dict[input] = 0;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.COUNTDISTINCT(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                int       output    = (int)tools.GetLong(bs);
                int       expected  = dict.Count;
                if (expected != output)
                {
                    throw new Exception("DbAggregators_COUNTDISTINCT(Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

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

                DbFunctionArguments[]      fargs = new DbFunctionArguments[rowcount];
                Dictionary <string, short> dict  = new Dictionary <string, short>();
                mstring repeat = mstring.Prepare();
                for (int i = 0; i < fargs.Length; i++)
                {
                    int     strlen = rnd.Next(1, 100);
                    mstring input  = Utils.GenString(strlen);
                    if (i == 0)
                    {
                        repeat = input;
                    }

                    if (i % 3 == 1)
                    {
                        input = repeat;
                    }
                    dict[input.ToString()] = 0;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.COUNTDISTINCT(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                int       output    = (int)tools.GetLong(bs);
                int       expected  = dict.Count;
                if (expected != output)
                {
                    throw new Exception("DbAggregators_COUNTDISTINCT(char(n)) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }