# ferdo R Lab | Lesson 6 | Deferred package acceptance test
# Run later from extracted ZIP ROOT: source("scripts/acceptance_test.R")
# debug_challenge.R is intentionally broken: parse only, never source.
required <- c("data/class_synthetic.csv","scripts/check_setup.R",
              "scripts/warmup_demo.R","scripts/analysis_starter.R",
              "scripts/debug_challenge.R")
stopifnot(all(file.exists(required)))
invisible(lapply(required[-1],function(x)parse(file=x)))
e <- new.env(parent=globalenv())
sys.source("scripts/check_setup.R",envir=e)
pdf_out <- tempfile(fileext=".pdf")
grDevices::pdf(pdf_out,width=10,height=7)
tryCatch({
  w <- new.env(parent=globalenv())
  sys.source("scripts/warmup_demo.R",envir=w)
  stopifnot(nrow(w$d)==12L,sum(w$score_known)==11L,
            identical(names(w$d),
                      c("student_id","study_hours","quiz_score","group")))
},finally=grDevices::dev.off())
stopifnot(file.exists(pdf_out),file.info(pdf_out)$size>0)
unlink(pdf_out)
s <- new.env(parent=globalenv())
sys.source("scripts/analysis_starter.R",envir=s)
stopifnot(identical(dim(s$d),c(12L,4L)))
# Does NOT grade the student's TODO work or the broken challenge!
cat("R LAB LESSON 6 ACCEPTANCE TEST PASS\n")
