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."); } } }
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."); } } }
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."); } } }
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_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."); } } }