File size: 3,236 Bytes
28adce7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
76
from __future__ import annotations

import tempfile
import unittest
from pathlib import Path

from t3 import backend
from t3.evaluate import _manual_progress


class ManualProgressTests(unittest.TestCase):
    def test_counts_only_required_top_level_admitted_goals(self) -> None:
        with tempfile.TemporaryDirectory() as directory:
            root = Path(directory)
            workspace = root / "ws"
            skeleton = workspace / "problem/groundtruth/demo_proof_manual.skel.v"
            skeleton.parent.mkdir(parents=True)
            skeleton.write_text(
                "Lemma proof_of_x_split_goal_1 : x1.\nProof. Abort.\n\n"
                "Lemma proof_of_x : x.\nProof. Admitted.\n\n"
                "Lemma proof_of_y : y.\nProof. Admitted.\n"
            )
            # Redirect the case output by temporarily constructing its expected tree under T3
            # is undesirable in a unit test, so exercise a small equivalent local Case subclass.
            class LocalCase:
                id = "demo"
                manual_name = "demo_proof_manual.v"
                suffix = ".v"
                be = backend.ROCQ
                out_dir = root / "out"

            LocalCase.out_dir.mkdir()
            (LocalCase.out_dir / LocalCase.manual_name).write_text(
                "Lemma proof_of_x_split_goal_1 : x1. Proof. Abort.\n"
                "Lemma proof_of_x : x.\nProof. exact px. Qed.\n"
                "Lemma proof_of_y : y.\nProof. exact py. Abort.\n"
            )
            progress = _manual_progress(LocalCase, workspace, "FAILED")
            self.assertEqual(progress["residual_vcs"], 2)
            self.assertEqual(progress["source_closed"], 1)
            self.assertEqual(progress["source_closed_names"], ["proof_of_x"])
            self.assertEqual(progress["kernel_checked"], 0)

    def test_lean_counts_theorems_not_example_stubs(self) -> None:
        with tempfile.TemporaryDirectory() as directory:
            root = Path(directory)
            workspace = root / "ws"
            skeleton = workspace / "problem/groundtruth/demo_proof_manual.skel.lean"
            skeleton.parent.mkdir(parents=True)
            skeleton.write_text(
                "example : demo_goal.x_split_goal_1 := by\n  sorry\n\n"
                "theorem proof_of_x : demo_goal.x := by\n  sorry\n\n"
                "theorem proof_of_y : demo_goal.y := by\n  sorry\n"
            )

            class LocalCase:
                id = "demo"
                manual_name = "demo_proof_manual.lean"
                suffix = ".lean"
                be = backend.LEAN
                out_dir = root / "out"

            LocalCase.out_dir.mkdir()
            (LocalCase.out_dir / LocalCase.manual_name).write_text(
                "theorem proof_of_x : demo_goal.x := by\n  unfold demo_goal.x\n  omega\n\n"
                "theorem proof_of_y : demo_goal.y := by\n  sorry\n"
            )
            progress = _manual_progress(LocalCase, workspace, "FAILED")
            self.assertEqual(progress["residual_vcs"], 2)
            self.assertEqual(progress["source_closed_names"], ["proof_of_x"])
            self.assertEqual(progress["kernel_checked"], 0)


if __name__ == "__main__":
    unittest.main()