package main import ( "math/rand/v2" "testing" "time" ) func TestBuildTimelineFromMockShow(t *testing.T) { t0 := time.Now() 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() if err := show.Validate(); err != nil { t.Fatalf("generated show failed validation: %v", err) } t.Logf("Validate: %v", time.Since(t1)) t2 := time.Now() tl, err := BuildTimeline(show) t.Logf("BuildTimeline: %v", time.Since(t2)) if err != nil { t.Fatalf("BuildTimeline failed: %v", err) } t.Logf("tracks=%d blocks=%d", len(tl.Tracks), len(tl.Blocks)) } func BenchmarkBuildTimeline(b *testing.B) { show := GenerateMockShow(42, 5, 20, 4, 5) if err := show.Validate(); err != nil { b.Fatal(err) } b.ResetTimer() for range b.N { BuildTimeline(show) } } 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) } _, err := BuildTimeline(show) if err != nil { t.Fatalf("BuildTimeline failed: %v", err) } }