Ejemplo n.º 1
0
    def test_unary_ops_resolve_correctly(self):
        unary_type = UnaryOpType()

        # Resolution should fail against a basic type
        assert unary_type.resolve(ROW_TYPE) is None

        # Resolution should fail against a complex type where the argument and return types are not same
        assert unary_type.resolve(ComplexType(CELL_TYPE, ROW_TYPE)) is None

        # Resolution should resolve ANY_TYPE given the other type
        resolution = unary_type.resolve(ComplexType(ANY_TYPE, ROW_TYPE))
        assert resolution == UnaryOpType(ROW_TYPE)
        resolution = unary_type.resolve(ComplexType(CELL_TYPE, ANY_TYPE))
        assert resolution == UnaryOpType(CELL_TYPE)

        reverse_type = ComplexType(ComplexType(CELL_TYPE, ROW_TYPE), ComplexType(CELL_TYPE, ROW_TYPE))
        resolution = unary_type.resolve(reverse_type)
        assert resolution == UnaryOpType(ComplexType(CELL_TYPE, ROW_TYPE))
Ejemplo n.º 2
0
 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"]
Ejemplo n.º 3
0
    def test_unary_ops_resolve_correctly(self):
        unary_type = UnaryOpType()

        # Resolution should fail against a basic type
        assert unary_type.resolve(ROW_TYPE) is None

        # Resolution should fail against a complex type where the argument and return types are not same
        assert unary_type.resolve(ComplexType(CELL_TYPE, ROW_TYPE)) is None

        # Resolution should resolve ANY_TYPE given the other type
        resolution = unary_type.resolve(ComplexType(ANY_TYPE, ROW_TYPE))
        assert resolution == UnaryOpType(ROW_TYPE)
        resolution = unary_type.resolve(ComplexType(CELL_TYPE, ANY_TYPE))
        assert resolution == UnaryOpType(CELL_TYPE)

        reverse_type = ComplexType(ComplexType(CELL_TYPE, ROW_TYPE), ComplexType(CELL_TYPE, ROW_TYPE))
        resolution = unary_type.resolve(reverse_type)
        assert resolution == UnaryOpType(ComplexType(CELL_TYPE, ROW_TYPE))
Ejemplo n.º 4
0
BASIC_TYPES = {CELL_TYPE, PART_TYPE, ROW_TYPE, DATE_TYPE, NUMBER_TYPE}
# Functions like fb:row.row.year.
COLUMN_TYPE = ComplexType(CELL_TYPE, ROW_TYPE)
# fb:cell.cell.part
PART_TO_CELL_TYPE = ComplexType(PART_TYPE, CELL_TYPE)
# fb:cell.cell.date
DATE_TO_CELL_TYPE = ComplexType(DATE_TYPE, CELL_TYPE)
# fb:cell.cell.number
NUM_TO_CELL_TYPE = ComplexType(NUMBER_TYPE, CELL_TYPE)
# number
NUMBER_FUNCTION_TYPE = ComplexType(NUMBER_TYPE, NUMBER_TYPE)
# date (Signature: <e,<e,<e,d>>>; Example: (date 1982 -1 -1))
DATE_FUNCTION_TYPE = ComplexType(NUMBER_TYPE,
                                 ComplexType(NUMBER_TYPE, ComplexType(NUMBER_TYPE, DATE_TYPE)))
# Unary numerical operations: max, min, >, <, sum etc.
UNARY_DATE_NUM_OP_TYPE = UnaryOpType(allowed_substitutions={DATE_TYPE, NUMBER_TYPE},
                                     signature='<nd,nd>')
UNARY_NUM_OP_TYPE = ComplexType(NUMBER_TYPE, NUMBER_TYPE)

# Binary numerical operation: -
BINARY_NUM_OP_TYPE = ComplexType(NUMBER_TYPE, ComplexType(NUMBER_TYPE, NUMBER_TYPE))

# next
ROW_TO_ROW_TYPE = ComplexType(ROW_TYPE, ROW_TYPE)
# reverse
REVERSE_TYPE = ReverseType(ComplexType(ANY_TYPE, ANY_TYPE), ComplexType(ANY_TYPE, ANY_TYPE))
# !=, fb:type.object.type
# fb:type.object.type takes a type and returns all objects of that type.
IDENTITY_TYPE = UnaryOpType()
# index
ROW_INDEX_TYPE = ComplexType(NUMBER_TYPE, ROW_TYPE)
# count