Exemplo n.º 1
0
def test_char_map_evaluation():
    """Test the characteristc map evaluation."""

    # create a characteristc line with values of y=(x-2)^2
    x = [1, 2, 3]
    y = np.array([[1, 2, 3], [2, 3, 4], [3, 4, 5]])
    z1 = y**0.5
    z2 = y**2
    map = char_map(x=x, y=y, z1=z1, z2=z2)

    # test evaluation at x=2 and y=3, result: z1=1.73, z2=9
    x = 2
    y = 3
    z1, z2 = map.evaluate(x=x, y=y)
    msg = ("The evaluation of x=" + str(x) + " and y=" + str(y) + " for z1 "
           "must be 1.73, but is " + str(round(z1, 2)) + ".")
    assert round(z1, 2) == 1.73, msg

    msg = ("The evaluation of x=" + str(x) + " and y=" + str(y) + " for z2 "
           "must be 9.0, but is " + str(round(z2, 1)) + ".")
    assert round(z2, 1) == 9.0, msg

    # test evaluation at x=0 and y=0 for lower value range limit,
    # result: z1=1, z2=1
    x = 0
    y = 0
    z1, z2 = map.evaluate(x=x, y=y)
    msg = ("The evaluation of x=" + str(x) + " and y=" + str(y) + " for z1 "
           "must be 1.0, but is " + str(round(z1, 1)) + ".")
    assert round(z1, 1) == 1.0, msg

    msg = ("The evaluation of x=" + str(x) + " and y=" + str(y) + " for z2 "
           "must be 1.0, but is " + str(round(z2, 1)) + ".")
    assert round(z2, 1) == 1.0, msg

    # test evaluation at x=4 and y=6 for upper value range limit,
    # result: z1=2.24, z2=25
    x = 4
    y = 6
    z1, z2 = map.evaluate(x=x, y=y)
    msg = ("The evaluation of x=" + str(x) + " and y=" + str(y) + " for z1 "
           "must be 2.24, but is " + str(round(z1, 2)) + ".")
    assert round(z1, 2) == 2.24, msg

    msg = ("The evaluation of x=" + str(x) + " and y=" + str(y) + " for z2 "
           "must be 25.0, but is " + str(round(z2, 1)) + ".")
    assert round(z2, 1) == 25.0, msg

    # check, if bound errors go through
    map.get_bound_errors(x, y, 'Componentlabel')
Exemplo n.º 2
0
def test_get_attr_errors():
    """Test errors of get_attr methods."""
    nw = network(['water', 'air'])
    comb = combustion.combustion_engine('combustion engine')
    pipeline = piping.pipe('pipeline')
    conn = connection(comb, 'out1', pipeline, 'in1')
    mybus = bus('mybus')
    sub = subsystems.subsystem('MySub')

    get_attr_KeyError(comb, 'wow')
    get_attr_KeyError(conn, 'key')
    get_attr_KeyError(mybus, 'components')
    get_attr_KeyError(nw, 'missing')
    get_attr_KeyError(ref(conn, 1, 0), 'comp')
    get_attr_KeyError(sub, 'test')
    get_attr_KeyError(char_line(), 'test')
    get_attr_KeyError(data_container(), 'somekey')
    get_attr_KeyError(char_map(), 'Stuff')
Exemplo n.º 3
0
def test_char_map_number_of_dimensions():
    char_map(x=[0, 1, 2], y=[[1, 2, 3, 4], [1, 2, 3, 4]])
Exemplo n.º 4
0
def test_char_map_number_of_points():
    char_map(x=[0, 1, 2], y=[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3]])
Exemplo n.º 5
0
def test_char_map_y_z_dimension_mismatch():
    with raises(ValueError):
        char_map(x=[0, 1],
                 y=[[1, 2, 3, 4], [1, 2, 3, 4]],
                 z1=[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]],
                 z2=[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]])
Exemplo n.º 6
0
def test_char_map_number_of_dimensions():
    with raises(ValueError):
        char_map(x=[0, 1, 2], y=[[1, 2, 3, 4], [1, 2, 3, 4]])
Exemplo n.º 7
0
def test_char_map_number_of_points():
    with raises(ValueError):
        char_map(x=[0, 1, 2], y=[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3]])
Exemplo n.º 8
0
def test_char_map_get_attr():
    char_map().get_attr('Stuff')
Exemplo n.º 9
0
def test_char_map_y_z_dimension_mismatch():
    char_map(x=[0, 1],
             y=[[1, 2, 3, 4], [1, 2, 3, 4]],
             z1=[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]],
             z2=[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]])