/// <summary> /// Class constructor. /// In accord with the COM callable wrapper, this constructor can not take any parameters, /// and there can be no other constructors besides this one. /// </summary> public ComTSLibrary() { // The ComTSLibrary class wraps an instance of the TSLibrary class TSLib = new TSLibrary(); // This class's ConnxObject field is simply a reference to the ConnxObject // field in the TSLibrary object that this class wraps. ConnxObject = TSLib.ConnxObject; }
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 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 maximum number of time steps to put into the series // 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) { 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); }
// 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); }
// 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; }
// 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; }
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); } }