+def loc_coverage(locations, text, report):
+ # locations have a long and a short description, that each have to
+ # be checked seperately
+ for name, loc in locations:
+ desc = loc["description"]
+ if name not in report["messages"]:
+ report["messages"][name] = {"long" : False, "short": False}
+ report["total"] += 2
+ if not report["messages"][name]["long"] and search(desc["long"], text):
+ report["messages"][name]["long"] = True
+ report["covered"] += 1
+ if not report["messages"][name]["short"] and search(desc["short"], text):
+ report["messages"][name]["short"] = True
+ report["covered"] += 1
+
+def hint_coverage(obituaries, text, report):
+ # hints have a "question" where the hint is offered, followed
+ # by the actual hint if the player requests it
+ for _, hintouter in enumerate(obituaries):
+ hint = hintouter["hint"]
+ name = hint["name"]
+ if name not in report["messages"]:
+ report["messages"][name] = {"question" : False, "hint": False}
+ report["total"] += 2
+ if not report["messages"][name]["question"] and search(hint["question"], text):
+ report["messages"][name]["question"] = True
+ report["covered"] += 1
+ if not report["messages"][name]["hint"] and search(hint["hint"], text):
+ report["messages"][name]["hint"] = True
+ report["covered"] += 1
+
+def obit_coverage(obituaries, text, report):
+ # obituaries have a "query" where it asks the player for a resurrection,
+ # followed by a snarky comment if the player says yes
+ for name, obit in enumerate(obituaries):
+ if name not in report["messages"]:
+ report["messages"][name] = {"query" : False, "yes_response": False}
+ report["total"] += 2
+ if not report["messages"][name]["query"] and search(obit["query"], text):
+ report["messages"][name]["query"] = True
+ report["covered"] += 1
+ if not report["messages"][name]["yes_response"] and search(obit["yes_response"], text):
+ report["messages"][name]["yes_response"] = True
+ report["covered"] += 1
+
+def threshold_coverage(classes, text, report):
+ # works for class thresholds and turn threshold, which have a "message"
+ # property
+ for name, item in enumerate(classes):
+ if name not in report["messages"]:
+ report["messages"][name] = {"covered" : False}
+ report["total"] += 1
+ if not report["messages"][name]["covered"] and search(item["message"], text):
+ report["messages"][name]["covered"] = True
+ report["covered"] += 1
+
+def arb_coverage(arb_msgs, text, report):
+ for name, message in arb_msgs:
+ if name not in report["messages"]:
+ report["messages"][name] = {"covered" : False}
+ report["total"] += 1
+ if not report["messages"][name]["covered"] and (search(message, text) or name in DANGLING_MESSAGES):
+ report["messages"][name]["covered"] = True
+ report["covered"] += 1
+
+def actions_coverage(items, text, report):
+ # works for actions
+ for name, item in items:
+ if name not in report["messages"]:
+ report["messages"][name] = {"covered" : False}
+ report["total"] += 1
+ if not report["messages"][name]["covered"] and (search(item["message"], text) or name in DANGLING_ACTIONS):
+ report["messages"][name]["covered"] = True
+ report["covered"] += 1
+
+def coverage_report(db, check_file_contents):
+ # Create report for each catagory, including total items, number of items
+ # covered, and a list of the covered messages
+ report = {}
+ for name in db.keys():
+ # initialize each catagory
+ report[name] = {
+ "name" : name, # convenience for string formatting
+ "total" : 0,
+ "covered" : 0,
+ "messages" : {}
+ }
+
+ # search for each message in every test check file
+ for chk in check_file_contents:
+ arb_coverage(db["arbitrary_messages"], chk, report["arbitrary_messages"])
+ hint_coverage(db["hints"], chk, report["hints"])
+ loc_coverage(db["locations"], chk, report["locations"])
+ obit_coverage(db["obituaries"], chk, report["obituaries"])
+ obj_coverage(db["objects"], chk, report["objects"])
+ actions_coverage(db["actions"], chk, report["actions"])
+ threshold_coverage(db["classes"], chk, report["classes"])
+ threshold_coverage(db["turn_thresholds"], chk, report["turn_thresholds"])
+
+ return report