update readme
This commit is contained in:
parent
e0df3df127
commit
3771637d65
|
@ -49,7 +49,7 @@ func main() {
|
|||
|
||||
// Print: hello bar world
|
||||
for i := 0; i < q.Len(); i++ {
|
||||
fmt.Print(q.PeekAt(i), " ")
|
||||
fmt.Print(q.Peek(i), " ")
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
|
|
@ -346,6 +346,16 @@ func TestInsert(t *testing.T) {
|
|||
if q.Peek(5) != "x" {
|
||||
t.Error("expected x at position 5")
|
||||
}
|
||||
|
||||
q.Insert(0, "b")
|
||||
if q.Front() != "b" {
|
||||
t.Error("expected b inserted at front")
|
||||
}
|
||||
|
||||
q.Insert(q.Len(), "e")
|
||||
if q.Back() != "e" {
|
||||
t.Error("expected e inserted at back")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemove(t *testing.T) {
|
||||
|
@ -375,6 +385,14 @@ func TestRemove(t *testing.T) {
|
|||
if q.Peek(4) != "G" {
|
||||
t.Error("expected G at position 4")
|
||||
}
|
||||
|
||||
if q.Remove(0) != "A" {
|
||||
t.Error("expected to remove A from front")
|
||||
}
|
||||
|
||||
if q.Remove(q.Len()-1) != "G" {
|
||||
t.Error("expected to remove G from back")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPeekOutOfRangePanics(t *testing.T) {
|
||||
|
@ -444,6 +462,42 @@ func TestPopBackOutOfRangePanics(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestInsertOutOfRangePanics(t *testing.T) {
|
||||
var q Deque
|
||||
|
||||
assertPanics(t, "should panic when inserting out of range", func() {
|
||||
q.Insert(1, "X")
|
||||
})
|
||||
|
||||
q.PushBack("A")
|
||||
|
||||
assertPanics(t, "should panic when inserting at negative index", func() {
|
||||
q.Insert(-1, "Y")
|
||||
})
|
||||
|
||||
assertPanics(t, "should panic when inserting out of range", func() {
|
||||
q.Insert(2, "B")
|
||||
})
|
||||
}
|
||||
|
||||
func TestRemoveOutOfRangePanics(t *testing.T) {
|
||||
var q Deque
|
||||
|
||||
assertPanics(t, "should panic when removing from empty queue", func() {
|
||||
q.Remove(0)
|
||||
})
|
||||
|
||||
q.PushBack("A")
|
||||
|
||||
assertPanics(t, "should panic when removing at negative index", func() {
|
||||
q.Remove(-1)
|
||||
})
|
||||
|
||||
assertPanics(t, "should panic when removing out of range", func() {
|
||||
q.Remove(1)
|
||||
})
|
||||
}
|
||||
|
||||
func assertPanics(t *testing.T, name string, f func()) {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
|
|
|
@ -4,7 +4,7 @@ set -e
|
|||
echo "" > coverage.txt
|
||||
|
||||
for d in $(go list ./... | grep -v vendor); do
|
||||
go test -race -coverprofile=profile.out -covermode=atomic $d
|
||||
go test -coverprofile=profile.out -covermode=atomic $d
|
||||
if [ -f profile.out ]; then
|
||||
cat profile.out >> coverage.txt
|
||||
rm profile.out
|
||||
|
|
Loading…
Reference in a new issue