public void TestIntTimeSeriesStreamCollectionCreateModifyWriteReadModify() { List <int?> addValues1 = new List <int?>() { 1, 3, 5, 3, 1, null, null, null, null, null }; List <int?> addValues2 = new List <int?>() { null, null, null, null, null, 21, 23, 25, 23, 21 }; var allValues = addValues1.Zip(addValues2, (x, y) => x ?? y).ToList(); // Create var timeseriesCollectionOrig = new TimeSeriesStreamCollection <Guid, int>(guids, guidSize, writeGuid, span); // Modify foreach (var item in timeseriesCollectionOrig) { for (int i = 0; i < Math.Min(addValues1.Count, item.Value.Count); i++) { if (addValues1[i].HasValue) { item.Value[i] = addValues1[i]; } } } // Write var compressed = timeseriesCollectionOrig.ToCompressedByteArray(); // Read var timeseriesCollectionRead = new TimeSeriesStreamCollection <Guid, int>(compressed, guidSize, readGuid, span); // Modify foreach (var item in timeseriesCollectionRead) { for (int i = 0; i < Math.Min(addValues2.Count, item.Value.Count); i++) { if (addValues2[i].HasValue) { item.Value[i] = addValues2[i]; } } } // Assert foreach (var item in timeseriesCollectionRead) { Assert.Equal(allValues, item.Value.Select(x => x.Value).Take(allValues.Count).ToList()); } }
public void TestIntTimeSeriesStreamCollectionIndexers() { var timeseriesCollection = new TimeSeriesStreamCollection <Guid, int>(guids, guidSize, writeGuid, span); List <ITimeSeries <int> > timeseries = new List <ITimeSeries <int> >(); int i = 0; foreach (var item in timeseriesCollection) { timeseries.Add(item.Value); // make sure the order and contents of keys are the same as in the original key list Assert.Equal(item.Key, guids[i]); i++; } // make sure the same object is returned by the indexer as by the Enumerable Assert.Same(timeseries[0], timeseriesCollection[guids[0]]); Assert.Same(timeseries[1], timeseriesCollection[guids[1]]); }
public void TestIntTimeSeriesCompression() { var timeseriesCollection = new TimeSeriesStreamCollection <byte, int>( new List <byte>() { 0x01 }, 1, (b, stream) => stream.WriteByte(b), span); var timeseries = timeseriesCollection[0x01]; timeseries[0] = 1; timeseries[3] = 23; timeseries[5] = 42; timeseries[7] = 43; timeseries[9] = 99; var compressor = new TimeSeriesCompressor <byte, int>(timeseriesCollection); var compressedBytes = compressor.ToCompressedByteArray(); var expected = new byte[] { 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x63, 0x64, 0x60, 0x60, 0x60, 0x04, 0x42, 0x10, 0x10, 0x03, 0x62, 0x61, 0x30, 0x9f, 0x81, 0xc1, 0xe2, 0x3f, 0x58, 0x08, 0x0d, 0x0c, 0x46, 0x41, 0x00, 0xb3, 0x3c, 0x5f, 0x36, 0xc2, 0x00, 0x00, 0x00 }; Assert.Equal(expected, compressedBytes); }