github.com/simpleiot/simpleiot@v0.18.3/modbus/data_test.go (about) 1 package modbus 2 3 import ( 4 "testing" 5 ) 6 7 func TestUint32(t *testing.T) { 8 v := uint32(412345623) 9 10 regs := Uint32ToRegs([]uint32{v}) 11 12 v2 := RegsToUint32(regs) 13 14 if v != v2[0] { 15 t.Error("Failed: ", v, v2[0]) 16 } 17 } 18 19 func TestInt32(t *testing.T) { 20 v := int32(-412345623) 21 22 regs := Int32ToRegs([]int32{v}) 23 24 v2 := RegsToInt32(regs) 25 26 if v != v2[0] { 27 t.Error("Failed: ", v, v2[0]) 28 } 29 } 30 31 func TestFloat32(t *testing.T) { 32 v := float32(2124.23e18) 33 34 regs := Float32ToRegs([]float32{v}) 35 36 v2 := RegsToFloat32(regs) 37 38 if v != v2[0] { 39 t.Error("Failed: ", v, v2[0]) 40 } 41 } 42 43 func TestRegsToFloat32SwapWords(t *testing.T) { 44 exp := float32(0.01) 45 46 f := RegsToFloat32SwapWords([]uint16{0xd70a, 0x3c23}) 47 48 if exp != f[0] { 49 t.Error("Failed: ", exp, f) 50 } 51 }