Beispiel #1
0
        public void PopMany()
        {
            var stack  = new StackState <DummyValue>();
            var values = CreateDummyValues(3);

            stack.Push(values);
            Assert.Equal(values.Reverse(), stack.Pop(3));
        }
Beispiel #2
0
        public void PopManyReversed()
        {
            var stack  = new StackState <DummyValue>();
            var values = CreateDummyValues(3);

            stack.Push(values);
            Assert.Equal(values, stack.Pop(3, reversed: true));
        }
Beispiel #3
0
        public void FirstIndexShouldReferToTop()
        {
            var stack  = new StackState <DummyValue>();
            var values = CreateDummyValues(3);

            stack.Push(values);
            Assert.Same(stack.Top, stack[0]);
        }
Beispiel #4
0
        public void Pop()
        {
            var stack = new StackState <DummyValue>();
            var value = new DummyValue();

            stack.Push(value);
            Assert.Equal(value, stack.Pop());
        }
Beispiel #5
0
        public void PushManyReversed()
        {
            var stack  = new StackState <DummyValue>();
            var values = CreateDummyValues(3);

            stack.Push(values, reversed: true);
            Assert.Equal(3, stack.Size);
            Assert.Equal(values.First(), stack.Top);
            Assert.Equal(values, stack.GetAllStackSlots());
        }
Beispiel #6
0
        public void Push()
        {
            var stack = new StackState <DummyValue>();
            var value = new DummyValue();

            stack.Push(value);
            Assert.Equal(1, stack.Size);
            Assert.Equal(value, stack.Top);
            Assert.Single(stack.GetAllStackSlots());
        }
Beispiel #7
0
        public void Copy()
        {
            var stack = new StackState <DummyValue>();

            stack.Push(CreateDummyValues(3));

            var copy = stack.Copy();

            Assert.Equal(stack.Top, copy.Top);
            Assert.Equal(stack.Size, copy.Size);
            Assert.Equal(stack.GetAllStackSlots(), copy.GetAllStackSlots());
        }
Beispiel #8
0
        public void MergeMultiple()
        {
            var sources = new[]
            {
                new[]
                {
                    CreateDummyNode(0),
                    CreateDummyNode(1)
                },
                new[]
                {
                    CreateDummyNode(2),
                    CreateDummyNode(3),
                },
                new[]
                {
                    CreateDummyNode(4),
                    CreateDummyNode(5),
                }
            };

            var stack1  = new StackState <SymbolicValue <DummyInstruction> >();
            var values1 = new[]
            {
                new SymbolicValue <DummyInstruction>(sources[0][0]),
                new SymbolicValue <DummyInstruction>(sources[1][0]),
                new SymbolicValue <DummyInstruction>(sources[2][0]),
            };

            stack1.Push(values1);

            var stack2  = new StackState <SymbolicValue <DummyInstruction> >();
            var values2 = new[]
            {
                new SymbolicValue <DummyInstruction>(sources[0][1]),
                new SymbolicValue <DummyInstruction>(sources[1][1]),
                new SymbolicValue <DummyInstruction>(sources[2][1]),
            };

            stack2.Push(values2);

            Assert.True(stack1.MergeWith(stack2));

            int index = sources.Length - 1;

            foreach (var slot in stack1.GetAllStackSlots())
            {
                Assert.Equal(new HashSet <DataFlowNode <DummyInstruction> >(sources[index]), slot.GetNodes());
                index--;
            }
        }
Beispiel #9
0
        public void MergeStackImbalance()
        {
            var stack1 = new StackState <SymbolicValue <DummyInstruction> >();

            stack1.Push(new[]
            {
                new SymbolicValue <DummyInstruction>(),
                new SymbolicValue <DummyInstruction>(),
            });

            var stack2 = new StackState <SymbolicValue <DummyInstruction> >();

            stack2.Push(new[]
            {
                new SymbolicValue <DummyInstruction>(),
            });

            Assert.Throws <StackImbalanceException>(() => stack1.MergeWith(stack2));
        }
Beispiel #10
0
        public void MergeSingle()
        {
            var sources = new[]
            {
                CreateDummyNode(0), CreateDummyNode(1),
            };

            var stack1 = new StackState <SymbolicValue <DummyInstruction> >();
            var value1 = new SymbolicValue <DummyInstruction>(sources[0]);

            stack1.Push(value1);

            var stack2 = new StackState <SymbolicValue <DummyInstruction> >();
            var value2 = new SymbolicValue <DummyInstruction>(sources[1]);

            stack2.Push(value2);

            Assert.True(stack1.MergeWith(stack2));
            Assert.Equal(new HashSet <DataFlowNode <DummyInstruction> >(sources), stack1.Top.GetNodes());
        }