// The series of tests below is for ConvertListToBlobWithChecksum() // // This method is reused by the actual test methods that follow public Boolean ComputeTestChecksums( TSDateCalculator.TimeStepUnitCode u1, short q1, List <TimeSeriesValue> list1, ITimeSeriesTrace trace1, TSDateCalculator.TimeStepUnitCode u2, short q2, List <TimeSeriesValue> list2, ITimeSeriesTrace trace2) { TSLibrary tsLib = new TSLibrary(); int compressionCode; tsLib.ConvertListToBlobWithChecksum( u1, q1, list1.Count, list1[0].Date, list1[list1.Count - 1].Date, list1, trace1, out compressionCode); tsLib.ConvertListToBlobWithChecksum( u2, q2, list2.Count, list2[0].Date, list2[list2.Count - 1].Date, list2, trace2, out compressionCode); Assert.IsTrue(trace1.Checksum.Length == 16); Assert.IsTrue(trace2.Checksum.Length == 16); for (int i = 0; i < trace2.Checksum.Length; i++) { if (trace1.Checksum[i] != trace2.Checksum[i]) { return(false); } } return(true); }
// The series of tests below is for ConvertBlobToListAll and ConvertListToBlob. // The tests take advantage of the fact that the methods are designed so that // the series that is put into the BLOB must be identical to the series that // comes out of the BLOB. // This method is re-used by the actual test methods that follow. public void ConvertBlobAll(List <TimeSeriesValue> inList, TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity, DateTime blobStartDate) { TSLibrary tsLib = new TSLibrary(); List <TimeSeriesValue> outList = new List <TimeSeriesValue>(); int compressionCode; byte[] blobData = tsLib.ConvertListToBlobWithChecksum(timeStepUnit, timeStepQuantity, inList.Count, inList.First().Date, inList.Last().Date, inList, new TSTrace { TraceNumber = 1 }, out compressionCode); int ret = tsLib.ConvertBlobToListAll(timeStepUnit, timeStepQuantity, inList.Count, blobStartDate, blobData, ref outList, compressionCode); // The return value of the function must match the number of items in the original list Assert.AreEqual(ret, inList.Count); // the count in both lists must match Assert.AreEqual(outList.Count, inList.Count); // now check each item in the two lists Boolean AreEqual = true; for (int i = 0; i < ret; i++) { if (outList[i].ValueEquals(inList[i]) == false) { AreEqual = false; } } Assert.IsTrue(AreEqual); }
private unsafe int WritingTest() { String paramTableName = "OutputTimeSeries"; String traceTableName = "OutputTimeSeriesTraces"; String extraParamNames = "RunGUID, TimeSeriesType, VariableType, Unit_Id, VariableName, RunElementGUID"; String extraParamValues = "'00000000-0000-0000-0000-000000000000', 2, 'Dummy', 2, 'DELETEME', '00000000-0000-0000-0000-000000000000'"; int connectionNumber = 1; TSLibrary tsLib = new TSLibrary(); connectionNumber = tsLib.OpenConnection( "Data Source=.; Database=NYC-SpeedTest; Trusted_Connection=yes;"); var connection = tsLib.ConnxObject.TSConnectionsCollection[connectionNumber]; List <Double> valList = new List <Double>(); DateTime date = StartDate; int x = 0; for (int i = 0; i < nVals; i++) { //x = Math.Abs(x - 1); valList.Add(i * Math.PI); date = date.AddDays(1); } var valArray = valList.ToArray(); //byte[] blob = null; for (int j = 0; j < nIter; j++) { var ts = new TS(connection, paramTableName, traceTableName); int id = ts.WriteParametersRegular(true, null, (short)TSDateCalculator.TimeStepUnitCode.Day, 1, nVals, StartDate, extraParamNames, extraParamValues); //int id = 800291; for (int i = 0; i < nTrc; i++) { ts.WriteTraceRegular(id, true, null, i + 1, valArray); //ITimeSeriesTrace traceObject = new TSTrace //{ // TraceNumber = i+1, // TimeStepCount = nVals, // EndDate = date //}; //blob = TSBlobCoder.ConvertArrayToBlobRegular(valArray, 2, traceObject); } } connection.CommitWritesToTable(traceTableName); return(0); // blob.Length; }
public List <ITimeSeriesTrace> Get3TracesRegular( TSDateCalculator.TimeStepUnitCode u1, short q1, int c1, DateTime sDate1, out DateTime eDate1, Boolean shouldPerturb = false, int perturbTraceIndex = 0, int perturbStep = 0, double perturbVal = 0, double perturbMinutes = 0) { eDate1 = DateTime.Now; // dummy TSLibrary tsLib = new TSLibrary(); List <ITimeSeriesTrace> traceList = new List <ITimeSeriesTrace>(); int compressionCode; for (int t = 0; t < 3; t++) { TSTrace trace1 = new TSTrace { TraceNumber = t + 1 }; List <TimeSeriesValue> tsValues = new List <TimeSeriesValue>(); DateTime curDate = sDate1; Double curVal = 20; for (int i = 0; i < c1; i++) { tsValues.Add(new TimeSeriesValue { Date = curDate, Value = curVal }); curDate = tsLib.IncrementDate(curDate, u1, q1, 1); curVal = curVal + i / (t + 1); } // make a perturbation if called for if (shouldPerturb && t == perturbTraceIndex) { tsValues[perturbStep].Value += perturbVal; tsValues[perturbStep].Date = tsValues[perturbStep].Date.AddMinutes(perturbMinutes); } eDate1 = tsValues.Last().Date; tsLib.ConvertListToBlobWithChecksum( u1, q1, c1, sDate1, eDate1, tsValues, trace1, out compressionCode); traceList.Add(trace1); } return(traceList); }
public void ComputeChecksum_Err1() { TSLibrary tsLib = new TSLibrary(); TSTrace traceObject = new TSTrace { TraceNumber = 1 }; try { byte[] blobData = tsLib.ComputeChecksum( TSDateCalculator.TimeStepUnitCode.Irregular, 3, IrregList1.First().Date, new List <ITimeSeriesTrace>()); Assert.Fail("Should have thrown exception"); } catch (TSLibraryException e) { Assert.AreEqual(ErrCode.Enum.Checksum_Quantity_Nonzero, e.ErrCode); } }
public void ConvertListToBlobWithChecksum_Err4() { TSLibrary tsLib = new TSLibrary(); TSTrace traceObject = new TSTrace { TraceNumber = 1 }; int compressionCode; try { byte[] blobData = tsLib.ConvertListToBlobWithChecksum( TSDateCalculator.TimeStepUnitCode.Irregular, 0, IrregList1.Count, IrregList1.First().Date, IrregList1.Last().Date.AddDays(2), IrregList1, traceObject, out compressionCode); Assert.Fail("Should have thrown exception"); } catch (TSLibraryException e) { Assert.AreEqual(ErrCode.Enum.Checksum_Improper_EndDate, e.ErrCode); } }
public void ConvertListToBlobWithChecksum_Err0() { TSLibrary tsLib = new TSLibrary(); TSTrace traceObject = new TSTrace { TraceNumber = 1 }; int compressionCode; try { byte[] blobData = tsLib.ConvertListToBlobWithChecksum( TSDateCalculator.TimeStepUnitCode.Irregular, 0, IrregList1.Count, IrregList1.First().Date, IrregList1.Last().Date, IrregList1, traceObject, out compressionCode); Assert.IsTrue(true); } catch (TSLibraryException) { Assert.Fail("Should not throw any exceptions"); } }
// The series of tests below is for ConvertBlobToListLimited and ConvertListToBlob. // The tests take advantage of the fact that the methods are designed so that // the series that is put into the BLOB must be identical to the series that // comes out of the BLOB. // This method is re-used by the actual test methods that follow. public void ConvertBlobLimited(List <TimeSeriesValue> inList, TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity, DateTime blobStartDate, int nCutStart, // the number of time steps that the test will truncate from the start of the series int nCutEnd, // the number of time steps that the test will truncate from the end of the series int nMax) // the maximum number of time steps to put into the series { TSLibrary tsLib = new TSLibrary(); List <TimeSeriesValue> outList = new List <TimeSeriesValue>(); int compressionCode; byte[] blobData = tsLib.ConvertListToBlobWithChecksum(timeStepUnit, timeStepQuantity, inList.Count, inList.First().Date, inList.Last().Date, inList, new TSTrace { TraceNumber = 1 }, out compressionCode); int ret = tsLib.ConvertBlobToListLimited(timeStepUnit, timeStepQuantity, inList.Count, blobStartDate, nMax, inList[nCutStart].Date, inList[inList.Count - nCutEnd - 1].Date, blobData, ref outList, compressionCode); // The return value of the function must match the number of items in the original list Assert.AreEqual(ret, Math.Min(nMax, inList.Count - nCutStart - nCutEnd)); // the count in both lists must match Assert.AreEqual(outList.Count, Math.Min(nMax, inList.Count - nCutStart - nCutEnd)); // now check each item in the two lists Boolean AreEqual = true; for (int i = 0; i < ret; i++) { if (outList[i].ValueEquals(inList[i + nCutStart]) == false) { AreEqual = false; } } Assert.IsTrue(AreEqual); }
// This method is reused by the actual test methods that follow public Boolean ComputeTestChecksums( TSDateCalculator.TimeStepUnitCode u1, short q1, DateTime sDate1, List <ITimeSeriesTrace> traceList1, TSDateCalculator.TimeStepUnitCode u2, short q2, DateTime sDate2, List <ITimeSeriesTrace> traceList2) { TSLibrary tsLib = new TSLibrary(); byte[] b1 = tsLib.ComputeChecksum(u1, q1, sDate1, traceList1); byte[] b2 = tsLib.ComputeChecksum(u2, q2, sDate2, traceList2); Assert.IsTrue(b1.Length == 16); Assert.IsTrue(b2.Length == 16); for (int i = 0; i < b2.Length; i++) { if (b1[i] != b2[i]) { return(false); } } return(true); }
// Note--this test class was created primarily b/c we wanted to individually test the different // compression methods. Hence, we have created the test methods below. The class TSBlobCoder // certainly deserves full test coverage, but that can be developed later. In the meantime, // it is generally expected that TSBlobCoder has adequate test coverage via TSLibraryTest. #region Test Methods for ConvertBlobToListAll() and ConvertListToBlob() // The series of tests below is for ConvertBlobToListAll and ConvertListToBlob. // The tests take advantage of the fact that the methods are designed so that // the series that is put into the BLOB must be identical to the series that // comes out of the BLOB. // This method is re-used by the actual test methods that follow. public void ConvertBlobAll(List <TimeSeriesValue> inList, TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity, DateTime blobStartDate, int compressionCode) { TSLibrary tsLib = new TSLibrary(); var traceObject = new TSTrace { TraceNumber = 1, TimeStepCount = inList.Count, EndDate = inList.Last().Date }; if (timeStepUnit == TSDateCalculator.TimeStepUnitCode.Irregular) { var inArray = inList.Select(v => (TSDateValueStruct)v).ToArray(); var outArray = new TSDateValueStruct[inList.Count]; byte[] blobData = TSBlobCoder.ConvertArrayToBlobIrregular(inArray, compressionCode, traceObject); int ret = TSBlobCoder.ConvertBlobToArrayIrregular(inList.Count, false, 0, blobStartDate, blobStartDate, blobData, outArray, compressionCode); // The return value of the function must match the number of items in the original list Assert.AreEqual(ret, inList.Count); // the count in both lists must match Assert.AreEqual(inArray.Length, outArray.Length); // now check each item in the two lists Boolean AreEqual = true; for (int i = 0; i < ret; i++) { if (outArray[i].Date != inArray[i].Date || outArray[i].Value != inArray[i].Value) { AreEqual = false; } } Assert.IsTrue(AreEqual); } else { var inArray = inList.Select(v => v.Value).ToArray(); var outArray = new Double[inList.Count]; byte[] blobData = TSBlobCoder.ConvertArrayToBlobRegular(inArray, compressionCode, traceObject); int ret = TSBlobCoder.ConvertBlobToArrayRegular(timeStepUnit, timeStepQuantity, inList.Count, blobStartDate, false, 0, blobStartDate, blobStartDate, blobData, outArray, compressionCode); // The return value of the function must match the number of items in the original list Assert.AreEqual(ret, inList.Count); // the count in both lists must match Assert.AreEqual(inArray.Length, outArray.Length); // now check each item in the two lists Boolean AreEqual = true; for (int i = 0; i < ret; i++) { if (outArray[i] != inArray[i]) { AreEqual = false; } } Assert.IsTrue(AreEqual); } }