aboutsummaryrefslogtreecommitdiff
path: root/pkg/stack/stack-stack_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/stack/stack-stack_test.go')
-rw-r--r--pkg/stack/stack-stack_test.go149
1 files changed, 149 insertions, 0 deletions
diff --git a/pkg/stack/stack-stack_test.go b/pkg/stack/stack-stack_test.go
index 6c0c47f..d2a7949 100644
--- a/pkg/stack/stack-stack_test.go
+++ b/pkg/stack/stack-stack_test.go
@@ -100,3 +100,152 @@ func TestBegin(t *testing.T) {
require.Equal(t, expected, ss)
})
}
+
+func TestEnd(t *testing.T) {
+ t.Run("empty", func(t *testing.T) {
+ expected := NewStackStack()
+ p := pointer.NewPointer()
+ ss := NewStackStack()
+ ss.Begin(p)
+ reflect := ss.End(p)
+ require.Equal(t, false, reflect)
+ require.Equal(t, expected, ss)
+ })
+ t.Run("drop", func(t *testing.T) {
+ expected := NewStackStack()
+ expected.head.Push(7)
+ expected.head.Push(12)
+ expected.head.Push(14)
+ expected.head.Push(-2)
+ expected.head.Push(5)
+ expected.head.Pop()
+ expected.head.Pop()
+ expected.head.Pop()
+ p := pointer.NewPointer()
+ ss := NewStackStack()
+ ss.head.Push(7)
+ ss.head.Push(12)
+ ss.head.Push(14)
+ ss.head.Push(-2)
+ ss.head.Push(5)
+ ss.head.Push(0)
+ ss.Begin(p)
+ ss.head.Push(18)
+ ss.head.Push(42)
+ ss.head.Push(-3)
+ reflect := ss.End(p)
+ require.Equal(t, false, reflect)
+ require.Equal(t, expected, ss)
+ })
+ t.Run("drop too much", func(t *testing.T) {
+ expected := NewStackStack()
+ p := pointer.NewPointer()
+ ss := NewStackStack()
+ ss.Begin(p)
+ ss.head.Push(-3)
+ reflect := ss.End(p)
+ require.Equal(t, false, reflect)
+ require.Equal(t, expected, ss)
+ })
+ t.Run("reflect", func(t *testing.T) {
+ expected := NewStackStack()
+ p := pointer.NewPointer()
+ ss := NewStackStack()
+ reflect := ss.End(p)
+ require.Equal(t, true, reflect)
+ require.Equal(t, expected, ss)
+ })
+ t.Run("transfert", func(t *testing.T) {
+ expected := NewStackStack()
+ expected.head.size = 5
+ expected.head.data = make([]int, 5)
+ expected.head.Push(7)
+ expected.head.Push(12)
+ expected.head.Push(14)
+ expected.head.Push(-2)
+ expected.head.Push(5)
+ p := pointer.NewPointer()
+ ss := NewStackStack()
+ ss.head.size = 4
+ ss.head.data = make([]int, 4)
+ ss.head.Push(7)
+ ss.head.Push(0)
+ ss.Begin(p)
+ ss.head.Push(0)
+ ss.head.Push(18)
+ ss.head.Push(42)
+ ss.head.Push(7)
+ ss.head.Push(12)
+ ss.head.Push(14)
+ ss.head.Push(-2)
+ ss.head.Push(5)
+ ss.head.Push(4)
+ reflect := ss.End(p)
+ require.Equal(t, false, reflect)
+ require.Equal(t, expected, ss)
+ })
+}
+
+func TestUnder(t *testing.T) {
+ t.Run("empty", func(t *testing.T) {
+ expected := NewStackStack()
+ ss := NewStackStack()
+ reflect := ss.Under()
+ require.Equal(t, true, reflect)
+ require.Equal(t, expected, ss)
+ })
+ t.Run("positive", func(t *testing.T) {
+ pe := pointer.NewPointer()
+ expected := NewStackStack()
+ expected.head.Push(1)
+ expected.head.Push(2)
+ expected.head.Push(3)
+ expected.head.Push(6)
+ expected.head.Push(0)
+ expected.Begin(pe)
+ expected.head.Push(0)
+ expected.head.Push(0)
+ expected.head.Push(6)
+ expected.head.next.Pop()
+ expected.head.next.Pop()
+ expected.head.next.Pop()
+ p := pointer.NewPointer()
+ ss := NewStackStack()
+ ss.head.Push(1)
+ ss.head.Push(2)
+ ss.head.Push(3)
+ ss.head.Push(6)
+ ss.head.Push(0)
+ ss.Begin(p)
+ ss.head.Push(3)
+ reflect := ss.Under()
+ require.Equal(t, false, reflect)
+ require.Equal(t, expected, ss)
+ })
+ t.Run("negative", func(t *testing.T) {
+ pe := pointer.NewPointer()
+ expected := NewStackStack()
+ expected.Begin(pe)
+ expected.head.next.Push(12)
+ expected.head.next.Push(5)
+ expected.head.next.Push(8)
+ expected.head.Push(8)
+ expected.head.Push(5)
+ expected.head.Push(12)
+ expected.head.Push(-3)
+ expected.head.Pop()
+ expected.head.Pop()
+ expected.head.Pop()
+ expected.head.Pop()
+ p := pointer.NewPointer()
+ ss := NewStackStack()
+ ss.Begin(p)
+ ss.head.Push(8)
+ ss.head.Push(5)
+ ss.head.Push(12)
+ ss.head.Push(-3)
+ reflect := ss.Under()
+ require.Equal(t, false, reflect)
+ require.Equal(t, expected, ss)
+ })
+}