Esempio n. 1
0
        public void TestRemoveRange()
        {
            var a = new PtrArray <OpaqueInt> ();

            a.Add(_(1));
            a.Add(_(2));
            a.Add(_(3));
            a.Add(_(4));
            a.Add(_(5));
            a.Add(_(6));
            Assume.That(a.Count, Is.EqualTo(6));

            a.RemoveRange(0, 0);
            Assert.That(a.Count, Is.EqualTo(6));

            a.RemoveRange(1, 2);
            Assert.That(a.Count, Is.EqualTo(4));
            Assert.That(getItemAt(a, 0), Is.EqualTo(_(1)));
            Assert.That(getItemAt(a, 1), Is.EqualTo(_(4)));
            Assert.That(getItemAt(a, 2), Is.EqualTo(_(5)));
            Assert.That(getItemAt(a, 3), Is.EqualTo(_(6)));

            Assert.That(() => a.RemoveRange(-1, 0), Throws.TypeOf <ArgumentOutOfRangeException> ());
            Assert.That(() => a.RemoveRange(0, -1), Throws.TypeOf <ArgumentOutOfRangeException> ());
            Assert.That(() => a.RemoveRange(3, 4), Throws.TypeOf <ArgumentException> ());

            a.Dispose();
            Assert.That(() => a.RemoveRange(0, 0), Throws.TypeOf <ObjectDisposedException> ());

            Utility.AssertNoGLibLog();
        }
Esempio n. 2
0
        public void TestSetSize()
        {
            var a = new PtrArray <OpaqueInt> ();

            Assume.That(a.Count, Is.EqualTo(0));

            a.SetSize(5);
            Assert.That(a.Count, Is.EqualTo(5));

            a.Dispose();
            Assert.That(() => a.SetSize(0), Throws.TypeOf <ObjectDisposedException> ());

            Utility.AssertNoGLibLog();
        }
Esempio n. 3
0
        public void TestSort()
        {
            var a = new PtrArray <OpaqueInt> ();

            a.Add(_(3));
            a.Add(_(1));
            a.Add(_(2));
            Assume.That(getItemAt(a, 0), Is.EqualTo(_(3)));
            Assume.That(getItemAt(a, 1), Is.EqualTo(_(1)));
            Assume.That(getItemAt(a, 2), Is.EqualTo(_(2)));

            a.Sort((x, y) => x.Value - y.Value);
            Assert.That(getItemAt(a, 0), Is.EqualTo(_(1)));
            Assert.That(getItemAt(a, 1), Is.EqualTo(_(2)));
            Assert.That(getItemAt(a, 2), Is.EqualTo(_(3)));

            Assert.That(() => a.Sort(null), Throws.TypeOf <ArgumentNullException> ());

            a.Dispose();
            Assert.That(() => a.Sort((x, y) => 0), Throws.TypeOf <ObjectDisposedException> ());

            Utility.AssertNoGLibLog();
        }
Esempio n. 4
0
        public void TestRemoveFast()
        {
            var a = new PtrArray <OpaqueInt> ();

            Assume.That(a.Count, Is.EqualTo(0));

            Assert.That(a.RemoveFast(_(0)), Is.False);
            Assert.That(a.Count, Is.EqualTo(0));

            a.Add(_(1));
            Assume.That(a.Count, Is.EqualTo(1));

            Assert.That(a.RemoveFast(_(0)), Is.False);
            Assert.That(a.Count, Is.EqualTo(1));
            Assert.That(a.RemoveFast(_(1)), Is.True);
            Assert.That(a.Count, Is.EqualTo(0));

            a.Add(_(1));
            a.Add(_(2));
            a.Add(_(3));
            a.Add(_(4));
            Assume.That(a.Count, Is.EqualTo(4));

            Assert.That(a.RemoveFast(_(0)), Is.False);
            Assert.That(a.Count, Is.EqualTo(4));
            Assert.That(a.RemoveFast(_(2)), Is.True);
            Assert.That(a.Count, Is.EqualTo(3));
            Assert.That(getItemAt(a, 0), Is.EqualTo(_(1)));
            Assert.That(getItemAt(a, 1), Is.EqualTo(_(4)));
            Assert.That(getItemAt(a, 2), Is.EqualTo(_(3)));

            a.Dispose();
            Assert.That(() => a.RemoveFast(_(0)), Throws.TypeOf <ObjectDisposedException> ());

            Utility.AssertNoGLibLog();
        }