github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/binary/le_test.go (about) 1 package binary 2 3 import "testing" 4 5 func TestLittleEndian_Uint16(t *testing.T) { 6 var expected uint16 = 0x0b0a 7 if got := LittleEndian.Uint16([]byte{0x0a, 0x0b}); got != expected { 8 t.Errorf("LittleEndian.Uint16(): got %x, want %x", got, expected) 9 } 10 } 11 12 func TestLittleEndian_Uint32(t *testing.T) { 13 var expected uint32 = 0x0d0c0b0a 14 if got := LittleEndian.Uint32([]byte{0x0a, 0x0b, 0x0c, 0x0d}); got != expected { 15 t.Errorf("LittleEndian.Uint32(): got %x, want %x", got, expected) 16 } 17 } 18 19 func TestLittleEndian_Uint64(t *testing.T) { 20 var expected uint64 = 0x0f0e0d0c0b0a0908 21 if got := LittleEndian.Uint64([]byte{0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}); got != expected { 22 t.Errorf("LittleEndian.Uint64(): got %x, want %x", got, expected) 23 } 24 } 25 26 func TestLittleEndian_PutUint16(t *testing.T) { 27 var got [2]byte 28 var expected = [2]byte{0x0b, 0x0a} 29 if LittleEndian.PutUint16(got[:], 0x0a0b); got != expected { 30 t.Errorf("LittleEndian.PutUint16(): got %x, want %x", got, expected) 31 } 32 } 33 34 func TestLittleEndian_PutUint32(t *testing.T) { 35 var got [4]byte 36 var expected = [4]byte{0x0d, 0x0c, 0x0b, 0x0a} 37 if LittleEndian.PutUint32(got[:], 0x0a0b0c0d); got != expected { 38 t.Errorf("LittleEndian.PutUint32(): got %x, want %x", got, expected) 39 } 40 } 41 42 func TestLittleEndian_PutUint64(t *testing.T) { 43 var got [8]byte 44 var expected = [8]byte{0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08} 45 if LittleEndian.PutUint64(got[:], 0x08090a0b0c0d0e0f); got != expected { 46 t.Errorf("LittleEndian.PutUint64(): got %x, want %x", got, expected) 47 } 48 }