tests/testthat/test-results.R

context("test_results")

test_that("main", {
  skip_on_cran()

  run_participant <- function(answers) {
    app <- AppTester$new("apps/results")

    for (answer in answers) {
       app$click(answer)
    }

    invisible(app)
  }

  run_participants <- function(...) {
    lapply(list(...), run_participant)
  }

  apps <- run_participants(c(1, 2, 3, 4),
                           c(2, 4),
                           c(4, 4, 3),
                           c(3, 3, 1, 2))

  df <- df_all_results("apps/results/output/results")

  expect_equal(df$session.complete, c(TRUE, FALSE, FALSE, TRUE))
  expect_equal(df$results.q1, c(1, 2,  4,  3) %>% as.character())
  expect_equal(df$results.q2, c(2, 4,  4,  3) %>% as.character())
  expect_equal(df$results.q3, c(3, NA, 3,  1) %>% as.character())
  expect_equal(df$results.q4, c(4, NA, NA, 2) %>% as.character())

  lapply(apps, function(x) x$stop())

})
pmcharrison/psychTestR documentation built on Sept. 30, 2023, 6:27 p.m.