CMSC330 Quiz 09/29

CMSC 330 — Fall 2026 · September 29, 2026 · 183 players · Max 10 pts

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
137
✓ Correct
B Write one hand-picked input and its expected output per test case
2
C Prove the program correct for every possible input
10
D Measure how many lines of code the tests execute
2
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
170
✓ Correct
B List.rev l = l
C List.hd (List.rev l) = List.hd l
D List.rev l <> l
1
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
167
✓ Correct
B List.length (l1 @ l2) = List.length l1 + List.length l2
3
C List.rev (l1 @ l2) = List.rev l2 @ List.rev l1
7
D List.length (List.rev l1) = List.length l1
2
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 = []
152
✓ Correct
B let my_sort l = List.rev l
1
C let my_sort l = l
13
D let my_sort l = List.rev (List.sort compare l)
14
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
181
✓ 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))
170
✓ Correct
B QCheck.(list (pair int string))
6
C QCheck.(pair (list int) string)
7
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?

A [-1]
164
✓ Correct
B []
13
C [0]
4
D [3; -7; 12]
2
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
163
✓ Correct
B Reports the test as failed
6
C Raises an exception that crashes the test runner
11
D Replaces [] with a non-empty list and keeps going
3
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
180
✓ Correct
B The function is proven correct for all inputs
C The function is correct for all inputs up to size 10,000
3
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
145
✓ Correct
B fun l -> is_sorted (my_sort l)
3
C fun l -> my_sort (my_sort l) = my_sort l
24
D fun l -> List.for_all (fun x -> List.mem x l) (my_sort l)
10
182 / 183 answered · 80% correct

Score Distribution

1
3
3
5
10
25
61
75
0
1
2
3
4
5
6
7
8
9
10

Score (points) →

Players
183
Average Score
8.9
High Score
10
Max Possible
10