-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathstack_test.go
54 lines (46 loc) · 1.62 KB
/
stack_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright © 2009-2011 Esko Luontola <www.orfjackal.net>
// This software is released under the Apache License 2.0.
// The license text is at http://www.apache.org/licenses/LICENSE-2.0
package examples
import (
"github.com/orfjackal/gospec/src/gospec"
. "github.com/orfjackal/gospec/src/gospec"
)
// This is the style that I've found the most useful in organizing tests.
// In the parent spec(s) is done some action and then it has multiple child
// specs which each verify one isolated piece of behaviour. Each spec has a
// well though out name which explains the motivation behind the code.
//
// To learn more, see this article and tutorial:
// http://blog.orfjackal.net/2010/02/three-styles-of-naming-tests.html
// http://github.com/orfjackal/tdd-tetris-tutorial
func StackSpec(c gospec.Context) {
stack := NewStack()
c.Specify("An empty stack", func() {
c.Specify("is empty", func() {
c.Expect(stack.Empty(), IsTrue)
})
c.Specify("After a push, the stack is no longer empty", func() {
stack.Push("a push")
c.Expect(stack.Empty(), IsFalse)
})
})
c.Specify("When objects have been pushed onto a stack", func() {
stack.Push("pushed first")
stack.Push("pushed last")
c.Specify("the object pushed last is popped first", func() {
poppedFirst := stack.Pop()
c.Expect(poppedFirst, Equals, "pushed last")
})
c.Specify("the object pushed first is popped last", func() {
stack.Pop()
poppedLast := stack.Pop()
c.Expect(poppedLast, Equals, "pushed first")
})
c.Specify("After popping all objects, the stack is empty", func() {
stack.Pop()
stack.Pop()
c.Expect(stack.Empty(), IsTrue)
})
})
}