tests/testthat/test-playlists.R

context("Video functions")
test_that("dv_video_timing works as expected", {
    skills <- c("Serve", "Reception", "Set", "Attack", "Block", "Dig", "Freeball")
    def_timing <- rep(list(c(-5, 3)), length(skills))
    names(def_timing) <- skills
    expect_identical(dv_video_timing(), def_timing)
    def_timing$Serve <- c(-2, 1)
    def_timing$Dig <- c(-2, 2)
    expect_identical(dv_video_timing(Serve = c(-2, 1), Dig = c(-2, 2)), def_timing)
    expect_warning(dv_video_timing(1), "must be named")
})

test_that("dv_video_playlist works as expected", {
    x <- datavolley::read_dv(datavolley::dv_example_file())
    expect_error(dv_video_playlist(x$plays[10, ], x$meta), "no video for")
    x$meta$video <- data.frame(camera = NA_character_, file = "myvideo.mp4")
    px <- dv_video_playlist(x$plays[10, ], x$meta)
    expect_equal(nrow(px), 1L)
    expect_named(px, c("video_src", "start_time", "duration", "type"))
    expect_true(is.na(px$start_time[1])) ## because this file has no non-NA video_time entries
    x$plays$video_time <- seq_len(nrow(x$plays))
    px <- dv_video_playlist(x$plays[10, ], x$meta)
    expect_equivalent(px, data.frame(video_src = "myvideo.mp4", start_time = 10-5, duration = 8, type = "local", stringsAsFactors = FALSE))
    px <- dv_video_playlist(x$plays[10, ], x$meta, timing = list(Set = c(0, 0)))
    expect_equal(px$start_time, 10)
    expect_equal(px$duration, 0)
    px <- dv_video_playlist(x$plays[1:10, ], x$meta, extra = "player_name")
    expect_equal(nrow(px), sum(!is.na(x$plays$skill[1:10])))
    expect_named(px, c("video_src", "start_time", "duration", "type", "player_name"))
})
scienceuntangled/dvideo documentation built on March 13, 2020, 6:50 p.m.