public void TestQueue()
        {
            var queue = new IndexedQueue <int>(new int[] { 1, 2, 3 });

            queue.Count.Should().Be(3);

            queue.Enqueue(4);
            queue.Count.Should().Be(4);
            queue.Peek().Should().Be(1);
            queue.TryPeek(out var a).Should().BeTrue();
            a.Should().Be(1);

            queue[0].Should().Be(1);
            queue[1].Should().Be(2);
            queue[2].Should().Be(3);
            queue.Dequeue().Should().Be(1);
            queue.Dequeue().Should().Be(2);
            queue.Dequeue().Should().Be(3);
            queue[0] = 5;
            queue.TryDequeue(out a).Should().BeTrue();
            a.Should().Be(5);

            queue.Enqueue(4);
            queue.Clear();
            queue.Count.Should().Be(0);
        }
        public void TestDefault()
        {
            var queue = new IndexedQueue <int>(10);

            queue.Count.Should().Be(0);

            queue = new IndexedQueue <int>();
            queue.Count.Should().Be(0);
            queue.TrimExcess();
            queue.Count.Should().Be(0);

            queue = new IndexedQueue <int>(Array.Empty <int>());
            queue.Count.Should().Be(0);
            queue.TryPeek(out var a).Should().BeFalse();
            a.Should().Be(0);
            queue.TryDequeue(out a).Should().BeFalse();
            a.Should().Be(0);

            Assert.ThrowsException <InvalidOperationException>(() => queue.Peek());
            Assert.ThrowsException <InvalidOperationException>(() => queue.Dequeue());
            Assert.ThrowsException <IndexOutOfRangeException>(() => _         = queue[-1]);
            Assert.ThrowsException <IndexOutOfRangeException>(() => queue[-1] = 1);
            Assert.ThrowsException <IndexOutOfRangeException>(() => _         = queue[1]);
            Assert.ThrowsException <IndexOutOfRangeException>(() => queue[1]  = 1);
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => new IndexedQueue <int>(-1));
        }
        public static double CalculateLatency(ref IndexedQueue<LatencySample> samples)
        {
            // There can only be marzullo!
            LatencyTuple[] table;

            GetLatencyTable (5, ref samples, out table);
            SortLatencyTable (ref table);

            int best = 0; // largest number of overlapping intervals found
            int count = 0; // Current number of overlapping intervals
            LatencyTuple bestStart = table[0]; // The beginning of the best interval
            LatencyTuple bestEnd = table[0]; // The end of the best interval

            for (int i = 0; i < table.Length; i++)
            {
                count -= table[i].Type;

                if (count > best)
                {
                    best = count;
                    bestStart = table[i];
                    bestEnd = table[i + 1];
                }
            }

            return (bestStart.Offset + bestEnd.Offset) / 2;
        }
Exemple #4
0
        public CincoUser()
        {
            TickRate = 66;
            UpdateRate = 66;
            TimeSyncRate = 0.5f;

            latencySamples = new IndexedQueue<LatencySample> (10);
        }
        public void TestEnumerator()
        {
            int[] arr = new int[3] {
                1, 2, 3
            };
            var queue = new IndexedQueue <int>(arr);

            arr.SequenceEqual(queue).Should().BeTrue();
        }
        private static void GetLatencyTable(int sampleCount, ref IndexedQueue<LatencySample> samples, out LatencyTuple[] table)
        {
            table = new LatencyTuple[sampleCount * 2];

            for (int i = 0; i < 5; i+=2)
            {
                LatencySample sample = samples[i];
                table[i] = new LatencyTuple (sample.LowValue, -1);
                table[i+1] = new LatencyTuple (sample.HighValue, +1);
            }
        }
        public void TestCopyTo()
        {
            int[] arr   = new int[3];
            var   queue = new IndexedQueue <int>(new int[] { 1, 2, 3 });

            Assert.ThrowsException <ArgumentNullException>(() => queue.CopyTo(null, 0));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => queue.CopyTo(arr, -1));
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => queue.CopyTo(arr, 2));

            queue.CopyTo(arr, 0);

            arr[0].Should().Be(1);
            arr[1].Should().Be(2);
            arr[2].Should().Be(3);

            arr = queue.ToArray();

            arr[0].Should().Be(1);
            arr[1].Should().Be(2);
            arr[2].Should().Be(3);
        }