-
Notifications
You must be signed in to change notification settings - Fork 1
/
raptordb_test.go
96 lines (77 loc) · 1.83 KB
/
raptordb_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package raptordb
import(
"testing"
"time"
"fmt"
crand "crypto/rand"
"io"
"log"
"os"
"rand"
"encoding/binary"
)
// Test IndexType const value
func TestIndexTypeConstValues(t *testing.T) {
if BTREE != 0 || HASH != 1 {
t.Fail()
}
}
// Test writing 1 mil records
func TestStorageFileForWriting1MilRecords(t *testing.T) {
ns := -time.Nanoseconds()
keySize := 16
storage := NewStorageFile("one_million.dat", keySize)
defer storage.Close()
// storage.SkipDateTime = true;
fmt.Printf("Filename: %v\n", storage.Filename)
for i:= 0; i < 1000000; i++ {
d := []byte("Hello World")
storage.Write(d)
}
storage.Flush()
ns += time.Nanoseconds()
fmt.Printf("Wrote 1 mil records took: %.2f seconds\n", float64(ns)/1e9)
}
// Test timer
func TestTimeModule(t *testing.T) {
ns := -time.Nanoseconds()
time.Sleep(1000000000) // 1 second
ns += time.Nanoseconds()
fmt.Printf("Duration: %.2f seconds\n", float64(ns)/1e9)
}
// Test bytes module
func TestBytesModule(t *testing.T) {
}
// Test rand module
func TestRandModule(t *testing.T) {
rand.Seed(1234567890)
var p int
for i := 0; i < 10; i ++ {
p = rand.Int()
println("Rand.Int() returns ", p)
}
}
func TestStringToByteArray(t *testing.T){
s := "Hello World"
byteArray := []byte(s)
fmt.Printf("StringToByte[]: %v\n",byteArray)
fmt.Printf("IntToByte[]: ")
var d int = 12345
binary.Write(os.Stdout, binary.BigEndian, d)
fmt.Printf("\n")
}
func uuid() string {
b := make([]byte, 16)
_, err := io.ReadFull(crand.Reader, b)
if err != nil {
log.Fatal(err)
}
b[6] = (b[6] & 0x0F) | 0x40
b[8] = (b[8] &^ 0x40) | 0x80
return fmt.Sprintf("%x-%x-%x-%x-%x", b[:4], b[4:6], b[6:8], b[8:10], b[10:])
}
func TestUuid(t *testing.T) {
for i := 0; i < 10; i++ {
fmt.Println(uuid())
}
}