forked from longtao.wu/droboticflow
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestCompactTimelineLosslessFixture(t *testing.T) {
|
|
n := 27001
|
|
l, r := make([]float64, n), make([]float64, n)
|
|
stamps := make([]int64, n)
|
|
left, right := make([]int, n), make([]int, n)
|
|
for i := 0; i < n; i++ {
|
|
left[i] = i
|
|
right[i] = i + i/97
|
|
l[i] = float64(i) * 899.966667 / 27000
|
|
r[i] = float64(right[i]) * 899.966667 / 27279
|
|
stamps[i] = int64(1700000000000000 + i*33333 + i%3)
|
|
}
|
|
v := map[string]any{"frameCount": 27000, "boundariesSeconds": l, "rightBoundariesSeconds": r, "boundaryTimestampUs": stamps, "leftFrameIndices": left, "rightFrameIndices": right, "boundaryContract": "hardware-frame-v1"}
|
|
c, e := compactAnnotationTimeline(v)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
raw, _ := json.Marshal(v)
|
|
packed, _ := json.Marshal(c)
|
|
if len(packed) > len(raw)/3 {
|
|
t.Fatalf("poor compression %d/%d", len(packed), len(raw))
|
|
}
|
|
t.Logf("wire bytes %d -> %d", len(raw), len(packed))
|
|
if path := os.Getenv("ANNOTATION_WIRE_FIXTURE"); path != "" {
|
|
b, _ := json.Marshal(map[string]any{"original": v, "compact": c})
|
|
if e = os.WriteFile(path, b, 0600); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
}
|
|
}
|