Пример #1
0
def check_attribute(context, var, att, expected):
    if expected == "identity_matrix":
        exp = identity(4)  # type: Union[Matrix, float]
    elif is_number(expected):
        exp = float(expected)
    elif expected == "true":
        exp = True
    elif expected == "false":
        exp = False
    else:
        exp = context.variables[expected]

    my_variable = context.variables[var]
    if att == "count":
        assert len(my_variable) == exp
    elif isinstance(exp, float) or isinstance(exp, int):
        assert equals(exp, getattr(my_variable, att))
    else:
        assert getattr(my_variable, att) == exp, f"{getattr(my_variable, att)} == {exp}"
Пример #2
0
def assign_attribute(context, var, attr, value):
    val = float(value) if is_number(value) else context.variables[value]
    variable = context.variables[var]
    setattr(variable, attr, val)
Пример #3
0
def check_tuple_multiplication(context, var_1, var_2, x, y, z, w):
    variable_1 = float(var_1) if is_number(var_1) else context.variables[var_1]
    variable_2 = float(var_2) if is_number(var_2) else context.variables[var_2]
    expected = Tuple(x, y, z, w)
    assert variable_1 * variable_2 == expected
Пример #4
0
def check_tuple_type(context, var, tuple_type, x, y, z):
    variable = float(var) if is_number(var) else context.variables[var]
    expected = create_structure(tuple_type, x, y, z)
    assert expected.approximately_equals(variable), f"{expected} ~= {variable}"
Пример #5
0
def check_multiplication(context, var_1, var_2, tuple_type, x, y, z):
    variable_1 = float(var_1) if is_number(var_1) else context.variables[var_1]
    variable_2 = float(var_2) if is_number(var_2) else context.variables[var_2]
    expected = create_structure(tuple_type, x, y, z)
    assert expected.approximately_equals(variable_1 * variable_2)
Пример #6
0
def check_list_member_attribute(context, var, index, attribute, expected):
    exp = float(expected) if is_number(
        expected) else context.variables[expected]
    array = context.variables[var]
    assert getattr(array[index], attribute) == exp