def get_valid_actions(self) -> Dict[str, List[str]]: if not self._valid_actions: multi_match_mapping = self.get_multi_match_mapping() self._valid_actions = types.get_valid_actions( self.get_name_mapping(), self.get_type_signatures(), self.get_basic_types(), valid_starting_types=self.get_valid_starting_types(), num_nested_lambdas=self._num_nested_lambdas, multi_match_mapping=multi_match_mapping) return self._valid_actions
def test_get_valid_actions_with_placeholder_type(self): type_r = NamedBasicType("R") type_d = NamedBasicType("D") type_e = NamedBasicType("E") name_mapping = {'sample_function': 'F'} # <#1,#1> type_signatures = {'F': UnaryOpType()} basic_types = {type_r, type_d, type_e} valid_actions = types.get_valid_actions(name_mapping, type_signatures, basic_types) assert len(valid_actions) == 5 assert valid_actions["<#1,#1>"] == ["<#1,#1> -> sample_function"] assert valid_actions["e"] == ["e -> [<#1,#1>, e]"] assert valid_actions["r"] == ["r -> [<#1,#1>, r]"] assert valid_actions["d"] == ["d -> [<#1,#1>, d]"] assert valid_actions["@start@"] == [ "@start@ -> d", "@start@ -> e", "@start@ -> r" ]
def test_get_valid_actions(self): type_r = NamedBasicType("R") type_d = NamedBasicType("D") type_e = NamedBasicType("E") name_mapping = {'sample_function': 'F'} # <e,<r,<d,r>>> type_signatures = { 'F': ComplexType(type_e, ComplexType(type_r, ComplexType(type_d, type_r))) } basic_types = {type_r, type_d, type_e} valid_actions = types.get_valid_actions(name_mapping, type_signatures, basic_types) assert len(valid_actions) == 3 assert valid_actions["<e,<r,<d,r>>>"] == [ "<e,<r,<d,r>>> -> sample_function" ] assert valid_actions["r"] == ["r -> [<e,<r,<d,r>>>, e, r, d]"] assert valid_actions["@start@"] == [ "@start@ -> d", "@start@ -> e", "@start@ -> r" ]
def test_get_valid_actions_with_any_type(self): type_r = NamedBasicType("R") type_d = NamedBasicType("D") type_e = NamedBasicType("E") name_mapping = {'sample_function': 'F'} # The purpose of this test is to ensure that ANY_TYPE gets substituted by every possible basic type, # to simulate an intermediate step while getting actions for a placeholder type. # I do not foresee defining a function type with ANY_TYPE. We should just use a ``PlaceholderType`` # instead. # <?,r> type_signatures = {'F': ComplexType(ANY_TYPE, type_r)} basic_types = {type_r, type_d, type_e} valid_actions = types.get_valid_actions(name_mapping, type_signatures, basic_types) assert len(valid_actions) == 5 assert valid_actions["<d,r>"] == ["<d,r> -> sample_function"] assert valid_actions["<e,r>"] == ["<e,r> -> sample_function"] assert valid_actions["<r,r>"] == ["<r,r> -> sample_function"] assert valid_actions["r"] == [ "r -> [<d,r>, d]", "r -> [<e,r>, e]", "r -> [<r,r>, r]" ] assert valid_actions["@start@"] == [ "@start@ -> d", "@start@ -> e", "@start@ -> r" ]