public static void DbFunctions_CHARINDEX() { DbFunctionTools tools = new DbFunctionTools(); //String,Int32. { Console.WriteLine("Testing DbFunctions.CHARINDEX(char(n), char(n)..."); mstring word = mstring.Prepare("apple"); mstring sentence = mstring.Prepare("Red is apple"); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(word)); args.Add(tools.AllocValue(sentence)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.CHARINDEX(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 7; if (expected != output) { throw new Exception("DbFunctions.CHARINDEX(char(n), char(n) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.CHARINDEX(char(n), char(n), Int32..."); mstring word = mstring.Prepare("apple"); mstring sentence = mstring.Prepare("Red is apple, or more apples."); int startIndex = 8; List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(word)); args.Add(tools.AllocValue(sentence)); args.Add(tools.AllocValue(startIndex)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.CHARINDEX(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 22; if (expected != output) { throw new Exception("DbFunctions.CHARINDEX(char(n), char(n), Int32 has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } }
public static void DbFunctions_INSTR() { DbFunctionTools tools = new DbFunctionTools(); { Console.WriteLine("Testing DbFunctions.SUBSTR(String,String)..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("apple is red"))); args.Add(tools.AllocValue(mstring.Prepare("red"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.INSTR(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 9; if (expected != output) { throw new Exception("DbFunctions.SUBSTR(String,String) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.SUBSTR(String,String, Int32)..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("apple is red"))); args.Add(tools.AllocValue(mstring.Prepare("red"))); int startindex = 2; args.Add(tools.AllocValue(startindex)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.INSTR(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 9; if (expected != output) { throw new Exception("DbFunctions.SUBSTR(String,String, Int32) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } }
public static void DbFunctions_PATINDEX() { DbFunctionTools tools = new DbFunctionTools(); //String,Int32. { Console.WriteLine("Testing DbFunctions.PATINDEX(String, string)..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("%ap_pl[e]%"))); args.Add(tools.AllocValue(mstring.Prepare("red is ap5ple, my favourite."))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.PATINDEX(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 7; if (expected != output) { throw new Exception("DbFunctions.PATINDEX(String) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } }
public static void DbFunctions_LEN() { DbFunctionTools tools = new DbFunctionTools(); //String,Int32. { Console.WriteLine("Testing DbFunctions.LEN(String)..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("hello world"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.LEN(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = mstring.Prepare("hello world").Length; if (expected != output) { throw new Exception("DbFunctions.LEN(String) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } }
public static void DbFunctions_SIGN() { DbFunctionTools tools = new DbFunctionTools(); Random rnd = new Random(); //Double. { Console.WriteLine("Testing DbFunctions.SIGN(Double)..."); double input = rnd.NextDouble(); if (input > 0.5) { input = input * -1; } List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(input)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.SIGN(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = Math.Sign(input); if (expected != output) { throw new Exception("DbFunctions.SIGN(Double) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.SIGN(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.SIGN(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = Math.Sign(input); if (expected != output) { throw new Exception("DbFunctions.SIGN(Int32) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.SIGN(Long)..."); long input = DateTime.Now.Ticks; if (input % 2 == 0) { input = input * -1; } List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(input)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.SIGN(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = Math.Sign(input); if (expected != output) { throw new Exception("DbFunctions.SIGN(Long) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } }
public static void DbFunctions_ABS() { DbFunctionTools tools = new DbFunctionTools(); Random rnd = new Random(); //Int32. { Console.WriteLine("Testing DbFunctions.ABS(Int32)..."); int input = rnd.Next(Int32.MinValue, Int32.MaxValue); DbValue valInput = tools.AllocValue(input); List <DbValue> args = new List <DbValue>(); args.Add(valInput); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ABS(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = Math.Abs(input); if (expected != output) { throw new Exception("DbFunctions.ABS(Int32) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } //Int64. { Console.WriteLine("Testing DbFunctions.ABS(Int64)..."); long input = DateTime.Now.Ticks - 1; if (input % 2 == 0) { input = input * -1L; } DbValue valInput = tools.AllocValue(input); List <DbValue> args = new List <DbValue>(); args.Add(valInput); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ABS(tools, fargs); ByteSlice bs = valOutput.Eval(); byte[] buf = bs.ToBytes(); long output = Entry.ToInt64(Entry.BytesToULong(buf, 1)); long expected = Math.Abs(input); if (expected != output) { throw new Exception("DbFunctions.ABS(Int64) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } //Double. { Console.WriteLine("Testing DbFunctions.ABS(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.ABS(tools, fargs); ByteSlice bs = valOutput.Eval(); byte[] buf = bs.ToBytes(); double output = Entry.BytesToDouble(buf, 1); double expected = Math.Abs(input); if (expected != output) { throw new Exception("DbFunctions.ABS(Double) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } }
public static void DbFunctions_ISNOTNULL() { DbFunctionTools tools = new DbFunctionTools(); Random rnd = new Random(); { Console.WriteLine("Testing DbFunctions.ISNOTNULL(char(n))..."); { mstring s1 = Utils.GenString(rnd.Next(1, 200)); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(s1)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISNOTNULL(tools, fargs); ByteSlice bs = valOutput.Eval(); bool output = tools.GetInt(bs) != 0; bool expected = !false; if (expected != output) { throw new Exception("DbFunctions.ISNOTNULL(char(n)='" + s1.ToString() + "') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(ByteSlice.Prepare(new byte[] { 1 }), DbTypeID.CHARS)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISNOTNULL(tools, fargs); ByteSlice bs = valOutput.Eval(); bool output = tools.GetInt(bs) != 0; bool expected = !true; if (expected != output) { throw new Exception("DbFunctions.ISNOTNULL(char(n)=NULL) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } } { Console.WriteLine("Testing DbFunctions.ISNOTNULL(Int32)..."); { int x = rnd.Next(Int32.MinValue, Int32.MaxValue); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(x)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISNOTNULL(tools, fargs); ByteSlice bs = valOutput.Eval(); bool output = tools.GetInt(bs) != 0; bool expected = !false; if (expected != output) { throw new Exception("DbFunctions.ISNOTNULL(Int32=" + x.ToString() + ") has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(ByteSlice.Prepare(new byte[] { 1 }), DbTypeID.INT)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISNOTNULL(tools, fargs); ByteSlice bs = valOutput.Eval(); bool output = tools.GetInt(bs) != 0; bool expected = !true; if (expected != output) { throw new Exception("DbFunctions.ISNOTNULL(Int32=NULL) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } } { Console.WriteLine("Testing DbFunctions.ISNOTNULL(Double)..."); { double x = rnd.NextDouble(); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(x)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISNOTNULL(tools, fargs); ByteSlice bs = valOutput.Eval(); bool output = tools.GetInt(bs) != 0; bool expected = !false; if (expected != output) { throw new Exception("DbFunctions.ISNOTNULL(Double=" + x.ToString() + ") has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(ByteSlice.Prepare(new byte[] { 1 }), DbTypeID.DOUBLE)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISNOTNULL(tools, fargs); ByteSlice bs = valOutput.Eval(); bool output = tools.GetInt(bs) != 0; bool expected = !true; if (expected != output) { throw new Exception("DbFunctions.ISNOTNULL(Double=NULL) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } } { Console.WriteLine("Testing DbFunctions.ISNOTNULL(Long)..."); { long x = DateTime.Now.Ticks; List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(x)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISNOTNULL(tools, fargs); ByteSlice bs = valOutput.Eval(); bool output = tools.GetInt(bs) != 0; bool expected = !false; if (expected != output) { throw new Exception("DbFunctions.ISNOTNULL(Long=" + x.ToString() + ") has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(ByteSlice.Prepare(new byte[] { 1 }), DbTypeID.LONG)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISNOTNULL(tools, fargs); ByteSlice bs = valOutput.Eval(); bool output = tools.GetInt(bs) != 0; bool expected = !true; if (expected != output) { throw new Exception("DbFunctions.ISNOTNULL(Long=NULL) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } } }
public static void DbFunctions_NULLIF() { DbFunctionTools tools = new DbFunctionTools(); { Console.WriteLine("Testing DbFunctions.NULLIF(DateTime, DateTime)..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(DateTime.Parse("12/1/2000 10:00:00 AM"))); args.Add(tools.AllocValue(DateTime.Parse("12/1/2000 10:00:00 AM"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.NULLIF(tools, fargs); ByteSlice bs = valOutput.Eval(); bool output = Types.IsNullValue(bs); bool expected = true; if (expected != output) { throw new Exception("DbFunctions.NULLIF(DateTime, DateTime) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.NULLIF(DateTime, DateTime)..."); List <DbValue> args = new List <DbValue>(); DateTime dt = DateTime.Parse("12/1/2000 10:00:00 AM"); args.Add(tools.AllocValue(dt)); args.Add(tools.AllocValue(DateTime.Parse("12/2/2000 10:00:00 AM"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.NULLIF(tools, fargs); ByteSlice bs = valOutput.Eval(); DateTime output = tools.GetDateTime(bs); DateTime expected = dt; if (expected != output) { throw new Exception("DbFunctions.NULLIF(DateTime, DateTime) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.NULLIF(Int32, Int32)..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(10)); args.Add(tools.AllocValue(10)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.NULLIF(tools, fargs); ByteSlice bs = valOutput.Eval(); bool output = Types.IsNullValue(bs); bool expected = true; if (expected != output) { throw new Exception("DbFunctions.NULLIF(Int32, Int32) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.NULLIF(Int32, Int32)..."); List <DbValue> args = new List <DbValue>(); int x = 10; args.Add(tools.AllocValue(x)); args.Add(tools.AllocValue(11)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.NULLIF(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = x; if (expected != output) { throw new Exception("DbFunctions.NULLIF(Int32, Int32) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.NULLIF(Int32, long)..."); List <DbValue> args = new List <DbValue>(); int x = 10; long y = 10; args.Add(tools.AllocValue(x)); args.Add(tools.AllocValue(y)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.NULLIF(tools, fargs); ByteSlice bs = valOutput.Eval(); bool output = Types.IsNullValue(bs); bool expected = true; if (expected != output) { throw new Exception("DbFunctions.NULLIF(Int32, long) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.NULLIF(Int32, long)..."); List <DbValue> args = new List <DbValue>(); int x = 10; long y = 11; args.Add(tools.AllocValue(x)); args.Add(tools.AllocValue(y)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.NULLIF(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = x; if (expected != output) { throw new Exception("DbFunctions.NULLIF(Int32, long) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } }
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."); } } }
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 DbFunctions_GREATEREQUAL() { DbFunctionTools tools = new DbFunctionTools(); Random rnd = new Random(); { Console.WriteLine("Testing DbFunctions.GREATEREQUAL(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.GREATEREQUAL(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.GREATEREQUAL(char(n), char(n)) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.GREATEREQUAL(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.GREATEREQUAL(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = (x >= y ? 1 : 0); if (expected != output) { throw new Exception("DbFunctions.GREATEREQUAL(Int32, Int32) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.GREATEREQUAL(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.GREATEREQUAL(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = (x >= y ? 1 : 0); if (expected != output) { throw new Exception("DbFunctions.GREATEREQUAL(Double, Double) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.GREATEREQUAL(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.GREATEREQUAL(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = (x >= y ? 1 : 0); if (expected != output) { throw new Exception("DbFunctions.GREATEREQUAL(Long, Long) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.GREATEREQUAL(Int32, Double)..."); int x = rnd.Next(Int32.MinValue, Int32.MaxValue); 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.GREATEREQUAL(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = (x >= y ? 1 : 0); if (expected != output) { throw new Exception("DbFunctions.GREATEREQUAL(Int32, Double) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.GREATEREQUAL(Int32, Long)..."); int x = rnd.Next(Int32.MinValue, Int32.MaxValue); 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.GREATEREQUAL(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = (x >= y ? 1 : 0); if (expected != output) { throw new Exception("DbFunctions.GREATEREQUAL(Int32, Long) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } }
public static void DbFunctions_COMPARE() { DbFunctionTools tools = new DbFunctionTools(); Random rnd = new Random(); const int NUM_RUNS_EACH = 4; for (int it = 0; it < NUM_RUNS_EACH; it++) { Console.WriteLine("Testing DbFunctions.COMPARE(char(n), char(n)) ({0} of {1})...", it + 1, NUM_RUNS_EACH); mstring x = Utils.GenString(rnd.Next(1, 200)); mstring y = Utils.GenString(rnd.Next(1, 200)); if (1 == it) { y = x; } List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(x)); args.Add(tools.AllocValue(y)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.COMPARE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = string.Compare(x.ToString(), y.ToString(), StringComparison.OrdinalIgnoreCase); if (!_SameCompareRank(expected, output)) { if (0 == expected || 0 == output) { throw new Exception("DbFunctions.COMPARE(char(n), char(n)) has failed. Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output)); } Console.WriteLine("Warning: C# StringComparison.OrdinalIgnoreCase and DbFunctions.COMPARE do not agree on string ordering: C# says " + _CompareRankToString(expected) + " but I say " + _CompareRankToString(output) + " for:\r\n\t'{0}'\r\n\t'{1}'", x.ToString(), y.ToString()); System.Threading.Thread.Sleep(1000 * 3); } else { Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected)); } } for (int it = 0; it < NUM_RUNS_EACH; it++) { Console.WriteLine("Testing DbFunctions.COMPARE(Int32, Int32) ({0} of {1})...", it + 1, NUM_RUNS_EACH); int x = rnd.Next(Int32.MinValue, Int32.MaxValue); int y = rnd.Next(Int32.MinValue, Int32.MaxValue); if (1 == it) { y = x; } List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(x)); args.Add(tools.AllocValue(y)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.COMPARE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = x.CompareTo(y); if (!_SameCompareRank(expected, output)) { throw new Exception("DbFunctions.COMPARE(Int32, Int32) has failed. Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output)); } else { Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected)); } } for (int it = 0; it < NUM_RUNS_EACH; it++) { Console.WriteLine("Testing DbFunctions.COMPARE(Double, Double) ({0} of {1})...", it + 1, NUM_RUNS_EACH); double x = rnd.NextDouble(); double y = rnd.NextDouble(); if (1 == it) { y = x; } List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(x)); args.Add(tools.AllocValue(y)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.COMPARE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = x.CompareTo(y); if (!_SameCompareRank(expected, output)) { throw new Exception("DbFunctions.COMPARE(Double, Double) has failed. Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output)); } else { Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected)); } } for (int it = 0; it < NUM_RUNS_EACH; it++) { Console.WriteLine("Testing DbFunctions.COMPARE(Long, Long) ({0} of {1})...", it + 1, NUM_RUNS_EACH); long x = unchecked ((long)rnd.Next() * (long)rnd.Next()); long y = unchecked ((long)rnd.Next() * (long)rnd.Next()); if (1 == it) { y = x; } List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(x)); args.Add(tools.AllocValue(y)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.COMPARE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = x.CompareTo(y); if (!_SameCompareRank(expected, output)) { throw new Exception("DbFunctions.COMPARE(Long, Long) has failed. Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output)); } else { Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected)); } } for (int it = 0; it < NUM_RUNS_EACH; it++) { Console.WriteLine("Testing DbFunctions.COMPARE(Double, Int32) ({0} of {1})...", it + 1, NUM_RUNS_EACH); double x = rnd.NextDouble(); int y = rnd.Next(); if (1 == it) { //y = x; x = y; } List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(x)); args.Add(tools.AllocValue(y)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.COMPARE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = x.CompareTo((double)y); if (!_SameCompareRank(expected, output)) { throw new Exception("DbFunctions.COMPARE(Double, Int32) has failed. Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output)); } else { Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected)); } } for (int it = 0; it < NUM_RUNS_EACH; it++) { Console.WriteLine("Testing DbFunctions.COMPARE(Double, Long) ({0} of {1})...", it + 1, NUM_RUNS_EACH); double x = rnd.NextDouble(); long y = unchecked ((long)rnd.Next() * (long)rnd.Next()); if (1 == it) { //y = x; x = y; } List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(x)); args.Add(tools.AllocValue(y)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.COMPARE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = x.CompareTo((double)y); if (!_SameCompareRank(expected, output)) { throw new Exception("DbFunctions.COMPARE(Double, Long) has failed. Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output)); } else { Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected)); } } for (int it = 0; it < NUM_RUNS_EACH; it++) { Console.WriteLine("Testing DbFunctions.COMPARE(DateTime, DateTime) ({0} of {1})...", it + 1, NUM_RUNS_EACH); DateTime x = DateTime.Now; DateTime y = x.AddDays(rnd.Next(-365, 365)); if (1 == it) { y = x; } List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(x)); args.Add(tools.AllocValue(y)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.COMPARE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = x.CompareTo(y); if (!_SameCompareRank(expected, output)) { throw new Exception("DbFunctions.COMPARE(DateTime, DateTime) has failed. Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output)); } else { Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected)); } } for (int it = 0; it < NUM_RUNS_EACH; it++) { Console.WriteLine("Testing DbFunctions.COMPARE(DateTime, Char(n)) ({0} of {1})...", it + 1, NUM_RUNS_EACH); DateTime x = DateTime.Now; DateTime dt = x.AddDays(rnd.Next(-365, 365)); mstring y = mstring.Prepare(dt.ToString()); if (1 == it) { y = mstring.Prepare(x.ToString()); } List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(x)); args.Add(tools.AllocValue(y)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.COMPARE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = x.CompareTo(DateTime.Parse(y.ToString())); if (!_SameCompareRank(expected, output)) { throw new Exception("DbFunctions.COMPARE(DateTime, Char(n)) has failed. Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output)); } else { Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected)); } } for (int it = 0; it < NUM_RUNS_EACH; it++) { Console.WriteLine("Testing DbFunctions.COMPARE(Char(n), DateTime) ({0} of {1})...", it + 1, NUM_RUNS_EACH); DateTime y = DateTime.Now; DateTime dt = y.AddDays(rnd.Next(-365, 365)); mstring x = mstring.Prepare(dt.ToString()); if (1 == it) { x = mstring.Prepare(y.ToString()); } List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(x)); args.Add(tools.AllocValue(y)); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.COMPARE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = DateTime.Parse(x.ToString()).CompareTo(y); if (!_SameCompareRank(expected, output)) { throw new Exception("DbFunctions.COMPARE(Char(n), DateTime) has failed. Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output)); } else { Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected)); } } }
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 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."); } } }
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 DbFunctions_DATEPART() { DbFunctionTools tools = new DbFunctionTools(); DateTime input = new DateTime(1999, 3, 14, 13, 1, 33); DbValue valInput = tools.AllocValue(input); List <DbValue> args = new List <DbValue>(); args.Add(valInput); DbFunctionArguments fargs = new DbFunctionArguments(args); { Console.WriteLine("Testing DbFunctions.DATEPART_YEAR..."); DbValue valOutput = DbFunctions.DATEPART_YEAR(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = input.Year; if (expected != output) { throw new Exception("DbFunctions.DATEPART_YEAR has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.DATEPART_MONTH..."); DbValue valOutput = DbFunctions.DATEPART_MONTH(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = input.Month; if (expected != output) { throw new Exception("DbFunctions.DATEPART_MONTH has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.DATEPART_DAY..."); DbValue valOutput = DbFunctions.DATEPART_DAY(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = input.Day; if (expected != output) { throw new Exception("DbFunctions.DATEPART_DAY has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.DATEPART_HOUR..."); DbValue valOutput = DbFunctions.DATEPART_HOUR(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = input.Hour; if (expected != output) { throw new Exception("DbFunctions.DATEPART_HOUR has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.DATEPART_MINUTE..."); DbValue valOutput = DbFunctions.DATEPART_MINUTE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = input.Minute; if (expected != output) { throw new Exception("DbFunctions.DATEPART_MINUTE has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing DbFunctions.DATEPART_SECOND..."); DbValue valOutput = DbFunctions.DATEPART_SECOND(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = input.Second; if (expected != output) { throw new Exception("DbFunctions.DATEPART_SECOND has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } }
public static void DbFunctions_ISLIKE() { DbFunctionTools tools = new DbFunctionTools(); { Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'%xxx')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("red apple"))); args.Add(tools.AllocValue(mstring.Prepare("%apple"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 1; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'%xxx') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing case-insensitive positive DbFunctions.ISLIKE(String,'%xxx')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("red apple"))); args.Add(tools.AllocValue(mstring.Prepare("%Apple"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 1; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'%xxx') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'%xxx')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("red aple"))); args.Add(tools.AllocValue(mstring.Prepare("%apple"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 0; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'%xxx') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'xx_x')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("apple"))); args.Add(tools.AllocValue(mstring.Prepare("app_e"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 1; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'xx_x') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'xx_x')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("applle"))); args.Add(tools.AllocValue(mstring.Prepare("app_e"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 0; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'xx_x') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'xx[a-d]xx')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("comater"))); args.Add(tools.AllocValue(mstring.Prepare("com[a-d]ter"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 1; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'xx[a-d]xx') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'xx[a-d]xx')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("comxter"))); args.Add(tools.AllocValue(mstring.Prepare("com[a-d]ter"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 0; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'xx[a-d]xx') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'xx[^a-d]xx')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("comxter"))); args.Add(tools.AllocValue(mstring.Prepare("com[^a-d]ter"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 1; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'xx[a-d]xx') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'xx[^a-d]xx')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("comater"))); args.Add(tools.AllocValue(mstring.Prepare("com[^a-d]ter"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 0; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'xx[a-d]xx') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } //Using Wildcard Characters As Literals { Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'x[%]')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("5%"))); args.Add(tools.AllocValue(mstring.Prepare("5[%]"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 1; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'x[%]') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'x[%]')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("54"))); args.Add(tools.AllocValue(mstring.Prepare("5[%]"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 0; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'x[%]') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'[_]n')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("_n"))); args.Add(tools.AllocValue(mstring.Prepare("[_]n"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 1; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'x[%]') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'[_]n')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("n"))); args.Add(tools.AllocValue(mstring.Prepare("[_]n"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 0; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'[_]n') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'[-acdf]')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("-"))); args.Add(tools.AllocValue(mstring.Prepare("[-acdf]"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 1; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'[-acdf]') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'[-acdf]')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("b"))); args.Add(tools.AllocValue(mstring.Prepare("[-acdf]"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 0; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'[-acdf]') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'[ [ ]')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("["))); args.Add(tools.AllocValue(mstring.Prepare("[ [ ]"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 1; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'[ [ ]') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'[ [ ]')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("p"))); args.Add(tools.AllocValue(mstring.Prepare("[ [ ]"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 0; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'[ [ ]') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } { Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'[*]')..."); List <DbValue> args = new List <DbValue>(); args.Add(tools.AllocValue(mstring.Prepare("*"))); args.Add(tools.AllocValue(mstring.Prepare("[*]"))); DbFunctionArguments fargs = new DbFunctionArguments(args); DbValue valOutput = DbFunctions.ISLIKE(tools, fargs); ByteSlice bs = valOutput.Eval(); int output = tools.GetInt(bs); int expected = 1; if (expected != output) { throw new Exception("DbFunctions.ISLIKE(String,'[*]') has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString()); } else { Console.WriteLine("Expected results received."); } } }