From 4a094a683d75ddb042e2baddbff62b480347d450 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Mon, 2 Sep 2024 23:43:06 -0500 Subject: [PATCH] test(movie): Improve file load test --- internal/movie/file.go | 2 +- internal/movie/file_test.go | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/internal/movie/file.go b/internal/movie/file.go index d00ec37d..4773c922 100644 --- a/internal/movie/file.go +++ b/internal/movie/file.go @@ -74,7 +74,7 @@ func (m *Movie) LoadFile(path string, src io.Reader, speed float64) error { bar := progressbar.New() totalDuration := m.Duration() - // Build the rest of every frame and write to disk + // Build the rest of every frame var currentPosition time.Duration m.Sections = make([]int, m.Width+1) for i, f := range m.Frames { diff --git a/internal/movie/file_test.go b/internal/movie/file_test.go index 026b78c7..e0a31af0 100644 --- a/internal/movie/file_test.go +++ b/internal/movie/file_test.go @@ -1,6 +1,7 @@ package movie import ( + "slices" "testing" "time" @@ -10,7 +11,7 @@ import ( ) func TestLoadFile(t *testing.T) { - const TestFile = "short_intro.txt" + const TestFile = "sw1.txt" f, err := movies.Movies.Open(TestFile) require.NoError(t, err) @@ -22,6 +23,18 @@ func TestLoadFile(t *testing.T) { require.NoError(t, movie.LoadFile(TestFile, f, 1)) assert.Equal(t, TestFile, movie.Filename) - assert.EqualValues(t, 3*time.Second, movie.Duration().Truncate(time.Second)) - assert.Len(t, movie.Frames, 45) + assert.EqualValues(t, 17*time.Minute+44*time.Second, movie.Duration().Truncate(time.Second)) + assert.Len(t, movie.Frames, 3410) + assert.Equal(t, 67, movie.Width) + assert.Equal(t, 13, movie.Height) + assert.Len(t, movie.Sections, 68) + var current time.Duration + totalDuration := movie.Duration() + for i, frame := range movie.Frames { + current += frame.Duration + if sectionIdx := slices.Index(movie.Sections, i); sectionIdx != -1 { + timeSection := int(current * time.Duration(movie.Width) / totalDuration) + assert.Equal(t, sectionIdx, timeSection) + } + } }