|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from pyk.cterm import CTerm |
| 8 | +from pyk.kast.inner import KApply, KSequence, KVariable |
| 9 | +from pyk.prelude.ml import mlTop |
| 10 | +from pyk.testing import KCFGExploreTest |
| 11 | + |
| 12 | +from ..utils import K_FILES |
| 13 | + |
| 14 | +if TYPE_CHECKING: |
| 15 | + from collections.abc import Iterable |
| 16 | + |
| 17 | + from pyk.kcfg import KCFGExplore |
| 18 | + |
| 19 | + |
| 20 | +EXECUTE_TEST_DATA: Iterable[tuple[str]] = (('branch',),) |
| 21 | + |
| 22 | + |
| 23 | +class TestMultipleDefinitionsProof(KCFGExploreTest): |
| 24 | + KOMPILE_MAIN_FILE = K_FILES / 'multiple-definitions.k' |
| 25 | + |
| 26 | + @staticmethod |
| 27 | + def config() -> CTerm: |
| 28 | + return CTerm( |
| 29 | + KApply( |
| 30 | + '<generatedTop>', |
| 31 | + KApply('<k>', KSequence(KApply('a', [KVariable('X')]))), |
| 32 | + KVariable('GENERATED_COUNTER_CELL'), |
| 33 | + ), |
| 34 | + (mlTop(),), |
| 35 | + ) |
| 36 | + |
| 37 | + @pytest.mark.parametrize( |
| 38 | + 'test_id', |
| 39 | + EXECUTE_TEST_DATA, |
| 40 | + ids=[test_id for test_id, *_ in EXECUTE_TEST_DATA], |
| 41 | + ) |
| 42 | + def test_execute( |
| 43 | + self, |
| 44 | + kcfg_explore: KCFGExplore, |
| 45 | + test_id: str, |
| 46 | + ) -> None: |
| 47 | + split_depth, split_post_term, split_next_terms, _logs = kcfg_explore.cterm_execute(self.config(), depth=1) |
| 48 | + |
| 49 | + split_k = kcfg_explore.kprint.pretty_print(split_post_term.cell('K_CELL')) |
| 50 | + split_next_k = [kcfg_explore.kprint.pretty_print(split_post_term.cell('K_CELL')) for term in split_next_terms] |
| 51 | + |
| 52 | + assert split_depth == 0 |
| 53 | + assert len(split_next_terms) == 2 |
| 54 | + assert 'a ( X:KItem )' == split_k |
| 55 | + assert [ |
| 56 | + 'a ( X:KItem )', |
| 57 | + 'a ( X:KItem )', |
| 58 | + ] == split_next_k |
| 59 | + |
| 60 | + step_1_depth, step_1_post_term, step_1_next_terms, _logs = kcfg_explore.cterm_execute( |
| 61 | + split_next_terms[0], depth=1 |
| 62 | + ) |
| 63 | + step_1_k = kcfg_explore.kprint.pretty_print(step_1_post_term.cell('K_CELL')) |
| 64 | + assert 'c' == step_1_k |
| 65 | + |
| 66 | + step_2_depth, step_2_post_term, step_2_next_terms, _logs = kcfg_explore.cterm_execute( |
| 67 | + split_next_terms[1], depth=1 |
| 68 | + ) |
| 69 | + step_2_k = kcfg_explore.kprint.pretty_print(step_1_post_term.cell('K_CELL')) |
| 70 | + assert 'c' == step_2_k |
0 commit comments