-
Notifications
You must be signed in to change notification settings - Fork 0
/
astrobwt_test.go
123 lines (103 loc) · 2.59 KB
/
astrobwt_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package astrobwt
import (
"math/rand"
"testing"
)
// see https://www.geeksforgeeks.org/burrows-wheeler-data-transform-algorithm/
func TestBWTAndInverseTransform(t *testing.T) {
tests := []struct {
input string
bwt string
}{
{"BANANA", "ANNB$AA"}, // from https://www.geeksforgeeks.org/burrows-wheeler-data-transform-algorithm/
{"abracadabra", "ard$rcaaaabb"},
{"appellee", "e$elplepa"},
{"GATGCGAGAGATG", "GGGGGGTCAA$TAA"},
{"abcdefg", "g$abcdef"},
}
for _, test := range tests {
trans2, eos := BWT([]byte(test.input))
trans2[eos] = '$'
if string(trans2) != test.bwt {
t.Errorf("Test failed: Transform %s", test.input)
}
if string(InverseTransform([]byte(trans2), '$')) != test.input {
t.Errorf("Test failed: InverseTransform expected '%s' actual '%s`", test.input, string(InverseTransform([]byte(trans2), '$')))
}
p := POW([]byte(test.input))
p0 := POW_0alloc([]byte(test.input))
if string(p[:]) != string(p0[:]) {
t.Error("Test failed: difference between pow and pow_0alloc")
}
}
}
func TestFromSuffixArray(t *testing.T) {
s := "GATGCGAGAGATG"
trans := "GGGGGGTCAA$TAA"
sa := SuffixArray([]byte(s))
B, err := FromSuffixArray([]byte(s), sa, '$')
if err != nil {
t.Error("Test failed: FromSuffixArray error")
}
if string(B) != trans {
t.Error("Test failed: FromSuffixArray returns wrong result")
}
}
func TestPow_Powalloc(t *testing.T) {
p := POW([]byte{0, 0, 0, 0})
p0 := POW_0alloc([]byte{0, 0, 0, 0})
if string(p[:]) != string(p0[:]) {
t.Error("Test failed: POW and POW_0alloc returns different ")
}
}
var cases [][]byte
func init() {
rand.Seed(1)
alphabet := "abcdefghjijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
n := len(alphabet)
_ = n
scales := []int{100000}
cases = make([][]byte, len(scales))
for i, scale := range scales {
l := scale
buf := make([]byte, int(l))
for j := 0; j < int(l); j++ {
buf[j] = byte(rand.Uint32() & 0xff) //alphabet[rand.Intn(n)]
}
cases[i] = buf
}
POW([]byte{0x99})
}
var result []byte
func BenchmarkTransform(t *testing.B) {
var r []byte
var err error
for i := 0; i < t.N; i++ {
r, err = Transform(cases[0], '$')
if err != nil {
t.Error(err)
return
}
}
result = r
}
func BenchmarkTransform_quick(t *testing.B) {
var r []byte
for i := 0; i < t.N; i++ {
//r, err = Transform(cases[0], '$')
r, _ = BWT(cases[0])
}
result = r
}
func BenchmarkPOW(t *testing.B) {
for i := 0; i < t.N; i++ {
rand.Read(cases[0][:])
_ = POW(cases[0][:])
}
}
func BenchmarkPOW_0alloc(t *testing.B) {
for i := 0; i < t.N; i++ {
rand.Read(cases[0][:])
_ = POW_0alloc(cases[0][:])
}
}