Spaces:
Running
Running
File size: 2,548 Bytes
59a8d26 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | 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"
|