optimize build size by avoiding fmt,

pack lo/hi values into Wavefront
This commit is contained in:
2024-11-12 18:44:12 +00:00
parent a878da42a3
commit 6f78825876
5 changed files with 96 additions and 66 deletions

View File

@@ -12,6 +12,7 @@ import (
wfa "wfa/pkg"
"github.com/schollz/progressbar/v3"
"golang.org/x/exp/constraints"
)
const testJsonPath = "tests.json"
@@ -29,14 +30,14 @@ type TestCase struct {
Solutions string `json:"solutions"`
}
func randRange(min, max int) uint32 {
return uint32(rand.IntN(max-min) + min)
func randRange[T constraints.Integer](min, max int) T {
return T(rand.IntN(max-min) + min)
}
func TestWavefrontPacking(t *testing.T) {
for range 1000 {
val := randRange(0, 1000)
tb := wfa.Traceback(randRange(0, 7))
val := randRange[uint32](0, 1000)
tb := wfa.Traceback(randRange[uint32](0, 7))
v := wfa.PackWavefrontValue(val, tb)
valid, gotVal, gotTB := wfa.UnpackWavefrontValue(v)
@@ -47,6 +48,20 @@ func TestWavefrontPacking(t *testing.T) {
}
}
func TestLoHiPacking(t *testing.T) {
for range 1000 {
lo := randRange[int](-1000, 1000)
hi := randRange[int](-1000, 1000)
v := wfa.PackWavefrontLoHi(lo, hi)
gotLo, gotHi := wfa.UnpackWavefrontLoHi(v)
if gotLo != lo || gotHi != hi {
t.Errorf(`test WavefrontPack/Unpack, lo: %d, hi: %d, packedval: %x, gotlo: %d, gothi: %d`, lo, hi, v, gotLo, gotHi)
}
}
}
func GetScoreFromCIGAR(CIGAR string, penalties wfa.Penalty) int {
unpackedCIGAR := wfa.RunLengthDecode(CIGAR)
previousOp := '~'