- if desc == None or desc == '':
- obj["descriptions"][j] = True
- objects[i] = (obj_name, obj)
- elif desc != True:
- if search(desc, text):
- obj["descriptions"][j] = True
- objects[i] = (obj_name, obj)
-
-def hint_coverage(hints, text):
- for name, hint in hints:
- if hint["question"] != True:
- if search(hint["question"], text):
- hint["question"] = True
- if hint["hint"] != True:
- if search(hint["hint"], text):
- hint["hint"] = True
-
-def special_coverage(specials, text):
- for name, special in specials:
- if special["message"] == None:
- special["message"] = True
- if special["message"] != True:
- if search(special["message"], text):
- special["message"] = True
-
-def threshold_coverage(classes, text):
- for i, msg in enumerate(classes):
- if msg["message"] == None:
- msg["message"] = True
- elif msg["message"] != True:
- if search(msg["message"], text):
- msg["message"] = True
-
-def obit_coverage(obituaries, text):
- for i, obit in enumerate(obituaries):
- if obit["query"] != True:
- if search(obit["query"], text):
- obit["query"] = True
- if obit["yes_response"] != True:
- if search(obit["yes_response"], text):
- obit["yes_response"] = True
-
-def actions_coverage(actions, text):
- for name, action in actions:
- if action["message"] == None:
- action["message"] = True
- if action["message"] != True:
- if search(action["message"], text):
- action["message"] = True
+ name = "{}[{}]".format(obj_name, j)
+ if name not in report["messages"]:
+ report["messages"][name] = {"covered" : False}
+ report["total"] += 1
+ if report["messages"][name]["covered"] != True and search(desc, text):
+ report["messages"][name]["covered"] = True
+ report["covered"] += 1
+
+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 report["messages"][name]["long"] != True and search(desc["long"], text):
+ report["messages"][name]["long"] = True
+ report["covered"] += 1
+ if report["messages"][name]["short"] != True 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 i, 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 report["messages"][name]["question"] != True and search(hint["question"], text):
+ report["messages"][name]["question"] = True
+ report["covered"] += 1
+ if report["messages"][name]["hint"] != True 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 report["messages"][name]["query"] != True and search(obit["query"], text):
+ report["messages"][name]["query"] = True
+ report["covered"] += 1
+ if report["messages"][name]["yes_response"] != True 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 report["messages"][name]["covered"] != True 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 report["messages"][name]["covered"] != True and search(message, text):
+ 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 report["messages"][name]["covered"] != True and (search(item["message"], text) or name in DANGLING):
+ 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