Пример #1
0
        public void AddRemove()
        {
            var a = new TestInt();

            a.CheckList();
            Assert.Throws <IndexOutOfRangeException>(() => a.RemoveAt(-1));
            Assert.Throws <IndexOutOfRangeException>(() => a.RemoveAt(0));
            Assert.Throws <IndexOutOfRangeException>(() => a.RemoveAt(1));

            a.Add(204);
            a.CheckList();
            Assert.Throws <IndexOutOfRangeException>(() => a.RemoveAt(-1));
            Assert.Throws <IndexOutOfRangeException>(() => a.RemoveAt(1));

            a.RemoveAt(0);
            Assert.That(a.Count, Is.EqualTo(0));
            a.CheckList();

            a.Add(206);
            a.Add(205);
            a.Add(204);
            CheckList(a, 204, 205, 206);

            a.RemoveAt(1);
            CheckList(a, 204, 206);
            Assert.Throws <IndexOutOfRangeException>(() => a.RemoveAt(2));
            a.RemoveAt(1);
            CheckList(a, 204);
            a.RemoveAt(0);
            CheckList(a);

            a.Add(206);
            a.Add(205);
            a.Add(204);
            a.Add(207);
            a.Add(208);
            CheckList(a, 204, 205, 206, 207, 208);
            Assert.Throws <IndexOutOfRangeException>(() => a.RemoveAt(5));
            a.RemoveAt(0);
            CheckList(a, 205, 206, 207, 208);
            a.RemoveAt(3);
            CheckList(a, 205, 206, 207);
            a.RemoveAt(1);
            CheckList(a, 205, 207);
            a.RemoveAt(1);
            CheckList(a, 205);
            a.RemoveAt(0);
            CheckList(a);
        }
Пример #2
0
        public void testing_add_and_remove_items()
        {
            var a = new TestInt();

            a.CheckList();
            a.Invoking(sut => sut.RemoveAt(-1)).Should().Throw <IndexOutOfRangeException>();
            a.Invoking(sut => sut.RemoveAt(0)).Should().Throw <IndexOutOfRangeException>();
            a.Invoking(sut => sut.RemoveAt(1)).Should().Throw <IndexOutOfRangeException>();

            a.Remove(-1).Should().BeFalse();
            a.Remove(0).Should().BeFalse();
            a.Remove(1).Should().BeFalse();

            a.Add(204);
            a.CheckList();
            a.Invoking(sut => sut.RemoveAt(-1)).Should().Throw <IndexOutOfRangeException>();
            a.Invoking(sut => sut.RemoveAt(1)).Should().Throw <IndexOutOfRangeException>();

            a.RemoveAt(0);
            a.Count.Should().Be(0);
            a.CheckList();

            a.Add(206);
            a.Add(205);
            a.Add(204);
            CheckList(a, 204, 205, 206);

            a.RemoveAt(1);
            CheckList(a, 204, 206);
            a.Invoking(sut => sut.RemoveAt(2)).Should().Throw <IndexOutOfRangeException>();
            a.RemoveAt(1);
            CheckList(a, 204);
            a.RemoveAt(0);
            CheckList(a);

            a.Add(206);
            a.Add(205);
            a.Add(204);
            a.Add(207);
            a.Add(208);
            CheckList(a, 204, 205, 206, 207, 208);
            a.Invoking(sut => sut.RemoveAt(5)).Should().Throw <IndexOutOfRangeException>();
            a.RemoveAt(0);
            CheckList(a, 205, 206, 207, 208);
            a.RemoveAt(3);
            CheckList(a, 205, 206, 207);
            a.RemoveAt(1);
            CheckList(a, 205, 207);
            a.RemoveAt(1);
            CheckList(a, 205);
            a.RemoveAt(0);
            CheckList(a);

            a.Add(206);
            a.Add(205);
            a.Add(204);
            a.Add(207);
            a.Add(208);
            CheckList(a, 204, 205, 206, 207, 208);
            a.Remove(203).Should().BeFalse();
            CheckList(a, 204, 205, 206, 207, 208);
            a.Remove(204).Should().BeTrue();
            CheckList(a, 205, 206, 207, 208);
            a.Remove(208).Should().BeTrue();
            CheckList(a, 205, 206, 207);
            a.Remove(208).Should().BeFalse();
            CheckList(a, 205, 206, 207);
            a.Remove(206).Should().BeTrue();
            CheckList(a, 205, 207);
            a.Remove(207).Should().BeTrue();
            CheckList(a, 205);
            a.Remove(205).Should().BeTrue();
            CheckList(a);
        }
Пример #3
0
        public void testing_add_and_remove_items()
        {
            var a = new TestInt();

            a.CheckList();
            Assert.Throws <IndexOutOfRangeException>(() => a.RemoveAt(-1));
            Assert.Throws <IndexOutOfRangeException>(() => a.RemoveAt(0));
            Assert.Throws <IndexOutOfRangeException>(() => a.RemoveAt(1));

            Assert.That(a.Remove(-1), Is.False);
            Assert.That(a.Remove(0), Is.False);
            Assert.That(a.Remove(1), Is.False);

            a.Add(204);
            a.CheckList();
            Assert.Throws <IndexOutOfRangeException>(() => a.RemoveAt(-1));
            Assert.Throws <IndexOutOfRangeException>(() => a.RemoveAt(1));

            a.RemoveAt(0);
            Assert.That(a.Count, Is.EqualTo(0));
            a.CheckList();

            a.Add(206);
            a.Add(205);
            a.Add(204);
            CheckList(a, 204, 205, 206);

            a.RemoveAt(1);
            CheckList(a, 204, 206);
            Assert.Throws <IndexOutOfRangeException>(() => a.RemoveAt(2));
            a.RemoveAt(1);
            CheckList(a, 204);
            a.RemoveAt(0);
            CheckList(a);

            a.Add(206);
            a.Add(205);
            a.Add(204);
            a.Add(207);
            a.Add(208);
            CheckList(a, 204, 205, 206, 207, 208);
            Assert.Throws <IndexOutOfRangeException>(() => a.RemoveAt(5));
            a.RemoveAt(0);
            CheckList(a, 205, 206, 207, 208);
            a.RemoveAt(3);
            CheckList(a, 205, 206, 207);
            a.RemoveAt(1);
            CheckList(a, 205, 207);
            a.RemoveAt(1);
            CheckList(a, 205);
            a.RemoveAt(0);
            CheckList(a);

            a.Add(206);
            a.Add(205);
            a.Add(204);
            a.Add(207);
            a.Add(208);
            CheckList(a, 204, 205, 206, 207, 208);
            Assert.That(a.Remove(203), Is.False);
            CheckList(a, 204, 205, 206, 207, 208);
            Assert.That(a.Remove(204), Is.True);
            CheckList(a, 205, 206, 207, 208);
            Assert.That(a.Remove(208), Is.True);
            CheckList(a, 205, 206, 207);
            Assert.That(a.Remove(208), Is.False);
            CheckList(a, 205, 206, 207);
            Assert.That(a.Remove(206), Is.True);
            CheckList(a, 205, 207);
            Assert.That(a.Remove(207), Is.True);
            CheckList(a, 205);
            Assert.That(a.Remove(205), Is.True);
            CheckList(a);
        }