2018-03-02 15:24:09 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestArrayReverse(t *testing.T) {
|
2019-02-05 12:22:10 +00:00
|
|
|
arr := []byte{0x01, 0x02, 0x03, 0x04, 0x05}
|
2018-03-02 15:24:09 +00:00
|
|
|
have := ArrayReverse(arr)
|
2019-02-05 12:22:10 +00:00
|
|
|
want := []byte{0x05, 0x04, 0x03, 0x02, 0x01}
|
2019-02-19 13:22:33 +00:00
|
|
|
if !bytes.Equal(have, want) {
|
2018-03-02 15:24:09 +00:00
|
|
|
t.Fatalf("expected %v got %v", want, have)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-09 15:53:58 +00:00
|
|
|
// This tests a bug that occurred with arrays of size 1
|
2018-03-02 15:24:09 +00:00
|
|
|
func TestArrayReverseLen2(t *testing.T) {
|
|
|
|
arr := []byte{0x01}
|
|
|
|
have := ArrayReverse(arr)
|
|
|
|
want := []byte{0x01}
|
2019-02-19 13:22:33 +00:00
|
|
|
if !bytes.Equal(have, want) {
|
2018-03-02 15:24:09 +00:00
|
|
|
t.Fatalf("expected %v got %v", want, have)
|
|
|
|
}
|
|
|
|
}
|