2016-02-03 23:55:33 -08:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2016-03-28 22:16:52 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
2016-02-03 23:55:33 -08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIntegerBigEndian(t *testing.T) {
|
2016-03-28 22:16:52 -07:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
2021-06-29 23:18:58 -04:00
|
|
|
bytes := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
|
2021-06-29 19:34:41 -04:00
|
|
|
integer, err := NewInteger(bytes)
|
|
|
|
assert.Nil(err)
|
2016-03-28 22:16:52 -07:00
|
|
|
|
2021-06-29 19:34:41 -04:00
|
|
|
assert.Equal(integer.Value(), 1, "Integer() did not parse bytes big endian")
|
|
|
|
|
|
|
|
checkbytes := integer.Bytes()
|
|
|
|
|
|
|
|
assert.Equal(bytes, checkbytes, "IntegerBytes() did not match original bytes")
|
2016-02-03 23:55:33 -08:00
|
|
|
}
|
|
|
|
|
2016-03-28 22:16:52 -07:00
|
|
|
func TestWorksWithOneByte(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
2021-06-29 19:34:41 -04:00
|
|
|
bytes := []byte{0x00}
|
|
|
|
integer, err := NewInteger(bytes)
|
|
|
|
assert.Nil(err)
|
2016-03-28 22:16:52 -07:00
|
|
|
|
2021-06-29 19:34:41 -04:00
|
|
|
assert.Equal(integer.Value(), 0, "Integer() did not correctly parse single byte slice")
|
2016-03-28 22:16:52 -07:00
|
|
|
|
2021-06-29 19:34:41 -04:00
|
|
|
checkbytes := integer.Bytes()
|
2016-03-28 22:16:52 -07:00
|
|
|
|
2021-06-29 19:34:41 -04:00
|
|
|
assert.Equal(bytes, checkbytes, "IntegerBytes() did not match original bytes")
|
2016-02-14 22:40:29 -08:00
|
|
|
}
|