context("Performance Stats Preparation")
library(podlover)
t_exmpl <- t_exmpl
# prepare for tests
t_perf_1 <- podlove_performance_stats(df_tidy_data = t_exmpl,
launch = Inf,
post_launch = 0,
limit_unit = "days")
t_perf_2 <- podlove_performance_stats(df_tidy_data = t_exmpl,
launch = 3,
post_launch = 30,
limit_unit = "days")
t_perf_3 <- podlove_performance_stats(df_tidy_data = t_exmpl,
launch = 72,
post_launch = 720,
limit_unit = "hours")
# generated by dput(object)
r_dls <- c(643L, 696L, 763L, 674L, 544L, 321L, 260L, 200L, 136L, 73L)
r_dlspd <- c(1.62784810126582, 1.88660492432799, 2.22557122022363, 2.31847498925039,
2.28052401746725, 2.39106145251397, 2.40277242972661, 2.43531202435312,
2.42676579925651, 2.43333333333333)
r2_dlpdat <- c(113.828571428571, 138.086956521739, 147.380281690141, 127.2,
101.746478873239, 64.8, 55.5223880597015, 46.8571428571429, 26.4,
15.887323943662)
r2_dlpdaft <- c(0.716455696202532, 0.677659814772984, 0.714632960622265, 0.598538053604701,
0.633013100436681, 0.581005586592179, 0.582210242587601, 0.353120243531202,
0.588847583643123, 0.0333333333333333)
# tests
test_that("dimensions of dfs are correct", {
expect_equal(nrow(t_perf_1), 10)
expect_equal(nrow(t_perf_2), 10)
expect_equal(nrow(t_perf_3), 10)
expect_equal(ncol(t_perf_1), 7)
expect_equal(ncol(t_perf_2), 7)
expect_equal(ncol(t_perf_3), 7)
})
test_that("col names of dfs are correct", {
cnam <- function(df, i) {
nams <- colnames(df)
nams[i]
}
expect_equal(cnam(t_perf_1, 1), "ep_number")
expect_equal(cnam(t_perf_1, 2), "title")
expect_equal(cnam(t_perf_1, 3), "ep_num_title")
expect_equal(cnam(t_perf_1, 4), "dls")
expect_equal(cnam(t_perf_1, 5), "dls_per_day")
expect_equal(cnam(t_perf_1, 6), "dls_per_day_at_launch")
expect_equal(cnam(t_perf_1, 7), "dls_per_day_after_launch")
expect_equal(cnam(t_perf_2, 1), "ep_number")
expect_equal(cnam(t_perf_2, 2), "title")
expect_equal(cnam(t_perf_2, 3), "ep_num_title")
expect_equal(cnam(t_perf_2, 4), "dls")
expect_equal(cnam(t_perf_2, 5), "dls_per_day")
expect_equal(cnam(t_perf_2, 6), "dls_per_day_at_launch")
expect_equal(cnam(t_perf_2, 7), "dls_per_day_after_launch")
expect_equal(cnam(t_perf_3, 1), "ep_number")
expect_equal(cnam(t_perf_3, 2), "title")
expect_equal(cnam(t_perf_3, 3), "ep_num_title")
expect_equal(cnam(t_perf_3, 4), "dls")
expect_equal(cnam(t_perf_3, 5), "dls_per_hour")
expect_equal(cnam(t_perf_3, 6), "dls_per_hour_at_launch")
expect_equal(cnam(t_perf_3, 7), "dls_per_hour_after_launch")
})
test_that("col classes of dfs are correct", {
expect_is(t_perf_1$ep_number, "character")
expect_is(t_perf_1$title, "character")
expect_is(t_perf_1$ep_num_title, "character")
expect_is(t_perf_1$dls, "integer")
expect_is(t_perf_1$dls_per_day, "numeric")
expect_is(t_perf_1$dls_per_day_at_launch, "numeric")
expect_is(t_perf_1$dls_per_day_after_launch, "numeric")
expect_is(t_perf_2$ep_number, "character")
expect_is(t_perf_2$title, "character")
expect_is(t_perf_2$ep_num_title, "character")
expect_is(t_perf_2$dls, "integer")
expect_is(t_perf_2$dls_per_day, "numeric")
expect_is(t_perf_2$dls_per_day_at_launch, "numeric")
expect_is(t_perf_2$dls_per_day_after_launch, "numeric")
expect_is(t_perf_3$ep_number, "character")
expect_is(t_perf_3$title, "character")
expect_is(t_perf_3$ep_num_title, "character")
expect_is(t_perf_3$dls, "integer")
expect_is(t_perf_3$dls_per_hour, "numeric")
expect_is(t_perf_3$dls_per_hour_at_launch, "numeric")
expect_is(t_perf_3$dls_per_hour_after_launch, "numeric")
})
test_that("content of dfs are correct", {
expect_equal(t_perf_1$dls, r_dls)
expect_equal(t_perf_1$dls_per_day, r_dlspd)
expect_equal(t_perf_1$dls_per_day_at_launch, r_dlspd)
expect_equal(t_perf_1$dls_per_day_after_launch, r_dlspd)
expect_equal(t_perf_2$dls, r_dls)
expect_equal(t_perf_2$dls_per_day, r_dlspd)
expect_equal(t_perf_2$dls_per_day_at_launch, r2_dlpdat)
expect_equal(t_perf_2$dls_per_day_after_launch, r2_dlpdaft)
expect_equal(t_perf_3$dls, r_dls)
expect_equal(t_perf_3$dls_per_hour, r_dlspd / 24)
expect_equal(t_perf_3$dls_per_hour_at_launch, r2_dlpdat / 24)
expect_equal(t_perf_3$dls_per_hour_after_launch, r2_dlpdaft / 24)
})
# cleanup
rm(t_exmpl)
rm(list = ls(pat = "[tr]_perf_[123]"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.