diff options
author | Julien Dessaux | 2021-11-12 15:26:16 +0100 |
---|---|---|
committer | Julien Dessaux | 2021-11-12 15:28:09 +0100 |
commit | c913c2ae46fd81a3274ef16c64c78ea2ed421de8 (patch) | |
tree | c454e21bfe42080fae433eae402b9f3a1c68783a /pkg/stack/stack_test.go | |
parent | Fixed tricky field loading bug (diff) | |
download | gofunge98-c913c2ae46fd81a3274ef16c64c78ea2ed421de8.tar.gz gofunge98-c913c2ae46fd81a3274ef16c64c78ea2ed421de8.tar.bz2 gofunge98-c913c2ae46fd81a3274ef16c64c78ea2ed421de8.zip |
Refactoring : isolate stack manipulation into their own package
Diffstat (limited to 'pkg/stack/stack_test.go')
-rw-r--r-- | pkg/stack/stack_test.go | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/pkg/stack/stack_test.go b/pkg/stack/stack_test.go new file mode 100644 index 0000000..2f15d3a --- /dev/null +++ b/pkg/stack/stack_test.go @@ -0,0 +1,83 @@ +package stack + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestClear(t *testing.T) { + s := NewStack(32, nil) + s.Clear() + require.Equal(t, 0, s.height) +} + +func TestDupicate(t *testing.T) { + expected := NewStack(32, nil) + expected.height = 2 + s := NewStack(32, nil) + s.Duplicate() + require.Equal(t, expected.height, s.height) + s.Push(12) + s.Duplicate() + expected.Push(12) + expected.Push(12) + require.Equal(t, expected.height, s.height) + require.Equal(t, expected.data, s.data) +} + +func TestPop(t *testing.T) { + s := NewStack(32, nil) + v := s.Pop() + require.Equal(t, 0, v) + s.Push(12) + s.Push(14) + v = s.Pop() + require.Equal(t, 14, v) + v = s.Pop() + require.Equal(t, 12, v) + v = s.Pop() + require.Equal(t, 0, v) +} + +func TestPush(t *testing.T) { + s := NewStack(32, nil) + for i := 0; i < 32; i++ { + s.Push(i) + } + require.Equal(t, 32, s.size) + s.Push(-1) + require.Equal(t, 64, s.size) +} + +func TestSwap(t *testing.T) { + s := NewStack(32, nil) + s2 := NewStack(32, nil) + s.Swap() + s2.Push(0) + s2.Push(0) + require.Equal(t, s2, s) + s.Clear() + s.Push(1) + s.Swap() + s2.Clear() + s2.Push(1) + s2.Push(0) + require.Equal(t, s2, s) + s.Clear() + s.Push(1) + s.Push(2) + s2.Clear() + s2.Push(2) + s2.Push(1) + s.Swap() + require.Equal(t, s2, s) +} + +func TestHeights(t *testing.T) { + // TODO +} + +func TestTransfert(t *testing.T) { + // TODO +} |