diff options
Diffstat (limited to '')
-rw-r--r-- | pkg/pointer/stack-stack.go (renamed from pkg/stack/stack-stack.go) | 18 | ||||
-rw-r--r-- | pkg/pointer/stack-stack_test.go (renamed from pkg/stack/stack-stack_test.go) | 39 | ||||
-rw-r--r-- | pkg/pointer/stack.go (renamed from pkg/stack/stack.go) | 2 | ||||
-rw-r--r-- | pkg/pointer/stack_test.go (renamed from pkg/stack/stack_test.go) | 2 |
4 files changed, 37 insertions, 24 deletions
diff --git a/pkg/stack/stack-stack.go b/pkg/pointer/stack-stack.go index 9b80079..6d22f51 100644 --- a/pkg/stack/stack-stack.go +++ b/pkg/pointer/stack-stack.go @@ -1,8 +1,4 @@ -package stack - -import ( - "git.adyxax.org/adyxax/gofunge/pkg/pointer" -) +package pointer type StackStack struct { head *Stack @@ -16,7 +12,7 @@ func NewStackStack() *StackStack { } } -func (ss *StackStack) Begin(p *pointer.Pointer) { +func (ss *StackStack) Begin(p *Pointer) { ss.height++ soss := ss.head n := soss.Pop() @@ -44,7 +40,7 @@ func (ss *StackStack) Begin(p *pointer.Pointer) { p.CalculateNewStorageOffset() } -func (ss *StackStack) End(p *pointer.Pointer) (reflect bool) { +func (ss *StackStack) End(p *Pointer) (reflect bool) { if ss.height == 1 { return true } @@ -89,3 +85,11 @@ func (ss *StackStack) Under() (reflect bool) { } return false } + +func (ss StackStack) Pop() int { + return ss.head.Pop() +} + +func (ss StackStack) Push(v int) { + ss.head.Push(v) +} diff --git a/pkg/stack/stack-stack_test.go b/pkg/pointer/stack-stack_test.go index d2a7949..fd4c9ea 100644 --- a/pkg/stack/stack-stack_test.go +++ b/pkg/pointer/stack-stack_test.go @@ -1,11 +1,10 @@ -package stack +package pointer import ( "os" "testing" "git.adyxax.org/adyxax/gofunge/pkg/field" - "git.adyxax.org/adyxax/gofunge/pkg/pointer" "github.com/stretchr/testify/require" ) @@ -17,7 +16,7 @@ func TestBegin(t *testing.T) { expected.head.next.Push(0) expected.height++ ss := NewStackStack() - p := pointer.NewPointer() + p := NewPointer() ss.Begin(p) require.Equal(t, expected, ss) x, y := p.GetStorageOffset() @@ -40,7 +39,7 @@ func TestBegin(t *testing.T) { expected.head.next.Push(0) expected.head.next.Push(0) expected.height++ - p := pointer.NewPointer() + p := NewPointer() file, err := os.Open("../field/test_data/hello.b98") require.NoError(t, err, "Failed to open file") f, err := field.Load(file) @@ -61,7 +60,7 @@ func TestBegin(t *testing.T) { expected.head.next.Push(2) expected.head.next.Push(3) expected.height++ - p := pointer.NewPointer() + p := NewPointer() p.SetStorageOffset(2, 3) file, err := os.Open("../field/test_data/hello.b98") require.NoError(t, err, "Failed to open file") @@ -87,7 +86,7 @@ func TestBegin(t *testing.T) { expected.head.next.Push(36) expected.head.next.Push(42) expected.height++ - p := pointer.NewPointer() + p := NewPointer() p.SetStorageOffset(36, 42) ss := NewStackStack() ss.head.Push(7) @@ -104,7 +103,7 @@ func TestBegin(t *testing.T) { func TestEnd(t *testing.T) { t.Run("empty", func(t *testing.T) { expected := NewStackStack() - p := pointer.NewPointer() + p := NewPointer() ss := NewStackStack() ss.Begin(p) reflect := ss.End(p) @@ -121,7 +120,7 @@ func TestEnd(t *testing.T) { expected.head.Pop() expected.head.Pop() expected.head.Pop() - p := pointer.NewPointer() + p := NewPointer() ss := NewStackStack() ss.head.Push(7) ss.head.Push(12) @@ -139,7 +138,7 @@ func TestEnd(t *testing.T) { }) t.Run("drop too much", func(t *testing.T) { expected := NewStackStack() - p := pointer.NewPointer() + p := NewPointer() ss := NewStackStack() ss.Begin(p) ss.head.Push(-3) @@ -149,7 +148,7 @@ func TestEnd(t *testing.T) { }) t.Run("reflect", func(t *testing.T) { expected := NewStackStack() - p := pointer.NewPointer() + p := NewPointer() ss := NewStackStack() reflect := ss.End(p) require.Equal(t, true, reflect) @@ -164,7 +163,7 @@ func TestEnd(t *testing.T) { expected.head.Push(14) expected.head.Push(-2) expected.head.Push(5) - p := pointer.NewPointer() + p := NewPointer() ss := NewStackStack() ss.head.size = 4 ss.head.data = make([]int, 4) @@ -195,7 +194,7 @@ func TestUnder(t *testing.T) { require.Equal(t, expected, ss) }) t.Run("positive", func(t *testing.T) { - pe := pointer.NewPointer() + pe := NewPointer() expected := NewStackStack() expected.head.Push(1) expected.head.Push(2) @@ -209,7 +208,7 @@ func TestUnder(t *testing.T) { expected.head.next.Pop() expected.head.next.Pop() expected.head.next.Pop() - p := pointer.NewPointer() + p := NewPointer() ss := NewStackStack() ss.head.Push(1) ss.head.Push(2) @@ -223,7 +222,7 @@ func TestUnder(t *testing.T) { require.Equal(t, expected, ss) }) t.Run("negative", func(t *testing.T) { - pe := pointer.NewPointer() + pe := NewPointer() expected := NewStackStack() expected.Begin(pe) expected.head.next.Push(12) @@ -237,7 +236,7 @@ func TestUnder(t *testing.T) { expected.head.Pop() expected.head.Pop() expected.head.Pop() - p := pointer.NewPointer() + p := NewPointer() ss := NewStackStack() ss.Begin(p) ss.head.Push(8) @@ -249,3 +248,13 @@ func TestUnder(t *testing.T) { require.Equal(t, expected, ss) }) } + +func TestPushPop(t *testing.T) { + ss := NewStackStack() + ss.Push(12) + ss.Push(5) + v := ss.Pop() + require.Equal(t, 5, v) + v = ss.Pop() + require.Equal(t, 12, v) +} diff --git a/pkg/stack/stack.go b/pkg/pointer/stack.go index 4dbb72c..1832dbb 100644 --- a/pkg/stack/stack.go +++ b/pkg/pointer/stack.go @@ -1,4 +1,4 @@ -package stack +package pointer type Stack struct { size int diff --git a/pkg/stack/stack_test.go b/pkg/pointer/stack_test.go index e48c615..1b16085 100644 --- a/pkg/stack/stack_test.go +++ b/pkg/pointer/stack_test.go @@ -1,4 +1,4 @@ -package stack +package pointer import ( "testing" |