Add deterministic seeds, debug tracing for assignRows cycle detection

This commit is contained in:
Ian Gulliver
2026-02-23 19:06:13 -08:00
parent 6c3eb67fb3
commit 0d77d2d6a1
4 changed files with 134 additions and 46 deletions

View File

@@ -1,13 +1,15 @@
package main
import (
"math/rand/v2"
"os"
"testing"
"time"
)
func TestBuildTimelineFromMockShow(t *testing.T) {
t0 := time.Now()
show := GenerateMockShow(5, 20, 4, 5)
show := GenerateMockShow(rand.Uint64(), 5, 20, 4, 5)
t.Logf("GenerateMockShow: %v (%d blocks, %d triggers)", time.Since(t0), len(show.Blocks), len(show.Triggers))
t1 := time.Now()
@@ -25,8 +27,19 @@ func TestBuildTimelineFromMockShow(t *testing.T) {
t.Logf("tracks=%d blocks=%d", len(tl.Tracks), len(tl.Blocks))
}
func TestBuildTimelineSeed11(t *testing.T) {
show := GenerateMockShow(11, 5, 20, 4, 5)
if err := show.Validate(); err != nil {
t.Fatalf("validate: %v", err)
}
_, err := BuildTimelineDebug(show, os.Stderr)
if err != nil {
t.Fatalf("BuildTimeline failed: %v", err)
}
}
func BenchmarkBuildTimeline(b *testing.B) {
show := GenerateMockShow(5, 20, 4, 5)
show := GenerateMockShow(42, 5, 20, 4, 5)
if err := show.Validate(); err != nil {
b.Fatal(err)
}
@@ -36,34 +49,25 @@ func BenchmarkBuildTimeline(b *testing.B) {
}
}
func TestTimelineOrderDependency(t *testing.T) {
show := &Show{
Tracks: []*Track{
{ID: "T1", Name: "Track 1"},
{ID: "T2", Name: "Track 2"},
},
Blocks: []*Block{
{ID: "B", Type: "media", Track: "T1", Name: "Block B"},
{ID: "A", Type: "media", Track: "T1", Name: "Block A"},
{ID: "C", Type: "media", Track: "T2", Name: "Block C"},
{ID: "C1", Type: "cue", Name: "Cue 1"},
},
Triggers: []*Trigger{
{
Source: TriggerSource{Block: "C1", Signal: "GO"},
Targets: []TriggerTarget{{Block: "A", Hook: "START"}},
},
{
Source: TriggerSource{Block: "A", Signal: "END"},
Targets: []TriggerTarget{{Block: "C", Hook: "START"}},
},
{
Source: TriggerSource{Block: "C", Signal: "END"},
Targets: []TriggerTarget{{Block: "B", Hook: "START"}},
},
},
func TestTimelineShuffle(t *testing.T) {
show := GenerateMockShow(rand.Uint64(), 5, 20, 4, 5)
var cues []*Block
var others []*Block
for _, b := range show.Blocks {
if b.Type == "cue" {
cues = append(cues, b)
} else {
others = append(others, b)
}
}
rand.Shuffle(len(others), func(i, j int) {
others[i], others[j] = others[j], others[i]
})
show.Blocks = append(cues, others...)
if err := show.Validate(); err != nil {
t.Fatalf("Validate failed: %v", err)
}