示例#1
0
def test_compu_method_tab_nointerp_both_defaults():
    parser = ParserWrapper('a2l', 'module', A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.TAB_NOINTP.DEFAULT_VALUE
          ""
          TAB_NOINTP "%8.4" "U/  min  "
          COMPU_TAB_REF CM.TAB_NOINTP.DEFAULT_VALUE.REF
        /end COMPU_METHOD
        /begin COMPU_TAB CM.TAB_NOINTP.DEFAULT_VALUE.REF
           ""
           TAB_NOINTP
           12
           -3 98
           -1 99
           0 100
           2 102
           4 104
           5 105
           6 106
           7 107
           8 108
           9 109
           10 110
           13 111
           DEFAULT_VALUE "value out of range"
           DEFAULT_VALUE_NUMERIC 300.56 /* DEFAULT_VALUE_NUME RIC should be used here as the normal output is numeric */
        /end COMPU_TAB
    /end MODULE
    """
    session = parser.parseFromString(DATA)
    module = session.query(model.Module).first()
    with pytest.raises(exceptions.StructuralError):
        compu = functions.CompuMethod(session, module.compu_method[0])
示例#2
0
def test_compu_method_tab_verb_no_default_value():
    parser = ParserWrapper("a2l", "module", A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.TAB_VERB.DEFAULT_VALUE
          "Verbal conversion with default value"
          TAB_VERB "%12.0" ""
          COMPU_TAB_REF CM.TAB_VERB.DEFAULT_VALUE.REF
        /end COMPU_METHOD
        /begin COMPU_VTAB CM.TAB_VERB.DEFAULT_VALUE.REF
          "List of text strings and relation to impl value"
          TAB_VERB 3
          1 "SawTooth"
          2 "Square"
          3 "Sinus"
        /end COMPU_VTAB
    /end MODULE
    """
    db = parser.parseFromString(DATA)
    module = db.session.query(model.Module).first()
    compu = functions.CompuMethod(
        db.session, inspect.CompuMethod(db.session,
                                        module.compu_method[0].name))
    assert compu.int_to_physical(1) == "SawTooth"
    assert compu.physical_to_int("Sinus") == 3
    assert compu.int_to_physical(10) is None
示例#3
0
def test_compu_method_formula_with_sysc():
    parser = ParserWrapper("a2l", "module", A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin MOD_PAR ""
             SYSTEM_CONSTANT "System_Constant_1" "42"
             SYSTEM_CONSTANT "System_Constant_2" "Textual constant"
        /end MOD_PAR

        /begin COMPU_METHOD CM.FORM.X_PLUS_SYSC
          ""
          FORM
          "%6.1"
          "rpm"
          /begin FORMULA
            "X1 + sysc(System_Constant_1)"
          /end FORMULA
        /end COMPU_METHOD
    /end MODULE
    """
    db = parser.parseFromString(DATA)
    module = db.session.query(model.Module).first()
    compu = functions.CompuMethod(
        db.session, inspect.CompuMethod(db.session,
                                        module.compu_method[0].name))
    assert compu.int_to_physical(23) == 65
示例#4
0
def test_compu_method_tab_nointerp_no_default():
    parser = ParserWrapper('a2l', 'module', A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.TAB_NOINTP.NO_DEFAULT_VALUE
          ""
          TAB_NOINTP "%8.4" "U/  min  "
          COMPU_TAB_REF CM.TAB_NOINTP.NO_DEFAULT_VALUE.REF
        /end COMPU_METHOD
        /begin COMPU_TAB CM.TAB_NOINTP.NO_DEFAULT_VALUE.REF
           ""
           TAB_NOINTP
           12
           -3 98
           -1 99
           0 100
           2 102
           4 104
           5 105
           6 106
           7 107
           8 108
           9 109
           10 110
           13 111
        /end COMPU_TAB
    /end MODULE
    """
    session = parser.parseFromString(DATA)
    module = session.query(model.Module).first()
    compu = functions.CompuMethod(session, module.compu_method[0])
    assert compu(-3) == 98
    assert compu(8) == 108
    assert compu.inv(108) == 8
    assert compu(1) is None
示例#5
0
def test_compu_method_tab_verb():
    parser = ParserWrapper('a2l', 'module', A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.TAB_VERB.DEFAULT_VALUE
          "Verbal conversion with default value"
          TAB_VERB "%12.0" ""
          COMPU_TAB_REF CM.TAB_VERB.DEFAULT_VALUE.REF
        /end COMPU_METHOD
        /begin COMPU_VTAB CM.TAB_VERB.DEFAULT_VALUE.REF
          "List of text strings and relation to impl value"
          TAB_VERB 3
          1 "SawTooth"
          2 "Square"
          3 "Sinus"
          DEFAULT_VALUE "unknown signal type"
        /end COMPU_VTAB
    /end MODULE
    """
    session = parser.parseFromString(DATA)
    module = session.query(model.Module).first()
    compu = functions.CompuMethod(session, module.compu_method[0])
    assert compu(1) == "SawTooth"
    assert compu.inv("Sinus") == 3
    assert compu(10) == "unknown signal type"
示例#6
0
def test_compu_method_tab_interp_default():
    parser = ParserWrapper("a2l", "module", A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.TAB_INTP.DEFAULT_VALUE
          ""
          TAB_INTP "%8.4" "U/  min  "
          COMPU_TAB_REF CM.TAB_INTP.DEFAULT_VALUE.REF
        /end COMPU_METHOD
        /begin COMPU_TAB CM.TAB_INTP.DEFAULT_VALUE.REF
           ""
           TAB_INTP
           12
           -3 98
           -1 99
           0 100
           2 102
           4 104
           5 105
           6 106
           7 107
           8 108
           9 109
           10 110
           13 111
           DEFAULT_VALUE_NUMERIC 300.56 /* DEFAULT_VALUE_NUME RIC should be used here as the normal output is numeric */
        /end COMPU_TAB
    /end MODULE
    """
    db = parser.parseFromString(DATA)
    module = db.session.query(model.Module).first()
    compu = functions.CompuMethod(
        db.session, inspect.CompuMethod(db.session,
                                        module.compu_method[0].name))
    xs = np.arange(-3, 14)
    ys = np.array([
        98.0,
        98.5,
        99.0,
        100.0,
        101.0,
        102.0,
        103.0,
        104.0,
        105.0,
        106.0,
        107.0,
        108.0,
        109.0,
        110.0,
        110.33333333333333,
        110.66666666666667,
        111.0,
    ])
    assert np.array_equal(compu.int_to_physical(xs), ys)
    assert compu.int_to_physical(-3) == 98
    assert compu.int_to_physical(8) == 108
    assert compu.int_to_physical(14) == 300.56
    assert compu.int_to_physical(-4) == 300.56
示例#7
0
def test_compu_method_invalid():
    parser = ParserWrapper('a2l', 'module', A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.TAB_VERB.DEFAULT_VALUE
          "Verbal conversion with default value"
          FOO_BAR "%12.0" ""
        /end COMPU_METHOD
    /end MODULE
    """
    session = parser.parseFromString(DATA)
    module = session.query(model.Module).first()
    compu = functions.CompuMethod(session, module.compu_method[0])
示例#8
0
def test_compu_method_rat_func_no_coeffs():
    parser = ParserWrapper('a2l', 'module', A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.RAT_FUNC.DIV_81_9175
          "rational function with parameter set for impl = f(phys) = phys * 81.9175"
          RAT_FUNC "%8.4" "grad C"
        /end COMPU_METHOD
    /end MODULE
    """
    session = parser.parseFromString(DATA)
    module = session.query(model.Module).first()
    with pytest.raises(exceptions.StructuralError):
        compu = functions.CompuMethod(session, module.compu_method[0])
示例#9
0
def test_compu_method_linear_no_coeffs():
    parser = ParserWrapper('a2l', 'module', A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.LINEAR.MUL_2
        "Linear function with parameter set for phys = f(int) = 2*int + 0"
         LINEAR "%3.1" "m/s"
        /end COMPU_METHOD
    /end MODULE
    """
    session = parser.parseFromString(DATA)
    module = session.query(model.Module).first()
    with pytest.raises(exceptions.StructuralError):
        compu = functions.CompuMethod(session, module.compu_method[0])
示例#10
0
def test_compu_method_tab_verb_no_vtab():
    parser = ParserWrapper('a2l', 'module', A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.TAB_VERB.DEFAULT_VALUE
          "Verbal conversion with default value"
          TAB_VERB "%12.0" ""
          COMPU_TAB_REF CM.TAB_VERB.DEFAULT_VALUE.REF
        /end COMPU_METHOD
    /end MODULE
    """
    session = parser.parseFromString(DATA)
    module = session.query(model.Module).first()
    with pytest.raises(exceptions.StructuralError):
        compu = functions.CompuMethod(session, module.compu_method[0])
示例#11
0
def test_compu_method_identical():
    parser = ParserWrapper('a2l', 'module', A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.IDENTICAL
          "conversion that delivers always phys = int"
          IDENTICAL "%3.0" "hours"
        /end COMPU_METHOD
    /end MODULE
    """
    session = parser.parseFromString(DATA)
    module = session.query(model.Module).first()
    compu = functions.CompuMethod(session, module.compu_method[0])
    xs = np.arange(-10, 11)
    assert np.array_equal(compu(xs), xs)
    assert np.array_equal(compu.inv(xs), xs)
示例#12
0
def test_compu_method_linear():
    parser = ParserWrapper('a2l', 'module', A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.LINEAR.MUL_2
        "Linear function with parameter set for phys = f(int) = 2*int + 0"
         LINEAR "%3.1" "m/s"
         COEFFS_LINEAR 2 0
        /end COMPU_METHOD
    /end MODULE
    """
    session = parser.parseFromString(DATA)
    module = session.query(model.Module).first()
    compu = functions.CompuMethod(session, module.compu_method[0])
    xs = np.arange(-10, 11)
    assert np.array_equal(compu(xs), xs * 2.0)
    assert np.array_equal(compu.inv(xs * 2.0), xs)
示例#13
0
def test_compu_method_rat_func_identical():
    parser = ParserWrapper('a2l', 'module', A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.RAT_FUNC.IDENT
          "rational function with parameter set for int = f(phys) = phys"
          RAT_FUNC "%3.1" "m/s"
          COEFFS 0 1 0 0 0 1
        /end COMPU_METHOD
    /end MODULE
    """
    session = parser.parseFromString(DATA)
    module = session.query(model.Module).first()
    compu = functions.CompuMethod(session, module.compu_method[0])
    xs = np.arange(-10, 11)
    assert np.array_equal(compu(xs), xs)
    assert np.array_equal(compu.inv(xs), xs)
示例#14
0
def test_compu_method_identical():
    parser = ParserWrapper("a2l", "module", A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.IDENTICAL
          "conversion that delivers always phys = int"
          IDENTICAL "%3.0" "hours"
        /end COMPU_METHOD
    /end MODULE
    """
    db = parser.parseFromString(DATA)
    module = db.session.query(model.Module).first()
    compu = functions.CompuMethod(
        db.session, inspect.CompuMethod(db.session,
                                        module.compu_method[0].name))
    xs = np.arange(-10, 11)
    assert np.array_equal(compu.int_to_physical(xs), xs)
    assert np.array_equal(compu.physical_to_int(xs), xs)
示例#15
0
def test_compu_method_formula_without_inv():
    parser = ParserWrapper('a2l', 'module', A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.FORM.X_PLUS_4
          ""
          FORM
          "%6.1"
          "rpm"
          /begin FORMULA
            "X1+4"
          /end FORMULA
        /end COMPU_METHOD
    /end MODULE
    """
    session = parser.parseFromString(DATA)
    module = session.query(model.Module).first()
    compu = functions.CompuMethod(session, module.compu_method[0])
    assert compu(6) == 10
示例#16
0
def test_compu_method_linear():
    parser = ParserWrapper("a2l", "module", A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.LINEAR.MUL_2
        "Linear function with parameter set for phys = f(int) = 2*int + 0"
         LINEAR "%3.1" "m/s"
         COEFFS_LINEAR 2 0
        /end COMPU_METHOD
    /end MODULE
    """
    db = parser.parseFromString(DATA)
    module = db.session.query(model.Module).first()
    compu = functions.CompuMethod(
        db.session, inspect.CompuMethod(db.session,
                                        module.compu_method[0].name))
    xs = np.arange(-10, 11)
    assert np.array_equal(compu.int_to_physical(xs), xs * 2.0)
    assert np.array_equal(compu.physical_to_int(xs * 2.0), xs)
示例#17
0
def test_compu_method_rat_func_linear():
    parser = ParserWrapper("a2l", "module", A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.RAT_FUNC.DIV_81_9175
          "rational function with parameter set for impl = f(phys) = phys * 81.9175"
          RAT_FUNC "%8.4" "grad C"
          COEFFS 0 81.9175 0 0 0 1
        /end COMPU_METHOD
    /end MODULE
    """
    db = parser.parseFromString(DATA)
    module = db.session.query(model.Module).first()
    compu = functions.CompuMethod(
        db.session, inspect.CompuMethod(db.session,
                                        module.compu_method[0].name))
    xs = np.arange(-10, 11)
    ys = np.array([
        -819.1750000000001,
        -737.2575,
        -655.34,
        -573.4225,
        -491.505,
        -409.58750000000003,
        -327.67,
        -245.7525,
        -163.835,
        -81.9175,
        0.0,
        81.9175,
        163.835,
        245.7525,
        327.67,
        409.58750000000003,
        491.505,
        573.4225,
        655.34,
        737.2575,
        819.1750000000001,
    ])
    assert np.array_equal(compu.int_to_physical(ys), xs)
    assert np.array_equal(compu.physical_to_int(xs), ys)
示例#18
0
def test_compu_method_tab_verb_ranges():
    parser = ParserWrapper("a2l", "module", A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.VTAB_RANGE.DEFAULT_VALUE
           "verbal range with default value"
           TAB_VERB
           "%4.2"
           ""
           COMPU_TAB_REF CM.VTAB_RANGE.DEFAULT_VALUE.REF
        /end COMPU_METHOD
        /begin COMPU_VTAB_RANGE CM.VTAB_RANGE.DEFAULT_VALUE.REF
           ""
           11
           0 1 "Zero_to_one"
           2 3 "two_to_three"
           4 7 "four_to_seven"
           14 17 "fourteen_to_seventeen"
           18 99 "eigteen_to_ninetynine"
           100 100 "hundred"
           101 101 "hundredone"
           102 102 "hundredtwo"
           103 103 "hundredthree"
           104 104 "hundredfour"
           105 105 "hundredfive"
           DEFAULT_VALUE "out of range value"
        /end COMPU_VTAB_RANGE
    /end MODULE
    """
    db = parser.parseFromString(DATA)
    module = db.session.query(model.Module).first()
    compu = functions.CompuMethod(
        db.session, inspect.CompuMethod(db.session,
                                        module.compu_method[0].name))
    assert compu.int_to_physical(0) == "Zero_to_one"
    assert compu.int_to_physical(6) == "four_to_seven"
    assert compu.int_to_physical(45) == "eigteen_to_ninetynine"
    assert compu.int_to_physical(100) == "hundred"
    assert compu.int_to_physical(105) == "hundredfive"
    assert compu.int_to_physical(-1) == "out of range value"
    assert compu.int_to_physical(106) == "out of range value"
    assert compu.int_to_physical(10) == "out of range value"
示例#19
0
def test_compu_method_tab_interp_no_default():
    parser = ParserWrapper('a2l', 'module', A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.TAB_INTP.NO_DEFAULT_VALUE
          ""
          TAB_INTP "%8.4" "U/  min  "
          COMPU_TAB_REF CM.TAB_INTP.NO_DEFAULT_VALUE.REF
        /end COMPU_METHOD
        /begin COMPU_TAB CM.TAB_INTP.NO_DEFAULT_VALUE.REF
           ""
           TAB_INTP
           12
           -3 98
           -1 99
           0 100
           2 102
           4 104
           5 105
           6 106
           7 107
           8 108
           9 109
           10 110
           13 111
        /end COMPU_TAB
    /end MODULE
    """
    session = parser.parseFromString(DATA)
    module = session.query(model.Module).first()
    compu = functions.CompuMethod(session, module.compu_method[0])
    xs = np.arange(-3, 14)
    ys = np.array(
        [98., 98.5, 99., 100., 101., 102., 103., 104., 105., 106.,
         107., 108., 109., 110., 110.33333333333333, 110.66666666666667, 111.]
    )
    assert np.array_equal(compu(xs), ys)
    assert compu(-3) == 98
    assert compu(8) == 108
    assert compu(14) is None
    assert compu(-4) is None
示例#20
0
def test_compu_method_formula_without_inv():
    parser = ParserWrapper("a2l", "module", A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.FORM.X_PLUS_4
          ""
          FORM
          "%6.1"
          "rpm"
          /begin FORMULA
            "X1+4"
          /end FORMULA
        /end COMPU_METHOD
    /end MODULE
    """
    db = parser.parseFromString(DATA)
    module = db.session.query(model.Module).first()
    compu = functions.CompuMethod(
        db.session, inspect.CompuMethod(db.session,
                                        module.compu_method[0].name))
    assert compu.int_to_physical(6) == 10
示例#21
0
def test_compu_method_tab_verb_ranges_no_default():
    parser = ParserWrapper('a2l', 'module', A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.VTAB_RANGE.NO_DEFAULT_VALUE
           "verbal range without default value"
           TAB_VERB
           "%4.2"
           ""
           COMPU_TAB_REF CM.VTAB_RANGE.NO_DEFAULT_VALUE.REF
        /end COMPU_METHOD
        /begin COMPU_VTAB_RANGE CM.VTAB_RANGE.NO_DEFAULT_VALUE.REF
           ""
           11
           0 1 "Zero_to_one"
           2 3 "two_to_three"
           4 7 "four_to_seven"
           14 17 "fourteen_to_seventeen"
           18 99 "eigteen_to_ninetynine"
           100 100 "hundred"
           101 101 "hundredone"
           102 102 "hundredtwo"
           103 103 "hundredthree"
           104 104 "hundredfour"
           105 105 "hundredfive"
        /end COMPU_VTAB_RANGE
    /end MODULE
    """
    session = parser.parseFromString(DATA)
    module = session.query(model.Module).first()
    compu = functions.CompuMethod(session, module.compu_method[0])
    assert compu(0) == "Zero_to_one"
    assert compu(6) == "four_to_seven"
    assert compu(45) == "eigteen_to_ninetynine"
    assert compu(100) == "hundred"
    assert compu(105) == "hundredfive"
    assert compu(-1) is None
    assert compu(106) is None
    assert compu(10) is None
示例#22
0
def test_compu_method_tab_nointerp_default():
    parser = ParserWrapper("a2l", "module", A2LListener)
    DATA = """
    /begin MODULE testModule ""
        /begin COMPU_METHOD CM.TAB_NOINTP.DEFAULT_VALUE
          ""
          TAB_NOINTP "%8.4" "U/  min  "
          COMPU_TAB_REF CM.TAB_NOINTP.DEFAULT_VALUE.REF
        /end COMPU_METHOD
        /begin COMPU_TAB CM.TAB_NOINTP.DEFAULT_VALUE.REF
           ""
           TAB_NOINTP
           12
           -3 98
           -1 99
           0 100
           2 102
           4 104
           5 105
           6 106
           7 107
           8 108
           9 109
           10 110
           13 111
           DEFAULT_VALUE_NUMERIC 300.56 /* DEFAULT_VALUE_NUME RIC should be used here as the normal output is numeric */
        /end COMPU_TAB
    /end MODULE
    """
    db = parser.parseFromString(DATA)
    module = db.session.query(model.Module).first()
    compu = functions.CompuMethod(
        db.session, inspect.CompuMethod(db.session,
                                        module.compu_method[0].name))
    assert compu.int_to_physical(-3) == 98
    assert compu.int_to_physical(8) == 108
    assert compu.physical_to_int(108) == 8
    assert compu.int_to_physical(1) == 300.56