Give the blind test by two measures, first and last months and also no wrong gap in the middle: 114 of 148 and 105 of 148, stored, scored and stated together
This commit is contained in:
1 parent
535d2bebaa
commit
e8ca8e862e
13 files changed
+183
-68
No files matched your search
@@ -391,13 +391,14 @@ class ProposeCheckTest(unittest.TestCase):
|
||||
|
||||
def blind_doc(self, root, share=0.77, tested=100):
|
||||
matched = int(round(share * tested))
|
||||
doc = {"date": "2026-11-20", "tested": tested, "matched": matched,
|
||||
"share": round(matched / tested, 2),
|
||||
sh = round(matched / tested, 2)
|
||||
doc = {"date": "2026-11-20", "tested": tested, "matched": matched, "share": sh,
|
||||
"strict_matched": matched, "strict_share": sh,
|
||||
"by_confidence": {
|
||||
"high": {"tested": tested, "matched": matched,
|
||||
"share": round(matched / tested, 2)},
|
||||
"medium": {"tested": 0, "matched": 0, "share": 0.0},
|
||||
"low": {"tested": 0, "matched": 0, "share": 0.0}}}
|
||||
"high": {"tested": tested, "matched": matched, "share": sh,
|
||||
"strict_matched": matched, "strict_share": sh},
|
||||
"medium": {"tested": 0, "matched": 0, "share": 0.0, "strict_matched": 0, "strict_share": 0.0},
|
||||
"low": {"tested": 0, "matched": 0, "share": 0.0, "strict_matched": 0, "strict_share": 0.0}}}
|
||||
with open(os.path.join(root, "tools", "season_blind_test.json"), "w") as f:
|
||||
json.dump(doc, f)
|
||||
|
||||
|
||||
@@ -158,26 +158,35 @@ class AnswersTest(unittest.TestCase):
|
||||
|
||||
|
||||
class ScoreTest(unittest.TestCase):
|
||||
def test_matches_are_counted_within_a_month_at_each_end_by_confidence(self):
|
||||
truth = {"a": [6, 7, 8, 9], "b": [6, 7, 8, 9], "c": [6, 7, 8, 9], "d": [1, 2, 3]}
|
||||
def test_matches_are_counted_both_ways_by_confidence(self):
|
||||
truth = {"a": [6, 7, 8, 9], "b": [6, 7, 8, 9], "c": [6, 7, 8, 9], "d": [1, 2, 3],
|
||||
"e": [3, 4, 5, 6, 7, 8, 9, 10, 11]}
|
||||
ans = {"a": ([6, 7, 8, 9], "", "high", ""), # exact
|
||||
"b": ([7, 8, 9, 10], "", "medium", ""), # one month at each end
|
||||
"c": ([1, 2, 3], "", "low", ""), # wrong
|
||||
"e": ([3, 4, 5, 9, 10, 11], "", "medium", ""), # right ends, wrong gap
|
||||
"x": ([1], "", "high", "")} # not a sourced trail: ignored
|
||||
got = J.score(ans, truth)
|
||||
self.assertEqual(got["tested"], 4)
|
||||
self.assertEqual(got["matched"], 2)
|
||||
self.assertEqual(got["by_confidence"]["high"], {"tested": 1, "matched": 1})
|
||||
self.assertEqual(got["by_confidence"]["medium"], {"tested": 1, "matched": 1})
|
||||
self.assertEqual(got["by_confidence"]["low"], {"tested": 1, "matched": 0})
|
||||
self.assertEqual(got["tested"], 5)
|
||||
self.assertEqual(got["matched"], 3)
|
||||
self.assertEqual(got["strict_matched"], 2)
|
||||
self.assertEqual(got["by_confidence"]["high"], {"tested": 1, "matched": 1, "strict_matched": 1})
|
||||
self.assertEqual(got["by_confidence"]["medium"], {"tested": 2, "matched": 2, "strict_matched": 1})
|
||||
self.assertEqual(got["by_confidence"]["low"], {"tested": 1, "matched": 0, "strict_matched": 0})
|
||||
# d was never answered: it counts as tested and missed
|
||||
self.assertEqual(got["unanswered"], 1)
|
||||
|
||||
def test_the_trails_judged_from_pages_that_differ_are_not_scored_against_themselves(self):
|
||||
truth = J._truth(J.ROOT)
|
||||
self.assertEqual(len(truth), 148)
|
||||
for tid in ("sierra-high-route", "cohos", "ouachita"):
|
||||
self.assertNotIn(tid, truth)
|
||||
|
||||
def test_the_figure_file_round_trips_and_shares_are_computed(self):
|
||||
figures = {"tested": 148, "matched": 114, "unanswered": 0,
|
||||
"by_confidence": {"high": {"tested": 52, "matched": 48},
|
||||
"medium": {"tested": 76, "matched": 55},
|
||||
"low": {"tested": 20, "matched": 11}}}
|
||||
figures = {"tested": 148, "matched": 114, "strict_matched": 105, "unanswered": 0,
|
||||
"by_confidence": {"high": {"tested": 52, "matched": 48, "strict_matched": 44},
|
||||
"medium": {"tested": 76, "matched": 55, "strict_matched": 50},
|
||||
"low": {"tested": 20, "matched": 11, "strict_matched": 11}}}
|
||||
d = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, d, True)
|
||||
path = os.path.join(d, "t.json")
|
||||
@@ -187,22 +196,42 @@ class ScoreTest(unittest.TestCase):
|
||||
self.assertEqual(got["tested"], 148)
|
||||
self.assertEqual(got["matched"], 114)
|
||||
self.assertEqual(got["share"], 0.77)
|
||||
self.assertEqual(got["strict_matched"], 105)
|
||||
self.assertEqual(got["strict_share"], 0.71)
|
||||
self.assertEqual(got["by_confidence"]["high"]["share"], 0.92)
|
||||
self.assertEqual(got["by_confidence"]["high"]["strict_share"], 0.85)
|
||||
self.assertEqual(got["by_confidence"]["low"]["share"], 0.55)
|
||||
self.assertEqual(J.check_blind_test(got), [])
|
||||
self.assertIn("first and last", got["measure"])
|
||||
self.assertIn("gap", got["strict_measure"])
|
||||
|
||||
def test_a_loaded_file_must_add_up(self):
|
||||
bad = {"date": "2026-11-20", "tested": 10, "matched": 5, "share": 0.5,
|
||||
"by_confidence": {"high": {"tested": 4, "matched": 5, "share": 1.0},
|
||||
"medium": {"tested": 3, "matched": 1, "share": 0.33},
|
||||
"low": {"tested": 3, "matched": 1, "share": 0.33}}}
|
||||
"strict_matched": 4, "strict_share": 0.4,
|
||||
"by_confidence": {"high": {"tested": 4, "matched": 5, "share": 1.0, "strict_matched": 1, "strict_share": 0.25},
|
||||
"medium": {"tested": 3, "matched": 1, "share": 0.33, "strict_matched": 1, "strict_share": 0.33},
|
||||
"low": {"tested": 3, "matched": 1, "share": 0.33, "strict_matched": 1, "strict_share": 0.33}}}
|
||||
self.assertTrue(J.check_blind_test(bad))
|
||||
|
||||
def test_the_strict_figure_may_not_exceed_the_ends_figure_or_be_missing(self):
|
||||
doc = {"date": "2026-11-20", "tested": 10, "matched": 5, "share": 0.5,
|
||||
"strict_matched": 6, "strict_share": 0.6,
|
||||
"by_confidence": {"high": {"tested": 10, "matched": 5, "share": 0.5, "strict_matched": 6, "strict_share": 0.6},
|
||||
"medium": {"tested": 0, "matched": 0, "share": 0.0, "strict_matched": 0, "strict_share": 0.0},
|
||||
"low": {"tested": 0, "matched": 0, "share": 0.0, "strict_matched": 0, "strict_share": 0.0}}}
|
||||
self.assertTrue(J.check_blind_test(doc))
|
||||
del doc["strict_matched"]
|
||||
self.assertTrue(J.check_blind_test(doc))
|
||||
|
||||
|
||||
class CommittedFilesTest(unittest.TestCase):
|
||||
def test_the_committed_blind_test_adds_up_and_passes_the_bar(self):
|
||||
got = J.load_blind_test(os.path.join(J.ROOT, "tools", "season_blind_test.json"))
|
||||
self.assertEqual(J.check_blind_test(got), [])
|
||||
self.assertGreaterEqual(got["share"], E.BAR["within1_min"])
|
||||
# both measures are stored, and the strict one is the lower
|
||||
self.assertEqual((got["tested"], got["matched"], got["strict_matched"]), (148, 114, 105))
|
||||
self.assertLessEqual(got["strict_matched"], got["matched"])
|
||||
|
||||
def test_every_judged_row_is_well_formed_and_matches_its_record(self):
|
||||
ids = R.trail_ids(J.ROOT)
|
||||
|
||||
@@ -45,6 +45,30 @@ class MatchTest(unittest.TestCase):
|
||||
self.assertFalse(M.match([3, 4, 5], spring_fall))
|
||||
self.assertFalse(M.match([3, 4, 5, 7, 9, 10, 11], spring_fall))
|
||||
|
||||
def test_the_strict_measure_counts_a_wrong_gap_in_the_middle_as_a_miss(self):
|
||||
# the ends-only measure passes March to May plus September to November
|
||||
# against a continuous March to November; the strict one does not
|
||||
gap = [3, 4, 5, 9, 10, 11]
|
||||
whole = list(range(3, 12))
|
||||
self.assertTrue(M.match(gap, whole))
|
||||
self.assertFalse(M.match_strict(gap, whole))
|
||||
self.assertFalse(M.match_strict(whole, gap))
|
||||
self.assertTrue(M.match_strict(whole, whole))
|
||||
self.assertTrue(M.match_strict([4, 5, 6, 7, 8, 9, 10], whole))
|
||||
self.assertTrue(M.match_strict(gap, gap))
|
||||
# a stray one-month window of the estimate has no partner in the truth
|
||||
self.assertFalse(M.match_strict([3, 4, 5, 6, 7, 11], [3, 4, 5, 6, 7]))
|
||||
self.assertTrue(M.match_strict(list(range(1, 11)), list(range(1, 13))))
|
||||
self.assertFalse(M.match_strict([], whole))
|
||||
|
||||
def test_strict_never_matches_what_the_ends_only_measure_misses(self):
|
||||
import itertools
|
||||
seasons = [[3, 4, 5, 9, 10, 11], list(range(3, 12)), [6, 7, 8], [11, 12, 1, 2], [1, 2, 3, 7, 8],
|
||||
list(range(1, 13)), [5, 6, 7, 8, 9, 10]]
|
||||
for est, src in itertools.product(seasons, seasons):
|
||||
if M.match_strict(est, src):
|
||||
self.assertTrue(M.match(est, src), (est, src))
|
||||
|
||||
def test_masks_and_lists_agree(self):
|
||||
self.assertEqual(M.to_months(M.to_mask([3, 1, 12])), [1, 3, 12])
|
||||
self.assertEqual(M.match(M.to_mask([6, 7]), [6, 7]), True)
|
||||
|
||||
Reference in new issue
Block a user