A small assertion turns an assumption into a visible TRUE or FALSE value.

Program

Play the script to change the limit and see whether the value passes.

limit
assertion_check.R
Replay: real traced execution (multi-file project)
limit <- 10
value <- 12
ok <- value <= limit
label <- paste("ok", ok, sep = ":")
cat(label, "\n", sep = "")
limit <- 5
value <- 12
ok <- value <= limit
label <- paste("ok", ok, sep = ":")
cat(label, "\n", sep = "")
limit <- 20
value <- 12
ok <- value <= limit
label <- paste("ok", ok, sep = ":")
cat(label, "\n", sep = "")
  1. limit ← 10

    1limit <- 102value <- 12
    values this step10limit
  2. value ← 12

    1limit <- 102value <- 123ok <- value <= limit
    values this step12value
  3. ok ← FALSE

    2value <- 123ok <- value <= limit4label <- paste("ok", ok, sep = ":")
    values this stepFALSEok12value10limit
  4. label ← ok:FALSE

    3ok <- value <= limit4label <- paste("ok", ok, sep = ":")5cat(label, "\n", sep = "")
    values this stepok:FALSElabelFALSEok
  5. cat(label, " ", sep = "")

    4label <- paste("ok", ok, sep = ":")5cat(label, "\n", sep = "")
    outputok:FALSE
    values this stepok:FALSElabel
  1. limit ← 5

    1limit <- 52value <- 12
    values this step5limit
  2. value ← 12

    1limit <- 52value <- 123ok <- value <= limit
    values this step12value
  3. ok ← FALSE

    2value <- 123ok <- value <= limit4label <- paste("ok", ok, sep = ":")
    values this stepFALSEok12value5limit
  4. label ← ok:FALSE

    3ok <- value <= limit4label <- paste("ok", ok, sep = ":")5cat(label, "\n", sep = "")
    values this stepok:FALSElabelFALSEok
  5. cat(label, " ", sep = "")

    4label <- paste("ok", ok, sep = ":")5cat(label, "\n", sep = "")
    outputok:FALSE
    values this stepok:FALSElabel
  1. limit ← 20

    1limit <- 202value <- 12
    values this step20limit
  2. value ← 12

    1limit <- 202value <- 123ok <- value <= limit
    values this step12value
  3. ok ← TRUE

    2value <- 123ok <- value <= limit4label <- paste("ok", ok, sep = ":")
    values this stepTRUEok12value20limit
  4. label ← ok:TRUE

    3ok <- value <= limit4label <- paste("ok", ok, sep = ":")5cat(label, "\n", sep = "")
    values this stepok:TRUElabelTRUEok
  5. cat(label, " ", sep = "")

    4label <- paste("ok", ok, sep = ":")5cat(label, "\n", sep = "")
    outputok:TRUE
    values this stepok:TRUElabel
assumption The limit records what value is considered acceptable.
check `value <= limit` turns the assumption into a logical result.
inspection label Printing the result makes the failed or passed check explicit.