Skip to content

Commit f836690

Browse files
authored
test(pkg/store): unit test score serialization and deserialization (#499)
1 parent 58cde22 commit f836690

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

pkg/store/set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func Float642bytes(float float64) []byte {
4141

4242
// Bytes2float ...
4343
func 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
}

pkg/store/set_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ limitations under the License.
1717
package store
1818

1919
import (
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

2528
func 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+
}

0 commit comments

Comments
 (0)