Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        void CopyTo_works_2()
        {
            var i     = GetInstructions();
            var list  = new InstructionList(i);
            var array = new Instruction[i.Length];

            list.CopyTo(0, array, 0, array.Length);
            Assert.Equal(i, array);
        }
Ejemplo n.º 3
0
        void RemoveRange_works(int index, int count, InstructionList list, Instruction[] expected)
        {
            list.RemoveRange(index, count);
            Assert.Equal(expected.Length, list.Count);
            Assert.True(expected.Length <= list.Capacity);
            var listElems = new Instruction[list.Count];

            list.CopyTo(listElems);
            AssertEqual(expected, listElems);
        }
Ejemplo n.º 4
0
        void AddRange_works(InstructionList list, IEnumerable <Instruction> inserted, Instruction[] expected)
        {
            list.AddRange(inserted);
            Assert.Equal(expected.Length, list.Count);
            Assert.True(expected.Length <= list.Capacity);
            var listElems = new Instruction[list.Count];

            list.CopyTo(listElems);
            AssertEqual(expected, listElems);
        }
Ejemplo n.º 5
0
        void Ctor_array(Instruction[] instructions)
        {
            var list = new InstructionList(instructions);

            Assert.Equal(instructions.Length, list.Count);
            Assert.Equal(instructions.Length, list.Capacity);
            var listElems = new Instruction[list.Count];

            list.CopyTo(listElems);
            AssertEqual(instructions, listElems);
        }
Ejemplo n.º 6
0
        void Remove_works(Instruction[] data, Instruction instr, bool expected, Instruction[] expectedData)
        {
            var list   = new InstructionList(data);
            var result = list.Remove(instr);

            Assert.Equal(expected, result);
            var listElems = new Instruction[list.Count];

            list.CopyTo(listElems);
            AssertEqual(expectedData, listElems);
        }
Ejemplo n.º 7
0
        void Ctor_IEnumerable(Instruction[] instructions)
        {
            var list = new InstructionList(instructions.AsEnumerable());

            Assert.Equal(instructions.Length, list.Count);
            Assert.True(instructions.Length <= list.Capacity);
            var listElems = new Instruction[list.Count];

            list.CopyTo(listElems);
            AssertEqual(instructions, listElems);
        }
Ejemplo n.º 8
0
        void AllocUninitializedElement_works()
        {
            var instructions = GetInstructions();
            var list         = new InstructionList();

            for (int i = 0; i < instructions.Length; i++)
            {
                list.AllocUninitializedElement() = instructions[i];
                Assert.Equal(i + 1, list.Count);
                Assert.True(i < list.Capacity);
                var listElems = new Instruction[list.Count];
                list.CopyTo(listElems);
                AssertEqual(instructions, listElems, listElems.Length);
            }
        }
Ejemplo n.º 9
0
        void CopyTo_works_1()
        {
            var i     = GetInstructions();
            var list  = new InstructionList(i);
            var array = new Instruction[5];

            array[0] = Instruction.Create(Code.Nopd);
            array[4] = Instruction.Create(Code.Nopq);
            var expected = new Instruction[5] {
                Instruction.Create(Code.Nopd),
                i[2],
                i[3],
                i[4],
                Instruction.Create(Code.Nopq),
            };

            list.CopyTo(2, array, 1, 3);
            Assert.Equal(expected, array);
        }
Ejemplo n.º 10
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);
        }