public void Conversions() { SqlInt64 test12 = new SqlInt64(12); SqlInt64 test0 = new SqlInt64(0); SqlInt64 TestNull = SqlInt64.Null; SqlInt64 test1000 = new SqlInt64(1000); SqlInt64 test288 = new SqlInt64(288); // ToSqlBoolean () Assert.True(test12.ToSqlBoolean().Value); Assert.False(test0.ToSqlBoolean().Value); Assert.True(TestNull.ToSqlBoolean().IsNull); // ToSqlByte () Assert.Equal((byte)12, test12.ToSqlByte().Value); Assert.Equal((byte)0, test0.ToSqlByte().Value); Assert.Throws <OverflowException>(() => test1000.ToSqlByte()); // ToSqlDecimal () Assert.Equal(12, test12.ToSqlDecimal().Value); Assert.Equal(0, test0.ToSqlDecimal().Value); Assert.Equal(288, test288.ToSqlDecimal().Value); // ToSqlDouble () Assert.Equal(12, test12.ToSqlDouble().Value); Assert.Equal(0, test0.ToSqlDouble().Value); Assert.Equal(1000, test1000.ToSqlDouble().Value); // ToSqlInt32 () Assert.Equal(12, test12.ToSqlInt32().Value); Assert.Equal(0, test0.ToSqlInt32().Value); Assert.Equal(288, test288.ToSqlInt32().Value); // ToSqlInt16 () Assert.Equal((short)12, test12.ToSqlInt16().Value); Assert.Equal((short)0, test0.ToSqlInt16().Value); Assert.Equal((short)288, test288.ToSqlInt16().Value); // ToSqlMoney () Assert.Equal(12.0000M, test12.ToSqlMoney().Value); Assert.Equal(0, test0.ToSqlMoney().Value); Assert.Equal(288.0000M, test288.ToSqlMoney().Value); // ToSqlSingle () Assert.Equal(12, test12.ToSqlSingle().Value); Assert.Equal(0, test0.ToSqlSingle().Value); Assert.Equal(288, test288.ToSqlSingle().Value); // ToSqlString () Assert.Equal("12", test12.ToSqlString().Value); Assert.Equal("0", test0.ToSqlString().Value); Assert.Equal("288", test288.ToSqlString().Value); // ToString () Assert.Equal("12", test12.ToString()); Assert.Equal("0", test0.ToString()); Assert.Equal("288", test288.ToString()); }
public static SqlString FN_FORMATINT(SqlInt64 FLD_VAL, SqlInt32 EXP_LEN, SqlString FLD_NAME, SqlString REC_TYPE, SqlString X02_KEY) { if (FLD_VAL.IsNull) { return(Convert.ToString(string.Empty.PadRight((int)EXP_LEN, '0').ToString())); } if (Convert.ToString(FLD_VAL).Length < (int)EXP_LEN) { return(Convert.ToString(FLD_VAL.ToString().PadLeft((int)EXP_LEN, '0'))); } if (Convert.ToString(FLD_VAL).Length > (int)EXP_LEN) { FN_FORMAT_EXCEPTION(REC_TYPE.ToString(), "Length OverRun", "W", X02_KEY.ToString(), FLD_NAME.ToString(), FLD_VAL.ToString(), string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty); return(FLD_VAL.ToString().Substring(0, (int)EXP_LEN)); } if (FLD_VAL.ToString().Length == (int)EXP_LEN) { return(FLD_VAL.ToString()); } return(new NotImplementedException().ToString()); }
public void Conversions() { SqlInt64 Test12 = new SqlInt64(12); SqlInt64 Test0 = new SqlInt64(0); SqlInt64 TestNull = SqlInt64.Null; SqlInt64 Test1000 = new SqlInt64(1000); SqlInt64 Test288 = new SqlInt64(288); // ToSqlBoolean () Assert.IsTrue(Test12.ToSqlBoolean().Value, "#P01"); Assert.IsTrue(!Test0.ToSqlBoolean().Value, "#P02"); Assert.IsTrue(TestNull.ToSqlBoolean().IsNull, "#P03"); // ToSqlByte () Assert.AreEqual((byte)12, Test12.ToSqlByte().Value, "#P04"); Assert.AreEqual((byte)0, Test0.ToSqlByte().Value, "#P05"); try { SqlByte b = (byte)Test1000.ToSqlByte(); Assert.Fail("#P06"); } catch (OverflowException e) { Assert.AreEqual(typeof(OverflowException), e.GetType(), "#P07"); } // ToSqlDecimal () Assert.AreEqual((decimal)12, Test12.ToSqlDecimal().Value, "#P08"); Assert.AreEqual((decimal)0, Test0.ToSqlDecimal().Value, "#P09"); Assert.AreEqual((decimal)288, Test288.ToSqlDecimal().Value, "#P10"); // ToSqlDouble () Assert.AreEqual((double)12, Test12.ToSqlDouble().Value, "#P11"); Assert.AreEqual((double)0, Test0.ToSqlDouble().Value, "#P12"); Assert.AreEqual((double)1000, Test1000.ToSqlDouble().Value, "#P13"); // ToSqlInt32 () Assert.AreEqual((int)12, Test12.ToSqlInt32().Value, "#P14"); Assert.AreEqual((int)0, Test0.ToSqlInt32().Value, "#P15"); Assert.AreEqual((int)288, Test288.ToSqlInt32().Value, "#P16"); // ToSqlInt16 () Assert.AreEqual((short)12, Test12.ToSqlInt16().Value, "#P17"); Assert.AreEqual((short)0, Test0.ToSqlInt16().Value, "#P18"); Assert.AreEqual((short)288, Test288.ToSqlInt16().Value, "#P19"); // ToSqlMoney () Assert.AreEqual(12.0000M, Test12.ToSqlMoney().Value, "#P20"); Assert.AreEqual((decimal)0, Test0.ToSqlMoney().Value, "#P21"); Assert.AreEqual(288.0000M, Test288.ToSqlMoney().Value, "#P22"); // ToSqlSingle () Assert.AreEqual((float)12, Test12.ToSqlSingle().Value, "#P23"); Assert.AreEqual((float)0, Test0.ToSqlSingle().Value, "#P24"); Assert.AreEqual((float)288, Test288.ToSqlSingle().Value, "#P25"); // ToSqlString () Assert.AreEqual("12", Test12.ToSqlString().Value, "#P26"); Assert.AreEqual("0", Test0.ToSqlString().Value, "#P27"); Assert.AreEqual("288", Test288.ToSqlString().Value, "#P28"); // ToString () Assert.AreEqual("12", Test12.ToString(), "#P29"); Assert.AreEqual("0", Test0.ToString(), "#P30"); Assert.AreEqual("288", Test288.ToString(), "#P31"); }
public void Conversions() { SqlInt64 Test12 = new SqlInt64(12); SqlInt64 Test0 = new SqlInt64(0); SqlInt64 TestNull = SqlInt64.Null; SqlInt64 Test1000 = new SqlInt64(1000); SqlInt64 Test288 = new SqlInt64(288); // ToSqlBoolean () Assert.True(Test12.ToSqlBoolean().Value); Assert.True(!Test0.ToSqlBoolean().Value); Assert.True(TestNull.ToSqlBoolean().IsNull); // ToSqlByte () Assert.Equal((byte)12, Test12.ToSqlByte().Value); Assert.Equal((byte)0, Test0.ToSqlByte().Value); try { SqlByte b = (byte)Test1000.ToSqlByte(); Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlDecimal () Assert.Equal(12, Test12.ToSqlDecimal().Value); Assert.Equal(0, Test0.ToSqlDecimal().Value); Assert.Equal(288, Test288.ToSqlDecimal().Value); // ToSqlDouble () Assert.Equal(12, Test12.ToSqlDouble().Value); Assert.Equal(0, Test0.ToSqlDouble().Value); Assert.Equal(1000, Test1000.ToSqlDouble().Value); // ToSqlInt32 () Assert.Equal(12, Test12.ToSqlInt32().Value); Assert.Equal(0, Test0.ToSqlInt32().Value); Assert.Equal(288, Test288.ToSqlInt32().Value); // ToSqlInt16 () Assert.Equal((short)12, Test12.ToSqlInt16().Value); Assert.Equal((short)0, Test0.ToSqlInt16().Value); Assert.Equal((short)288, Test288.ToSqlInt16().Value); // ToSqlMoney () Assert.Equal(12.0000M, Test12.ToSqlMoney().Value); Assert.Equal(0, Test0.ToSqlMoney().Value); Assert.Equal(288.0000M, Test288.ToSqlMoney().Value); // ToSqlSingle () Assert.Equal(12, Test12.ToSqlSingle().Value); Assert.Equal(0, Test0.ToSqlSingle().Value); Assert.Equal(288, Test288.ToSqlSingle().Value); // ToSqlString () Assert.Equal("12", Test12.ToSqlString().Value); Assert.Equal("0", Test0.ToSqlString().Value); Assert.Equal("288", Test288.ToSqlString().Value); // ToString () Assert.Equal("12", Test12.ToString()); Assert.Equal("0", Test0.ToString()); Assert.Equal("288", Test288.ToString()); }
/// <summary> /// /// </summary> /// <returns></returns> public override string ToString() { return(_sql.ToString()); }
public static void ShortestPath(SqlInt64 startNode, SqlInt64 endNode, SqlInt32 maxNodesToCheck, out SqlString pathResult, out SqlDouble distResult) { Dictionary <long, double> distance = new Dictionary <long, double>(); // curr shortest distance (double) from startNode to (key) node Dictionary <long, long> previous = new Dictionary <long, long>(); // predecessor values to construct the actual path when done Dictionary <long, bool> beenAdded = new Dictionary <long, bool>(); // has node been added to the queue yet? Once added, we don't want to add again long startNodeAsLong = (long)startNode; long endNodeAsLong = (long)endNode; int maxNodesToCheckAsInt = (int)maxNodesToCheck; MyPriorityQueue PQ = new MyPriorityQueue(); //initialize start node distance[startNodeAsLong] = 0.0; // distance from start node to itself is 0 previous[startNodeAsLong] = -1; // -1 is the code for undefined. PQ.Enqueue(new NodeDistance(startNodeAsLong, 0.0)); // the queue holds distance information because Enqueue and Dequeue need it to keep queue ordered by priority. alt approach would be to store only node IDs and then do a distance lookup beenAdded[startNodeAsLong] = true; double alt = 0.0; //'test distance' try { while (PQ.Count() > 0 && beenAdded.Count < maxNodesToCheckAsInt) { NodeDistance u = PQ.Dequeue();// node with shortest distance from start if (u.nodeID == endNode) { break;// found the target end node } //fetch all neighbors (v) of u List <Tuple <long, double> > neighbors = new List <Tuple <long, double> >(); neighbors = FetchNeighbors(u.nodeID); foreach (var v in neighbors) // if there are no neighbors, this loop will exit immediately { if (beenAdded.ContainsKey(v.Item1) == false) //first appearance of node v { distance[v.Item1] = double.MaxValue; //stand-in for infinity previous[v.Item1] = -1; //undefined PQ.Enqueue(new NodeDistance(v.Item1, double.MaxValue)); //maxValue is a dummy value beenAdded[v.Item1] = true; } //alt = distance[u.nodeID] + 1.0; // if all edge weights are just hops can simplify to this alt = distance[u.nodeID] + v.Item2; // alt = dist(start-to-u) + dist(u-to-v), so alt is total distance from start to v if (alt < distance[v.Item1]) // is alt a new, shorter distance from start to v? { distance[v.Item1] = alt; previous[v.Item1] = u.nodeID; PQ.ChangePriority(v.Item1, alt); // this will change the distance/priority } } } // extract the shortest path as a string from the previous[] array pathResult = "NOTREACHABLE"; // default result string distResult = -1.0; // distance result defaults to -1 == unreachable if (distance.ContainsKey(endNodeAsLong) == true) // endNode was encountered at some point in the algorithm { double sp = distance[endNodeAsLong]; // shortest path distance if (sp != double.MaxValue) // we have a reachable path { pathResult = ""; long currNode = endNodeAsLong; while (currNode != startNodeAsLong) // construct the path as semicolon delimited string { pathResult += currNode.ToString() + ";"; currNode = previous[currNode]; } pathResult += startNode.ToString(); // tack on the start node distResult = sp; // the distance result } } } catch (Exception ex) // typically Out Of Memory or a Command TimeOut { pathResult = ex.ToString(); distResult = -1.0; } }
public override string ToString() => _sql.ToString();