major optimization by packing wavefront values

This commit is contained in:
2024-11-05 18:28:28 +00:00
parent 8679c51fb0
commit 3da3ddf10c
6 changed files with 154 additions and 146 deletions

View File

@@ -3,6 +3,7 @@ package tests
import (
"bufio"
"encoding/json"
"math/rand/v2"
"os"
"strconv"
"strings"
@@ -27,6 +28,24 @@ type TestCase struct {
Solutions string `json:"solutions"`
}
func randRange(min, max int) uint32 {
return uint32(rand.IntN(max-min) + min)
}
func TestWavefrontPacking(t *testing.T) {
for range 1000 {
val := randRange(0, 1000)
tb := wfa.Traceback(randRange(0, 7))
v := wfa.PackWavefrontValue(val, tb)
valid, gotVal, gotTB := wfa.UnpackWavefrontValue(v)
if !valid || gotVal != val || gotTB != tb {
t.Errorf(`test WavefrontPack/Unpack, val: %d, tb: %d, packedval: %x, gotok: %t, gotval: %d, gottb: %d\n`, val, tb, v, valid, gotVal, gotTB)
}
}
}
func TestWFA(t *testing.T) {
content, _ := os.ReadFile(testJsonPath)