# Question format: # qX = [Case1, Case2, ..., CaseN] # Where each case is an instance Case(label, function[, number]) # * label is a description of the test # * function is a predicate which consumes the parameters to the function and the expected answer # * number is the number of tests of that form required (if not included, n=1) q1a = [Case("empty list", lambda lst, ans: lst == ans == []), Case("nonempty list, all cards red and odd", lambda lst, ans: lst == ans != []), Case("nonempty list, no cards red and odd", lambda lst, ans: lst != ans == []), Case("nonempty list, some cards red and odd", lambda lst, ans: lst != ans != [])] q1b = [Case("10 of spades", lambda c, ans: c.suit == "spades" and c.value == 10), Case("A spade other than the 10", lambda c, ans: c.suit == "spades" and c.value != 10), Case("A card other than a spade", lambda c, ans: c.suit != "spades")] q2 = [Case("empty list", lambda hand, v, ans: hand == []), Case("nonempty list, all cards removed", lambda hand, v, ans: hand != [] and filter(lambda c: c.value != v, hand) == []), Case("nonempty list, no cards removed", lambda hand, v, ans: hand != [] and filter(lambda c: c.value == v, hand) == []), Case("nonempty list, some cards removed", lambda hand, v, ans: hand != [] and filter(lambda c: c.value == v, hand) != [] and filter(lambda c: c.value != v, hand) != [])] q3 = [Case("Empty dictionary", lambda d, key, threshold, ans: d == {}), Case("Element is less than threshold", lambda d, key, threshold, ans: d.has_key(key) and d[key] < threshold), Case("Element is equal to threshold", lambda d, key, threshold, ans: d.has_key(key) and d[key] == threshold), Case("Element is greater than threshold", lambda d, key, threshold, ans: d.has_key(key) and d[key] > threshold)] q4 = [Case("Q is input", lambda d, inp, ans: "Q" in inp), Case("L is input", lambda d, inp, ans: "L" in inp), Case("E is input", lambda d, inp, ans: "E" in inp), Case("G is input", lambda d, inp, ans: "G" in inp), Case("I is input", lambda d, inp, ans: "I" in inp), Case("D is input", lambda d, inp, ans: "D" in inp), Case("A is input", lambda d, inp, ans: "A" in inp), Case("Multiple inputs in one case", lambda d, inp, ans: len(set("LEGIDA") & set(inp)) > 1)]