Beispiel #1
0
        void RemoveAt_works()
        {
            var instructions = GetInstructions();
            var list         = new InstructionList(instructions);

            Assert.Equal(instructions.Length, list.Count);
            Assert.Equal(instructions.Length, list.Capacity);
            list.RemoveAt(0);
            Assert.Equal(instructions.Length - 1, list.Count);
            Assert.Equal(instructions.Length, list.Capacity);
            list.RemoveAt(list.Count - 1);
            Assert.Equal(instructions.Length - 2, list.Count);
            Assert.Equal(instructions.Length, list.Capacity);
            list.RemoveAt(4);
            Assert.Equal(instructions.Length - 3, list.Count);
            Assert.Equal(instructions.Length, list.Capacity);
            var expected = new Instruction[instructions.Length - 3];

            for (int i = 0, j = 0; i < instructions.Length; i++)
            {
                if (i == 0 || i == instructions.Length - 1 || i == 4 + 1)
                {
                    continue;
                }
                expected[j++] = instructions[i];
            }
            var listElems = new Instruction[list.Count];

            list.CopyTo(listElems);
            AssertEqual(expected, listElems);
        }
Beispiel #2
0
        void RemoveAt_throws_if_invalid_input()
        {
            var             instructions = GetInstructions();
            InstructionList list;

            list = new InstructionList();
            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(GetValue(-1)));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(GetValue(0)));

            list = new InstructionList(instructions);
            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(GetValue(-1)));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(GetValue(int.MinValue)));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(GetValue(int.MaxValue)));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(GetValue(list.Count)));
        }