2019-02-27 21:38:39 +00:00
|
|
|
package stack
|
|
|
|
|
|
|
|
import (
|
2019-02-28 13:51:02 +00:00
|
|
|
"bytes"
|
|
|
|
"encoding/binary"
|
2019-02-27 21:38:39 +00:00
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
// helper functions
|
|
|
|
func testPeakInteger(t *testing.T, tStack *RandomAccess, n uint16) *Int {
|
|
|
|
stackElement, err := tStack.Peek(n)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
item, err := stackElement.Integer()
|
|
|
|
if err != nil {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
return item
|
|
|
|
}
|
|
|
|
|
|
|
|
func testPopInteger(t *testing.T, tStack *RandomAccess) *Int {
|
|
|
|
stackElement, err := tStack.Pop()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
item, err := stackElement.Integer()
|
|
|
|
if err != nil {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
return item
|
|
|
|
}
|
|
|
|
|
|
|
|
func testMakeStackInt(t *testing.T, num int64) *Int {
|
|
|
|
a, err := NewInt(big.NewInt(num))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
return a
|
|
|
|
}
|
2019-02-28 13:51:02 +00:00
|
|
|
|
|
|
|
func testReadInt64(data []byte) int64 {
|
|
|
|
var ret int64
|
|
|
|
buf := bytes.NewBuffer(data)
|
|
|
|
binary.Read(buf, binary.LittleEndian, &ret)
|
|
|
|
return ret
|
|
|
|
}
|
2019-04-02 20:38:41 +00:00
|
|
|
|
|
|
|
func testMakeStackMap(t *testing.T, m map[Item]Item) *Map {
|
|
|
|
a, err := NewMap(m)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
|
|
|
func testArray(t *testing.T, m map[Item]Item) *Map {
|
|
|
|
a, err := NewMap(m)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
return a
|
|
|
|
}
|