Questions & Results
Q1 of 10Multiple ChoiceAccuracy45s · 1 pt
What is the main idea of property-based testing?
A State a property that should hold for all inputs, then check it on many randomly generated inputs✓ Correct B Write one hand-picked input and its expected output per test case C Prove the program correct for every possible input D Measure how many lines of code the tests execute 151 / 183 answered · 91% correct
Q2 of 10Multiple ChoiceAccuracy60s · 1 pt
Which property is TRUE for every OCaml list l?
A List.rev (List.rev l) = l✓ Correct C List.hd (List.rev l) = List.hd l 171 / 183 answered · 99% correct
Q3 of 10Multiple ChoiceAccuracy60s · 1 pt
Which property FAILS for some lists l1 and l2?
A List.rev (l1 @ l2) = List.rev l1 @ List.rev l2✓ Correct B List.length (l1 @ l2) = List.length l1 + List.length l2 C List.rev (l1 @ l2) = List.rev l2 @ List.rev l1 D List.length (List.rev l1) = List.length l1 179 / 183 answered · 93% correct
Q4 of 10Multiple ChoiceAccuracy60s · 1 pt
We test a sort function with only this property:
fun l -> is_sorted (my_sort l)
Which buggy implementation would still pass every test?
A let my_sort l = []✓ Correct B let my_sort l = List.rev l D let my_sort l = List.rev (List.sort compare l) 180 / 183 answered · 84% correct
Q5 of 10Multiple ChoiceAccuracy60s · 1 pt
What does ~count:500 mean in this QCheck test?
let t = QCheck.Test.make ~count:500 ~name:"rev_rev"
QCheck.(list int)
(fun l -> List.rev (List.rev l) = l)
A QCheck generates 500 random lists and checks the property on each one✓ Correct B Every generated list has exactly 500 elements C The test stops after 500 failures D Every generated integer is between 0 and 500 181 / 183 answered · 100% correct
Q6 of 10Multiple ChoiceAccuracy60s · 1 pt
A property takes a pair (n, names) where n : int and names : string list. Which QCheck arbitrary generates its inputs?
A QCheck.(pair int (list string))✓ Correct B QCheck.(list (pair int string)) C QCheck.(pair (list int) string) D QCheck.(triple int list string) 183 / 183 answered · 93% correct
Q7 of 10Multiple ChoiceAccuracy75s · 1 pt
This test fails:
let max_list l = List.fold_left max 0 l
QCheck.Test.make QCheck.(list int)
(fun l -> l = [] || List.mem (max_list l) l)
After shrinking, which counterexample is QCheck most likely to report?
183 / 183 answered · 90% correct
Q8 of 10Multiple ChoiceAccuracy60s · 1 pt
A property only makes sense for non-empty lists, so we write
fun l -> QCheck.assume (l <> []); List.hd (List.rev l) = last l
What does QCheck.assume do when l = []?
A Discards that input, so it counts as neither a pass nor a failure✓ Correct B Reports the test as failed C Raises an exception that crashes the test runner D Replaces [] with a non-empty list and keeps going 183 / 183 answered · 89% correct
Q9 of 10Multiple ChoiceAccuracy45s · 1 pt
A QCheck property passes on 10,000 random inputs. What can we conclude?
A QCheck found no counterexample, but the function could still have a bug✓ Correct B The function is proven correct for all inputs C The function is correct for all inputs up to size 10,000 D The property itself must be correct 183 / 183 answered · 98% correct
Q10 of 10Multiple ChoiceAccuracy75s · 1 pt
This buggy sort removes duplicates:
let my_sort l = List.sort_uniq compare l
Which property catches the bug?
A fun l -> List.length (my_sort l) = List.length l✓ Correct B fun l -> is_sorted (my_sort l) C fun l -> my_sort (my_sort l) = my_sort l D fun l -> List.for_all (fun x -> List.mem x l) (my_sort l) 182 / 183 answered · 80% correct
Score Distribution
Score (points) →