expvarmon/stack_test.go

29 lines
514 B
Go
Raw Permalink Normal View History

2015-04-25 14:06:45 +08:00
package main
import "testing"
func TestStack(t *testing.T) {
size := 10
2015-05-01 21:49:19 +08:00
s := NewStackWithSize(size)
2015-04-25 14:06:45 +08:00
for i := 0; i < size+5; i++ {
2016-11-14 04:58:37 +08:00
s.Push(&Number{float64(i), false})
2016-11-11 06:59:32 +08:00
l := len(s.values)
2015-04-25 14:06:45 +08:00
if l < size {
if l != i+1 {
2015-04-25 14:07:33 +08:00
t.Fatalf("len is incorrect. expecting %d, got %d", i, l)
2015-04-25 14:06:45 +08:00
}
} else {
if l != size {
2015-04-25 14:07:33 +08:00
t.Fatalf("len is incorrect. expecting %d, got %d", size, l)
2015-04-25 14:06:45 +08:00
}
}
}
2015-05-01 04:54:54 +08:00
2016-11-11 06:59:32 +08:00
got := s.Values()[9]
if got != 14 {
t.Fatalf("Front returns wrong value: expecting %d, got %d", 14, got)
2015-05-02 14:35:39 +08:00
}
2015-04-25 14:06:45 +08:00
}