@@ -84,6 +84,25 @@ def _product(left: list[list[int]], right: list[list[int]]) -> list[list[int]]:
8484 return [sorted (neighbors ) for neighbors in result ]
8585
8686
87+ def _frozen_graphs (graphs : list [object ]) -> dict [str , list [list [int ]]] | None :
88+ by_id : dict [str , list [list [int ]]] = {}
89+ for graph in graphs :
90+ if (
91+ not isinstance (graph , dict )
92+ or set (graph ) != {"id" , "adjacency" }
93+ or graph .get ("id" ) not in GRAPH_IDS
94+ or graph ["id" ] in by_id
95+ ):
96+ return None
97+ adjacency = _adjacency (graph ["adjacency" ])
98+ if adjacency is None :
99+ return None
100+ by_id [graph ["id" ]] = adjacency
101+ if tuple (by_id ) != GRAPH_IDS :
102+ return None
103+ return by_id
104+
105+
87106def _frozen () -> dict [str , Any ] | None :
88107 try :
89108 value = json .loads ((TESTS / "input.json" ).read_text ())
@@ -106,20 +125,8 @@ def _frozen() -> dict[str, Any] | None:
106125 or len (pairs ) != 13
107126 ):
108127 return None
109- by_id : dict [str , list [list [int ]]] = {}
110- for graph in graphs :
111- if (
112- not isinstance (graph , dict )
113- or set (graph ) != {"id" , "adjacency" }
114- or graph .get ("id" ) not in GRAPH_IDS
115- or graph ["id" ] in by_id
116- ):
117- return None
118- adjacency = _adjacency (graph ["adjacency" ])
119- if adjacency is None :
120- return None
121- by_id [graph ["id" ]] = adjacency
122- if tuple (by_id ) != GRAPH_IDS :
128+ by_id = _frozen_graphs (graphs )
129+ if by_id is None :
123130 return None
124131 actual = []
125132 for pair in pairs :
@@ -167,17 +174,11 @@ def _product_witness(
167174 )
168175
169176
170- def _math (result : object , frozen : dict [str , Any ]) -> bool :
171- if (
172- not isinstance (result , dict )
173- or set (result ) != {"graphs" , "pairs" , "derived_conclusion" , "scope_identity" }
174- or result .get ("scope_identity" ) != SCOPE
175- ):
176- return False
177- graphs = frozen ["graphs" ]
178- expected = {name : _domination (graphs [name ]) for name in GRAPH_IDS }
179- if any (value is None for value in expected .values ()):
180- return False
177+ def _math_graphs (
178+ result : dict [str , Any ],
179+ graphs : dict [str , list [list [int ]]],
180+ expected : dict [str , Any ],
181+ ) -> bool :
181182 rows = result .get ("graphs" )
182183 if not isinstance (rows , list ) or len (rows ) != 8 :
183184 return False
@@ -204,11 +205,17 @@ def _math(result: object, frozen: dict[str, Any]) -> bool:
204205 or not _dominates (row ["minimum_dominating_set" ], gamma , adjacency )
205206 ):
206207 return False
207- if seen != set (GRAPH_IDS ):
208- return False
208+ return seen == set (GRAPH_IDS )
209+
210+
211+ def _math_pairs (
212+ result : dict [str , Any ],
213+ graphs : dict [str , list [list [int ]]],
214+ expected : dict [str , Any ],
215+ ) -> bool | None :
209216 rows = result .get ("pairs" )
210217 if not isinstance (rows , list ) or len (rows ) != 13 :
211- return False
218+ return None
212219 seen_pairs : set [tuple [str , str ]] = set ()
213220 all_hold = True
214221 for row in rows :
@@ -226,10 +233,10 @@ def _math(result: object, frozen: dict[str, Any]) -> bool:
226233 "bound_holds" ,
227234 }
228235 if not isinstance (row , dict ) or set (row ) != required :
229- return False
236+ return None
230237 pair = (row .get ("left" ), row .get ("right" ))
231238 if pair not in PAIR_IDS or pair in seen_pairs :
232- return False
239+ return None
233240 seen_pairs .add (pair )
234241 left , right = pair
235242 left_adj , right_adj = graphs [left ], graphs [right ]
@@ -238,7 +245,7 @@ def _math(result: object, frozen: dict[str, Any]) -> bool:
238245 product_adj = _product (left_adj , right_adj )
239246 product_value = _domination (product_adj )
240247 if product_value is None :
241- return False
248+ return None
242249 product_gamma = product_value [0 ]
243250 if (
244251 row ["gamma_left" ] != left_gamma
@@ -257,12 +264,31 @@ def _math(result: object, frozen: dict[str, Any]) -> bool:
257264 len (right_adj ),
258265 )
259266 ):
260- return False
267+ return None
261268 holds = product_gamma >= left_gamma * right_gamma
262269 if row ["bound_holds" ] is not holds :
263- return False
270+ return None
264271 all_hold = all_hold and holds
265272 if seen_pairs != set (PAIR_IDS ):
273+ return None
274+ return all_hold
275+
276+
277+ def _math (result : object , frozen : dict [str , Any ]) -> bool :
278+ if (
279+ not isinstance (result , dict )
280+ or set (result ) != {"graphs" , "pairs" , "derived_conclusion" , "scope_identity" }
281+ or result .get ("scope_identity" ) != SCOPE
282+ ):
283+ return False
284+ graphs = frozen ["graphs" ]
285+ expected = {name : _domination (graphs [name ]) for name in GRAPH_IDS }
286+ if any (value is None for value in expected .values ()):
287+ return False
288+ if not _math_graphs (result , graphs , expected ):
289+ return False
290+ all_hold = _math_pairs (result , graphs , expected )
291+ if all_hold is None :
266292 return False
267293 return result .get ("derived_conclusion" ) == (
268294 "HOLDS_ON_FROZEN_PAIR_SET" if all_hold else "VIOLATION_IN_FROZEN_PAIR_SET"
0 commit comments