2019-03-13 04:21:30 +00:00
|
|
|
package lastack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/emirpasic/gods/stacks/arraystack"
|
|
|
|
|
|
|
|
"github.com/Pallinder/go-randomdata"
|
|
|
|
)
|
|
|
|
|
2019-04-02 10:28:41 +00:00
|
|
|
func TestPush(t *testing.T) {
|
|
|
|
s := New()
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
v := randomdata.Number(0, 10)
|
|
|
|
s.Push(v)
|
|
|
|
t.Error(v)
|
|
|
|
t.Error(s.String(), " size ", s.size)
|
|
|
|
}
|
2019-03-13 05:57:08 +00:00
|
|
|
|
2019-04-02 10:28:41 +00:00
|
|
|
t.Error(s.Values())
|
2019-03-13 05:57:08 +00:00
|
|
|
|
2019-04-02 10:28:41 +00:00
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
v, ok := s.Pop()
|
|
|
|
t.Error(v, ok)
|
|
|
|
t.Error(s.String(), " size ", s.size)
|
|
|
|
}
|
2019-03-13 05:57:08 +00:00
|
|
|
|
2019-04-03 10:24:05 +00:00
|
|
|
var l []int
|
|
|
|
|
2019-04-02 10:28:41 +00:00
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
v := randomdata.Number(0, 10)
|
|
|
|
s.Push(v)
|
2019-04-03 10:24:05 +00:00
|
|
|
l = append(l, v)
|
2019-04-02 10:28:41 +00:00
|
|
|
}
|
2019-03-13 05:57:08 +00:00
|
|
|
|
2019-04-02 10:28:41 +00:00
|
|
|
for i := -1; i < 11; i++ {
|
|
|
|
v, ok := s.Get(i)
|
|
|
|
t.Error(v, ok)
|
|
|
|
}
|
2019-04-03 10:24:05 +00:00
|
|
|
t.Error(l)
|
2019-04-02 10:28:41 +00:00
|
|
|
}
|
2019-03-13 04:21:30 +00:00
|
|
|
|
|
|
|
func BenchmarkGet(b *testing.B) {
|
|
|
|
s := New()
|
|
|
|
b.N = 20000000
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
v := randomdata.Number(0, 65535)
|
|
|
|
s.Push(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
b.StartTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
s.Get(i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkPush(b *testing.B) {
|
|
|
|
s := New()
|
2019-03-23 19:11:42 +00:00
|
|
|
b.N = 20000000
|
2019-03-13 04:21:30 +00:00
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
v := randomdata.Number(0, 65535)
|
|
|
|
s.Push(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkGodsPush(b *testing.B) {
|
|
|
|
s := arraystack.New()
|
2019-03-23 19:11:42 +00:00
|
|
|
b.N = 2000000
|
2019-03-13 04:21:30 +00:00
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
v := randomdata.Number(0, 65535)
|
|
|
|
s.Push(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkPop(b *testing.B) {
|
|
|
|
s := New()
|
2019-03-23 19:11:42 +00:00
|
|
|
b.N = 2000000
|
2019-03-13 04:21:30 +00:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
v := randomdata.Number(0, 65535)
|
|
|
|
s.Push(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
b.StartTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
s.Pop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkGodsPop(b *testing.B) {
|
|
|
|
s := arraystack.New()
|
2019-03-23 19:11:42 +00:00
|
|
|
b.N = 2000000
|
2019-03-13 04:21:30 +00:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
v := randomdata.Number(0, 65535)
|
|
|
|
s.Push(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
b.StartTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
s.Pop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkValues(b *testing.B) {
|
|
|
|
s := New()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
v := randomdata.Number(0, 65535)
|
|
|
|
s.Push(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
b.StartTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
s.Values()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkGodsValues(b *testing.B) {
|
|
|
|
s := arraystack.New()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
v := randomdata.Number(0, 65535)
|
|
|
|
s.Push(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
b.StartTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
s.Values()
|
|
|
|
}
|
|
|
|
}
|