tests/testthat/test-reddit.R

# Tests for Reddit module plotting, n-gram generation, etc.

# load comments
test_comments <- socialastronomy.pbs4dash::test_comments


testthat::test_that("Comments for running tests loaded properly",{
  
  testthat::expect_s3_class(test_comments, "tbl_df")
  
  testthat::expect_equal(nrow(test_comments), 1000)
  
})


testthat::test_that("Heatmap plots work properly for null data and good data.", {
  
  testthat::expect_equal(
    plot_reddit_heatmap(dplyr::tibble()),
    NULL
  )
  
  testthat::expect_s3_class(
    plot_reddit_heatmap(test_comments),
    "ggplot")
  
})

testthat::test_that("Posts-over-time barcharts plots work properly for null data and good data.", {
  
  testthat::expect_equal(
    plot_reddit_posts_over_time(dplyr::tibble()),
    NULL
  )
  
  testthat::expect_s3_class(
    plot_reddit_posts_over_time(test_comments),
    "ggplot")
  
})


testthat::test_that("Subreddit tables work properly forn null data and good data.",{
  
  testthat::expect_equal(make_subreddit_table(dplyr::tibble()), dplyr::tibble())
  testthat::expect_s3_class(make_subreddit_table(test_comments), "tbl_df")
  
})



testthat::test_that("Subreddit plots work properly forn null data and good data.",{
  
  testthat::expect_equal(make_subreddit_plot(dplyr::tibble()), NULL)
  testthat::expect_s3_class(make_subreddit_plot(test_comments), "ggplot")
  
})


testthat::test_that("Reddit comments top words work properly for null data and good data.",{
  
  testthat::expect_equal(get_top_words(dplyr::tibble()), dplyr::tibble())
  
  testthat::expect_s3_class(get_top_words(test_comments), "tbl_df")
  
  testthat::expect_equal(colnames(get_top_words(test_comments)),
                         c("word", "num_uses", "num_comments", "pct_comments"))
})


testthat::test_that("Reddit comments 2-grams work properly for null data and good data.",{
  
  testthat::expect_equal(get_top_2grams(dplyr::tibble()), dplyr::tibble())
  
  testthat::expect_s3_class(get_top_2grams(test_comments), "tbl_df")
  
})
BelangerAnalytics/socialastronomy.pbs4dash documentation built on Feb. 15, 2022, 8:06 a.m.