Skip to content

Commit

Permalink
test(movie): Improve file load test
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Sep 3, 2024
1 parent c2f82f2 commit 4a094a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/movie/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 16 additions & 3 deletions internal/movie/file_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package movie

import (
"slices"
"testing"
"time"

Expand All @@ -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)
Expand All @@ -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)
}
}
}

0 comments on commit 4a094a6

Please sign in to comment.