File size: 3,006 Bytes
2dbfb72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
71
72
73
74
75
from typing import List, Tuple, Dict


def assert_test_format_codeforces(tests: List[Tuple[List[str], str]]):
    assert isinstance(tests, list) or tests is None
    if tests is None:
        return
    for test in tests:
        assert isinstance(test, list)
        assert len(test) == 2
        inputs, outputs = test
        assert isinstance(inputs, list)
        assert isinstance(outputs, str)
        for input in inputs:
            assert isinstance(input, str)


def assert_entry_format_codeforces(obj: Dict):
    # each data point must follow the same schema
    assert isinstance(obj["id"], str)  # contest + problem_name = id, will not change when formatting changes
    assert isinstance(obj["id_hash"], str)  # hashsum of all entries, any change to obj will change this
    assert isinstance(obj["contest"], int)
    assert isinstance(obj["problem_name"], str)
    assert isinstance(obj["problem_url"], str)
    assert isinstance(obj["solution_url"], str)

    assert isinstance(obj["header"], str)
    assert isinstance(obj["problem_description"], str)
    assert isinstance(obj["input_description"], str)
    assert isinstance(obj["output_description"], str)
    assert isinstance(obj["note"], str) or obj["note"] is None

    assert isinstance(obj["difficulty"], int)
    assert isinstance(obj["tags"], list)
    assert isinstance(obj["working_solution"], str)  # can be empty

    assert_test_format_codeforces(obj["public_tests_io"])
    assert_test_format_codeforces(obj["public_tests_individual_io"])
    assert_test_format_codeforces(obj["hidden_tests_io"])


def assert_test_format_leetcode(tests: List[Tuple[List[str], str]]):
    pass
    # ToDo: Uncomment after the test format is updated
    # assert isinstance(tests, list)
    # for test in tests:
    #     assert isinstance(test, tuple)
    #     assert len(test) == 2
    #     x, y = test
    #     assert isinstance(x, str)
    #     assert isinstance(y, str)


def assert_entry_format_leetcode(obj: Dict):
    # each data point must follow the same schema
    assert isinstance(obj["id"], str)  # contest + problem_name = id, will not change when formatting changes
    assert isinstance(obj["id_hash"], str)  # hashsum of all entries, any change to obj will change this
    assert isinstance(obj["index"], int)
    assert isinstance(obj["problem_name"], str)
    assert isinstance(obj["problem_url"], str)

    assert isinstance(obj["problem_description"], str)
    assert isinstance(obj["constraints"], str)
    assert isinstance(obj["python_stub"], str)
    assert isinstance(obj["difficulty"], str) and obj["difficulty"] in {"easy", "medium", "hard"}

    # ToDo: Should be added
    # assert isinstance(obj['tags'], list)
    # assert isinstance(obj['solution_url'], str)
    # assert isinstance(obj['working_solution'], str)  # can be empty

    # ToDo: Uncomment after the test format is updated
    # assert_test_format_leetcode(obj['public_tests_io'])
    # assert_test_format_leetcode(obj['hidden_tests_io'])