Ejemplo n.º 1
0
        void Insert_throws_if_invalid_input()
        {
            InstructionList list;

            list = new InstructionList();
            Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(GetValue(-1), Instruction.Create(Code.Nopd)));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(GetValue(1), Instruction.Create(Code.Nopd)));

            list = new InstructionList(GetInstructions());
            Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(GetValue(-1), Instruction.Create(Code.Nopd)));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(GetValue(int.MinValue), Instruction.Create(Code.Nopd)));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(GetValue(int.MaxValue), Instruction.Create(Code.Nopd)));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(GetValue(list.Count + 1), Instruction.Create(Code.Nopd)));
        }
Ejemplo n.º 2
0
        void Insert_works()
        {
            var instructions = GetInstructions();
            var list         = new InstructionList();

            Assert.Equal(0, list.Count);
            Assert.Equal(0, list.Capacity);
            list.Insert(0, instructions[0]);
            Assert.Equal(1, list.Count);
            Assert.True(1 <= list.Capacity);
            list.Insert(1, instructions[1]);
            Assert.Equal(2, list.Count);
            Assert.True(2 <= list.Capacity);
            list.Insert(0, instructions[2]);
            Assert.Equal(3, list.Count);
            Assert.True(3 <= list.Capacity);
            list.Insert(1, instructions[3]);
            Assert.Equal(4, list.Count);
            Assert.True(4 <= list.Capacity);
            list.Insert(3, instructions[4]);
            Assert.Equal(5, list.Count);
            Assert.True(5 <= list.Capacity);
            list.Insert(5, instructions[5]);
            Assert.Equal(6, list.Count);
            Assert.True(6 <= list.Capacity);
            var expected = new Instruction[] {
                instructions[2],
                instructions[3],
                instructions[0],
                instructions[4],
                instructions[1],
                instructions[5],
            };
            var listElems = new Instruction[list.Count];

            list.CopyTo(listElems);
            AssertEqual(expected, listElems);
        }