Skip to content
This repository was archived by the owner on Feb 13, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ func (stack *Stack) Push(s string) {

// Pop do pop from the top of stack and remove it.
func (stack *Stack) Pop() string {
if len(*stack) == 0 {
return ""
}
ret := (*stack)[len(*stack)-1]
*stack = (*stack)[:len(*stack)-1]
return ret
Expand Down
70 changes: 70 additions & 0 deletions stack_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package stack

import (
"reflect"
"testing"
)

func TestPush(t *testing.T) {
s := Stack{}
s.Push("foo")
s.Push("bar")

want := Stack([]string{"foo", "bar"})
if !reflect.DeepEqual(s, want) {
// TODO: more detail message
t.Error("error")
return
}
}

func TestPop(t *testing.T) {
s := Stack([]string{"foo", "bar"})
t.Run("pop 1", func(t *testing.T) {
got := s.Pop()
wantVal := "bar"
if got != wantVal {
// TODO: more detail message
t.Error("error on 1 val")
return
}
want := Stack([]string{"foo"})
if !reflect.DeepEqual(s, want) {
// TODO: more detail message
t.Error("error on 1")
return
}
})

t.Run("pop 2", func(t *testing.T) {
got := s.Pop()
wantVal := "foo"
if got != wantVal {
// TODO: more detail message
t.Error("error on 2 val")
return
}
want := Stack{}
if !reflect.DeepEqual(s, want) {
// TODO: more detail message
t.Error("error on 2")
return
}
})

t.Run("pop 3", func(t *testing.T) {
got := s.Pop()
wantVal := ""
if got != wantVal {
// TODO: more detail message
t.Error("error on 3 val")
return
}
want := Stack{}
if !reflect.DeepEqual(s, want) {
// TODO: more detail message
t.Error("error on 3")
return
}
})
}