diff options
author | Dimitri Sokolyuk <demon@dim13.org> | 2015-01-09 20:32:18 +0100 |
---|---|---|
committer | Dimitri Sokolyuk <demon@dim13.org> | 2015-01-09 20:32:18 +0100 |
commit | 124868483febccd9fce69c00571b05b16c891613 (patch) | |
tree | 9d322872b422b1ac92bf4df3cfeb6b24b08ed86a | |
parent | 876d05d5764485a42c9dd0f87c242dc8f355523a (diff) |
Remove clutter
-rw-r--r-- | stack.go | 10 | ||||
-rw-r--r-- | stack_test.go | 12 |
2 files changed, 10 insertions, 12 deletions
@@ -15,12 +15,11 @@ func (s *Stack) Push(v interface{}) { } // Pop generic value from Stack -func (s *Stack) Pop() (v interface{}, ok bool) { - size := len(*s) - 1 - if ok = size >= 0; ok { +func (s *Stack) Pop() (v interface{}) { + if size := len(*s) - 1; size >= 0 { v, *s = (*s)[size], (*s)[:size] } - return v, ok + return v } // Peek returns top value from Stack @@ -35,8 +34,7 @@ func (s *Stack) Depth() int { // Swap swapes to top values func (s *Stack) Swap() { - size := len(*s) - if size >= 2 { + if size := len(*s); size >= 2 { (*s)[size-1], (*s)[size-2] = (*s)[size-2], (*s)[size-1] } } diff --git a/stack_test.go b/stack_test.go index dec53cc..e66a3ae 100644 --- a/stack_test.go +++ b/stack_test.go @@ -5,7 +5,7 @@ import "testing" func TestInt(t *testing.T) { s := NewStack() s.Push(1) - i, _ := s.Pop() + i := s.Pop() if i != 1 { t.Error("Expected 1, got ", i) } @@ -14,7 +14,7 @@ func TestInt(t *testing.T) { func TestComplex(t *testing.T) { s := NewStack() s.Push(1+1i) - i, _ := s.Pop() + i := s.Pop() if i != 1+1i { t.Error("Expected 1+1i, got ", i) } @@ -24,11 +24,11 @@ func TestMeny(t *testing.T) { s := NewStack() s.Push(1) s.Push(2) - i, _ := s.Pop() + i := s.Pop() if i != 2 { t.Error("Expected 2, got ", i) } - i, _ = s.Pop() + i = s.Pop() if i != 1 { t.Error("Expected 1, got ", i) } @@ -42,8 +42,8 @@ func TestSwap(t *testing.T) { if s.Depth() != 2 { t.Error("Expected depth of 2") } - a, _ := s.Pop() - b, _ := s.Pop() + a := s.Pop() + b := s.Pop() if s.Depth() != 0 { t.Error("Expected depth of 0") } |