Debugging and Inspection
Assertion Check
Compare a Value
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.
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 = "")
limit ← 10
1limit <- 102value <- 12values this step10limitvalue ← 12
1limit <- 102value <- 123ok <- value <= limitvalues this step12valueok ← FALSE
2value <- 123ok <- value <= limit4label <- paste("ok", ok, sep = ":")values this stepFALSEok12value10limitlabel ← ok:FALSE
3ok <- value <= limit4label <- paste("ok", ok, sep = ":")5cat(label, "\n", sep = "")values this stepok:FALSElabelFALSEokcat(label, " ", sep = "")
4label <- paste("ok", ok, sep = ":")5cat(label, "\n", sep = "")outputok:FALSEvalues this stepok:FALSElabel
limit ← 5
1limit <- 52value <- 12values this step5limitvalue ← 12
1limit <- 52value <- 123ok <- value <= limitvalues this step12valueok ← FALSE
2value <- 123ok <- value <= limit4label <- paste("ok", ok, sep = ":")values this stepFALSEok12value5limitlabel ← ok:FALSE
3ok <- value <= limit4label <- paste("ok", ok, sep = ":")5cat(label, "\n", sep = "")values this stepok:FALSElabelFALSEokcat(label, " ", sep = "")
4label <- paste("ok", ok, sep = ":")5cat(label, "\n", sep = "")outputok:FALSEvalues this stepok:FALSElabel
limit ← 20
1limit <- 202value <- 12values this step20limitvalue ← 12
1limit <- 202value <- 123ok <- value <= limitvalues this step12valueok ← TRUE
2value <- 123ok <- value <= limit4label <- paste("ok", ok, sep = ":")values this stepTRUEok12value20limitlabel ← ok:TRUE
3ok <- value <= limit4label <- paste("ok", ok, sep = ":")5cat(label, "\n", sep = "")values this stepok:TRUElabelTRUEokcat(label, " ", sep = "")
4label <- paste("ok", ok, sep = ":")5cat(label, "\n", sep = "")outputok:TRUEvalues 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.