public void SelectorThrowsWhenEndEqualsOrLessThanStart()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         RangeSelector.GetRange(_fixture.SampleEvents1.Buckets, 1, 1);
     });
     Assert.Throws <ArgumentException>(() =>
     {
         RangeSelector.GetRange(_fixture.SampleEvents1.Buckets, 2, 1);
     });
 }
        public void SelectorReturnsCorrectNearestEvent(long start, long end, long expectedNearestEventTime)
        {
            var   buckets = _fixture.SampleEvents1.Buckets;
            Range range   = RangeSelector.GetRange(buckets, start, end);

            Assert.False(range.IsFound);
            Assert.True(range.IsNearestEventFound);

            Bucket bucket = buckets[range.NearestBucketIndex];

            Assert.Equal(expectedNearestEventTime, bucket.GetAbsoluteTimeForEvent(range.NearestEventIndex));
        }
        /// <summary>
        /// Selects all buckets that are related to the given interval
        /// </summary>
        /// <param name="start">Start time (inclusive)</param>
        /// <param name="end">End time (exclusive)</param>
        /// <returns>All the buckets that were found</returns>
        public Bucket[] GetBuckets(long start, long end)
        {
            var range = RangeSelector.GetRange(Buckets, start, end);

            if (!range.IsFound)
            {
                throw new RangeNotFoundException();
            }

            var slice = new Bucket[range.Length];

            Array.Copy(Buckets, range.FirstBucketIndex, slice, 0, range.Length);
            return(slice);
        }
        public void SelectorReturnsBoundaryEvents(long start, long end)
        {
            var   buckets = _fixture.SampleEvents1.Buckets;
            Range range   = RangeSelector.GetRange(buckets, start, end);

            Assert.True(range.IsFound);

            Bucket firstBucket = buckets[range.FirstBucketIndex];

            Assert.Equal(start, firstBucket.GetAbsoluteTimeForEvent(range.FirstEventIndex));

            Bucket lastBucket = buckets[range.LastBucketIndex];

            Assert.Equal(end - 1, lastBucket.GetAbsoluteTimeForEvent(range.LastEventIndex));
        }
        public void RangeIsNotFoundWhenBucketsArrayIsEmpty()
        {
            Range range = RangeSelector.GetRange(Array.Empty <Bucket>(), 0, long.MaxValue);

            Assert.False(range.IsFound);
        }