public void PopMany() { var stack = new StackState <DummyValue>(); var values = CreateDummyValues(3); stack.Push(values); Assert.Equal(values.Reverse(), stack.Pop(3)); }
public void PopManyReversed() { var stack = new StackState <DummyValue>(); var values = CreateDummyValues(3); stack.Push(values); Assert.Equal(values, stack.Pop(3, reversed: true)); }
public void FirstIndexShouldReferToTop() { var stack = new StackState <DummyValue>(); var values = CreateDummyValues(3); stack.Push(values); Assert.Same(stack.Top, stack[0]); }
public void Pop() { var stack = new StackState <DummyValue>(); var value = new DummyValue(); stack.Push(value); Assert.Equal(value, stack.Pop()); }
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()); }
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()); }
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()); }
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--; } }
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)); }
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()); }