rstudio/pygradethis

Make use of unittest for `grade_result`

nischalshrestha opened this issue · 2 comments

When checking several conditions for grade_result we should do two things that make checking more maintainable:

  • use existing unit testing framework (this has advantage of leveraging pandas/numpy asserts as well)
  • custom unittest class will help in collecting all matched conditions, number of (in)correct test cases.

which requires more fields for graded result:

  • add num_correct and num_total

This requires changing the graded structure to return as well a la {gradethis}:

graded(
    correct = is_correct,
    message = glue_message(
      if (is_correct) glue_correct else glue_incorrect, # nolint
      .is_correct = is_correct,
      .message = NULL,
      .correct = correct,
      .incorrect = incorrect,
      .num_correct = as.character(num_correct),
      .num_total = as.character(length(conditions))
    )
  )

See this test. We'd like something like this:

grade_result_strict(
  pass_if(~ .result(3) == 4),
  pass_if(~ .result(10) == 11),
  grader_args = list(),
  learnr_args = list(last_value = example_function, envir_prep = new.env()),
  glue_correct = glue_correct_no_praise
)

This might not even be a thing anymore so might have to remove.