- refactor stacks' tests

This commit is contained in:
Emir Pasic
2016-06-24 19:57:54 +02:00
parent a86a65ffaf
commit fe7fb7b07b
2 changed files with 44 additions and 33 deletions
+22 -17
View File
@@ -30,15 +30,11 @@ import (
"testing"
)
func TestArrayStack(t *testing.T) {
func TestStackPush(t *testing.T) {
stack := New()
if actualValue := stack.Empty(); actualValue != true {
t.Errorf("Got %v expected %v", actualValue, true)
}
// insertions
stack.Push(1)
stack.Push(2)
stack.Push(3)
@@ -46,47 +42,57 @@ func TestArrayStack(t *testing.T) {
if actualValue := stack.Values(); actualValue[0].(int) != 3 || actualValue[1].(int) != 2 || actualValue[2].(int) != 1 {
t.Errorf("Got %v expected %v", actualValue, "[3,2,1]")
}
if actualValue := stack.Empty(); actualValue != false {
t.Errorf("Got %v expected %v", actualValue, false)
}
if actualValue := stack.Size(); actualValue != 3 {
t.Errorf("Got %v expected %v", actualValue, 3)
}
if actualValue, ok := stack.Peek(); actualValue != 3 || !ok {
t.Errorf("Got %v expected %v", actualValue, 3)
}
}
func TestStackPeek(t *testing.T) {
stack := New()
if actualValue, ok := stack.Peek(); actualValue != nil || ok {
t.Errorf("Got %v expected %v", actualValue, nil)
}
stack.Push(1)
stack.Push(2)
stack.Push(3)
if actualValue, ok := stack.Peek(); actualValue != 3 || !ok {
t.Errorf("Got %v expected %v", actualValue, 3)
}
}
func TestStackPop(t *testing.T) {
stack := New()
stack.Push(1)
stack.Push(2)
stack.Push(3)
stack.Pop()
if actualValue, ok := stack.Peek(); actualValue != 2 || !ok {
t.Errorf("Got %v expected %v", actualValue, 2)
}
if actualValue, ok := stack.Pop(); actualValue != 2 || !ok {
t.Errorf("Got %v expected %v", actualValue, 2)
}
if actualValue, ok := stack.Pop(); actualValue != 1 || !ok {
t.Errorf("Got %v expected %v", actualValue, 1)
}
if actualValue, ok := stack.Pop(); actualValue != nil || ok {
t.Errorf("Got %v expected %v", actualValue, nil)
}
if actualValue := stack.Empty(); actualValue != true {
t.Errorf("Got %v expected %v", actualValue, true)
}
if actualValue := stack.Values(); len(actualValue) != 0 {
t.Errorf("Got %v expected %v", actualValue, "[]")
}
}
func TestArrayStackIterator(t *testing.T) {
func TestStackIterator(t *testing.T) {
stack := New()
stack.Push("a")
stack.Push("b")
@@ -121,7 +127,7 @@ func TestArrayStackIterator(t *testing.T) {
}
}
func BenchmarkArrayStack(b *testing.B) {
func BenchmarkStack(b *testing.B) {
for i := 0; i < b.N; i++ {
stack := New()
for n := 0; n < 1000; n++ {
@@ -131,5 +137,4 @@ func BenchmarkArrayStack(b *testing.B) {
stack.Pop()
}
}
}