File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ func Float642bytes(float float64) []byte {
4141
4242// Bytes2float ...
4343func Bytes2float (bytes []byte ) float64 {
44- bits := binary .LittleEndian .Uint64 (bytes )
44+ bits := binary .BigEndian .Uint64 (bytes )
4545 float := math .Float64frombits (bits )
4646 return float
4747}
Original file line number Diff line number Diff line change @@ -17,9 +17,12 @@ limitations under the License.
1717package store
1818
1919import (
20+ "math/rand"
21+ "testing"
22+ "time"
23+
2024 "github.com/codenotary/immudb/pkg/api/schema"
2125 "github.com/stretchr/testify/assert"
22- "testing"
2326)
2427
2528func TestStoreIndexExists (t * testing.T ) {
@@ -92,3 +95,17 @@ func TestStoreIndexExists(t *testing.T) {
9295 assert .Equal (t , []byte (`myThirdElementKey` ), itemList2 .Items [1 ].Key )
9396 assert .Equal (t , []byte (`mySecondElementKey` ), itemList2 .Items [2 ].Key )
9497}
98+
99+ func TestFloat (t * testing.T ) {
100+ s := rand .NewSource (time .Now ().UnixNano ())
101+ r := rand .New (s )
102+
103+ for i := 0 ; i < 100 ; i ++ {
104+ n := r .Float64 ()
105+ bs := Float642bytes (n )
106+ assert .NotNil (t , bs )
107+ assert .True (t , len (bs ) == 8 )
108+ assert .Equal (t , n , Bytes2float (bs ))
109+ }
110+
111+ }
You can’t perform that action at this time.
0 commit comments