def test_regex(self): rect_attrs = ('x1', 'y1', 'x2', 'y2') for string, claim2 in self.sample_input: claim1 = Claim.from_string(string) self.assertEqual(claim1.claim_id, claim2.claim_id) for attr in rect_attrs: self.assertEqual(getattr(claim2.rect, attr, None), getattr(claim1.rect, attr, None))
def get_input(path=INPUT_PATH): """Get the problem input from the data file. Reads the file line by line and builds a dict by calling the factory method on Claim. Invalid claims are filtered out. The keys are the claim IDs. Params: path - Path to input file""" with open(path) as f: claims = [Claim.from_string(line) for line in f] return {claim.claim_id: claim for claim in claims if claim is not None}
def get_input(path=INPUT_PATH): """Get the problem input from the data file. Reads the file line by line and builds a list by calling the factory method on Claim. Invalid claims are filtered out. Params: path - Path to input file""" with open(path) as f: lines = [Claim.from_string(line) for line in f] # Invalid lines (blanks) will be None so filter them out return [claim for claim in lines if claim is not None]