from gdrive_sync import parse_problem_body class TestGdriveSyncParsing: def test_single_method_with_generic_header(self): """When a doc has 'Method 1:' without a specific name, clean name to problem_name.""" body = """ Easy Method 1: Time Complexity: O(N) Space Complexity: O(N) def solve(): pass """ methods = parse_problem_body("Two Sum", body) assert len(methods) == 1 assert methods[0]["name"] == "Two Sum" assert methods[0]["pattern"] == "General Algorithm" assert methods[0]["difficulty"] == "Easy" assert methods[0]["optimal_time"] == "O(N)" assert methods[0]["optimal_space"] == "O(N)" def test_single_method_with_named_approach(self): """When a doc has 'Method 1 (Hash Map (One-Pass)):', capture the approach.""" body = """ Easy Method 1 (Hash Map (One-Pass)): Time Complexity: O(N) Space Complexity: O(N) def solve(): pass """ methods = parse_problem_body("Two Sum", body) assert len(methods) == 1 assert methods[0]["name"] == "Two Sum - Method 1 (Hash Map (One-Pass))" assert methods[0]["pattern"] == "Hash Map (One-Pass)" def test_multiple_methods_distinction(self): """When multiple methods are present, ensure distinct method indices without echo.""" body = """ Medium Method 1: Time Complexity: O(N^2) Space Complexity: O(1) def solve_brute(): pass Method 2 (Two Pointers): Time Complexity: O(N) Space Complexity: O(1) def solve_two_pointers(): pass """ methods = parse_problem_body("Two Sum II", body) assert len(methods) == 2 assert methods[0]["name"] == "Two Sum II - Method 1" assert methods[0]["pattern"] == "General Algorithm" assert methods[1]["name"] == "Two Sum II - Method 2 (Two Pointers)" assert methods[1]["pattern"] == "Two Pointers" def test_no_method_headers_fallback(self): """When no 'Method X' headers exist, problem should have clean name.""" body = """ Easy Pattern: Arrays & Hashing Time Complexity: O(N) Space Complexity: O(N) def solve(): pass """ methods = parse_problem_body("Contains Duplicate", body) assert len(methods) == 1 assert methods[0]["name"] == "Contains Duplicate" assert methods[0]["pattern"] == "Arrays & Hashing"