def test_random_value(repl, low, high, units):
    verbose = False
    if verbose: print("\ntestrepl:", pformat(repl))
    x = DG.random_value(repl)
    urepl = repl.copy()
    urepl.update(units)
    if verbose: print("urepl:", pformat(urepl), "units:", pformat(units))
    if verbose: print("test x:", pformat(x))
    assert isinrange(x['value'].magnitude, low, high)
    ux = DG.random_value(urepl)
    assert isinrange(ux['value'].magnitude, low, high)
    val = ux['value']
    strval = str(val)
    just_units = re.sub('^[^ ]+ ?', '', strval)
    if verbose: print(f"{strval =} {just_units =}  {units['formatted'] =}")
    assert just_units == units['formatted']
def test_permute_sets(A, B, result):
    vars = {"A": A, "B": B}
    resultset = DG.permute_sets({"setA": "A", "setB": "B", "vars": vars})
    assert len(resultset["value"]) == len(
        result), f"set lengths don't match: {resultset =} {result =}"
    for checkstr in result:
        assert checkstr in resultset[
            "value"], f"string {checkstr =} not in {resultset =}"
Beispiel #3
0
def validate_listOfDataGenerators(generatorList):
    """ validates a list of DataGenerators
    """
    msg=""
    for idx, dataGenerator in enumerate(generatorList,start=1):
        result = DG.validate_args(dataGenerator)
        #print("result",pformat(result))
        if len(result) != 0:
            msg += "\n  ".join([f"dataGenerator index({idx}):",*result])
        if len(msg)>0: msg += "\n"
    return msg
Beispiel #4
0
def validate_dictOfDataGenerators(dictOfGenerators):
    """ validates a dictionary of DataGenerators
    """
    msg=""
    for var,dataGenerator in dictOfGenerators.items():
        result = DG.validate_args(dataGenerator)
        #print("result",len(result),":",pformat(result),"<\n")
        if len(result) != 0:
            msg += "\n  ".join([f"dataGenerator key({var}):",*result])
        if len(msg)>0: msg += "\n"
    return msg
def test_args_validator(test_dict, answer):

    for name, DoD in test_dict.items():
        result = DG.validate_args(DoD)
        #print("Name:", name, " result:", result)
        assert answer == result
def test_copy_text(text, answer):
    x = DG.copy_text({"text": text})
    #print("test_copy_text x:",pformat(x))
    assert str(x["value"]) == str(answer)
def test_fill_template(template, vars, answer):
    x = DG.fill_template({"template": template, "vars": vars})
    #print("test_fill_template x:",pformat(x))
    assert str(x["value"]) == str(answer)
def test_parser(expression, vars, answer):
    x = DG.parse_expression({"expression": expression, "vars": vars})
    #print("test_parser x:",pformat(x))
    assert str(x["value"]) == str(answer)
def test_exactnumbers(number, answerstr):
    repl = {'type': 'exact', 'exact': number}
    x = DG.random_value(repl)
    assert str(x['value'].magnitude) == answerstr