Exemplo n.º 1
0
        public static void PeekTest()
        {
            var array = new UnmanagedArray <int>(3);

            array[0] = 1;
            array[1] = 2;
            array[2] = 3;

            using (var valueQueue = new UnmanagedValueQueue <int>(array, takeOwnership: true))
            {
                Assert.That(() => valueQueue.Peek(),
                            Is.EqualTo(1)
                            );

                valueQueue.Enqueue(4);

                Assert.That(() => valueQueue.Peek(),
                            Is.EqualTo(1)
                            );

                _ = valueQueue.Dequeue();
                valueQueue.Enqueue(5);

                Assert.That(() => valueQueue.Peek(),
                            Is.EqualTo(2)
                            );

                _ = valueQueue.Dequeue();
                valueQueue.Enqueue(6);
                valueQueue.Enqueue(7);

                Assert.That(() => valueQueue.Peek(),
                            Is.EqualTo(3)
                            );

                Assert.That(() => valueQueue,
                            Has.Property("Capacity").EqualTo((nuint)6)
                            .And.Count.EqualTo((nuint)5)
                            );
            }

            using (var valueQueue = new UnmanagedValueQueue <int>())
            {
                Assert.That(() => valueQueue.Peek(),
                            Throws.InvalidOperationException
                            );
            }
        }
Exemplo n.º 2
0
        public static void PeekNUIntTest()
        {
            var array = new UnmanagedArray <int>(3);

            array[0] = 1;
            array[1] = 2;
            array[2] = 3;

            using (var valueQueue = new UnmanagedValueQueue <int>(array, takeOwnership: true))
            {
                Assert.That(() => valueQueue.Peek(0),
                            Is.EqualTo(1)
                            );

                valueQueue.Enqueue(4);

                Assert.That(() => valueQueue.Peek(0),
                            Is.EqualTo(1)
                            );

                Assert.That(() => valueQueue.Peek(3),
                            Is.EqualTo(4)
                            );

                _ = valueQueue.Dequeue();
                valueQueue.Enqueue(5);

                Assert.That(() => valueQueue.Peek(0),
                            Is.EqualTo(2)
                            );

                Assert.That(() => valueQueue.Peek(1),
                            Is.EqualTo(3)
                            );

                _ = valueQueue.Dequeue();
                valueQueue.Enqueue(6);
                valueQueue.Enqueue(7);

                Assert.That(() => valueQueue.Peek(0),
                            Is.EqualTo(3)
                            );

                Assert.That(() => valueQueue.Peek(2),
                            Is.EqualTo(5)
                            );

                Assert.That(() => valueQueue,
                            Has.Property("Capacity").EqualTo((nuint)6)
                            .And.Count.EqualTo((nuint)5)
                            );
            }

            using (var valueQueue = new UnmanagedValueQueue <int>())
            {
                Assert.That(() => valueQueue.Peek(0),
                            Throws.InstanceOf <ArgumentOutOfRangeException>()
                            .And.Property("ActualValue").EqualTo((nuint)0)
                            .And.Property("ParamName").EqualTo("index")
                            );
            }
        }