From 50beb802806b0403c971c1037b5f1e6932cae09b Mon Sep 17 00:00:00 2001 From: ytwei Date: Sat, 22 Aug 2026 22:24:34 +0800 Subject: [PATCH] fix(curriculum): add actionable itertools assertion messages --- checks/itertools/itertools3.py | 10 +++++++++- checks/itertools/itertools4.py | 8 +++++++- checks/itertools/itertools5.py | 5 ++++- checks/itertools/itertools6.py | 5 ++++- checks/itertools/itertools7.py | 5 ++++- checks/itertools/itertools8.py | 10 ++++++++-- 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/checks/itertools/itertools3.py b/checks/itertools/itertools3.py index 629c89d..2527119 100644 --- a/checks/itertools/itertools3.py +++ b/checks/itertools/itertools3.py @@ -1,2 +1,10 @@ -assert coordinates == [(0, "low"), (0, "high"), (1, "low"), (1, "high")] +assert coordinates == [ + (0, "low"), + (0, "high"), + (1, "low"), + (1, "high"), +], ( + "coordinates should contain every (x, y) pair from xs and ys, " + f"got {coordinates!r}" +) print("itertools3 ok") diff --git a/checks/itertools/itertools4.py b/checks/itertools/itertools4.py index 858745e..fc6f17a 100644 --- a/checks/itertools/itertools4.py +++ b/checks/itertools/itertools4.py @@ -1,2 +1,8 @@ -assert grouped == {"fruit": ["apple", "pear"], "veg": ["carrot"]} +assert grouped == { + "fruit": ["apple", "pear"], + "veg": ["carrot"], +}, ( + "grouped should map each category to its item names, " + f"got {grouped!r}" +) print("itertools4 ok") diff --git a/checks/itertools/itertools5.py b/checks/itertools/itertools5.py index de89c34..838ce14 100644 --- a/checks/itertools/itertools5.py +++ b/checks/itertools/itertools5.py @@ -1,2 +1,5 @@ -assert running_totals == [3, 7, 12, 18] +assert running_totals == [3, 7, 12, 18], ( + "running_totals should contain cumulative sums [3, 7, 12, 18], " + f"got {running_totals!r}" +) print("itertools5 ok") diff --git a/checks/itertools/itertools6.py b/checks/itertools/itertools6.py index ffb0e86..b72da97 100644 --- a/checks/itertools/itertools6.py +++ b/checks/itertools/itertools6.py @@ -1,2 +1,5 @@ -assert repeated == ["red", "blue", "red", "blue", "red", "blue"] +assert repeated == ["red", "blue", "red", "blue", "red", "blue"], ( + "repeated should cycle through colors for six values, " + f"got {repeated!r}" +) print("itertools6 ok") diff --git a/checks/itertools/itertools7.py b/checks/itertools/itertools7.py index 6a3219b..d955fed 100644 --- a/checks/itertools/itertools7.py +++ b/checks/itertools/itertools7.py @@ -1,2 +1,5 @@ -assert pairs == [("a", 1), ("b", "?"), ("c", "?")] +assert pairs == [("a", 1), ("b", "?"), ("c", "?")], ( + "pairs should fill missing right-side values with '?', " + f"got {pairs!r}" +) print("itertools7 ok") diff --git a/checks/itertools/itertools8.py b/checks/itertools/itertools8.py index e188cba..77605aa 100644 --- a/checks/itertools/itertools8.py +++ b/checks/itertools/itertools8.py @@ -1,3 +1,9 @@ -assert flattened == [1, 2, 3, 4, 5] -assert adjacent_pairs == [(1, 2), (2, 3), (3, 4), (4, 5)] +assert flattened == [1, 2, 3, 4, 5], ( + "flattened should contain all batch items in order, " + f"got {flattened!r}" +) +assert adjacent_pairs == [(1, 2), (2, 3), (3, 4), (4, 5)], ( + "adjacent_pairs should contain each neighboring pair, " + f"got {adjacent_pairs!r}" +) print("itertools8 ok")