Пример #1
0
        public void SegmentsReadyCallbackTest()
        {
            var b = new CoverageCircularBuffer <long>(new [] { 14, 15, 16 }, 10 * 1000, 10, new MillisTimeUtils());

            var called = false;

            b.AddSamples(1000, 14, new double[] { 14, 14, 14, 14 }, (time, count, segments) =>
            {
                called = true;
            });
            Assert.IsFalse(called);

            called = false;
            b.AddSamples(1030, 15, new double[] { 15, 15, 15, 15 }, (time, count, segments) =>
            {
                called = true;
            });
            Assert.IsFalse(called);

            called = false;
            b.AddSamples(1070, 16, new double[] { 16, 16, 16, 16 }, (time, count, segments) =>
            {
                called = true;
                Assert.AreEqual(1070, time);
                Assert.AreEqual(3, count);

                Assert.AreEqual(3, segments.Count);

                for (int i = 0; i < count; ++i)
                {
                    Assert.AreEqual(14, segments[0][i]);
                }

                for (int i = 0; i < count; ++i)
                {
                    Assert.AreEqual(15, segments[1][i]);
                }

                for (int i = 0; i < count; ++i)
                {
                    Assert.AreEqual(16, segments[2][i]);
                }
            });
            Assert.IsTrue(called);
        }
        public void AddValues(TTime time, int channelId, double[] values, Computed <TTime> computed)
        {
            m_coverageCircularBuffer.AddSamples(time, channelId, values,
                                                (t, count, segments) =>
            {
                var computedValues = new double[count];
                for (var i = 0; i < count; i++)
                {
                    var sampleTime = m_timeUtils.IndexToTime(t, i, m_loggedParametersFrequencyInMilliHz);
                    m_context.SetCurrentValue(sampleTime, segments, i);
                    computedValues[i] = m_evaluate();
                }

                computed(t, m_virtualParameterId, computedValues);
            });
        }