Пример #1
0
def test_bnet2primes_a():
    fname_in = get_tests_path_in(fname="fileexchange_constants.bnet")
    fname_out = get_tests_path_out(fname="fileexchange_stdout1.primes")
    file_in = "A, 0\nB, 1"

    expected = {"A": [[{}], []], "B": [[], [{}]]}

    primes = bnet2primes(bnet=fname_in)
    assert primes_are_equal(primes, expected)

    primes = bnet2primes(bnet=file_in)
    assert primes_are_equal(primes, expected)

    primes = bnet2primes(bnet=fname_in, fname_primes=fname_out)
    assert primes_are_equal(primes, expected)
Пример #2
0
def test_bnet2primes_missing_inputs():
    fname_in = get_tests_path_in(fname="fileexchange_missing_inputs.bnet")
    fname_out = get_tests_path_out(fname="fileexchange_missing_inputs.primes")
    primes = bnet2primes(bnet=fname_in, fname_primes=fname_out)
    primes_expected = {
        "B": [[{
            "B": 0
        }], [{
            "B": 1
        }]],
        "C": [[{
            "C": 0
        }], [{
            "C": 1
        }]],
        "A": [[{
            "B": 0,
            "C": 1
        }], [{
            "C": 0
        }, {
            "B": 1
        }]]
    }

    assert primes_are_equal(primes, primes_expected), str(primes)
Пример #3
0
def test_bnet2primes_empty():
    fname_in = get_tests_path_in(fname="fileexchange_empty.bnet")
    fname_out = get_tests_path_out(fname="fileexchange_empty.primes")
    primes = bnet2primes(bnet=fname_in, fname_primes=fname_out)
    primes_expected = {}

    assert primes_are_equal(primes, primes_expected), str(primes)
Пример #4
0
def test_read_primes():
    fname = get_tests_path_in(fname="fileexchange_missing_inputs.primes")
    primes = read_primes(fname_json=fname)
    primes_expected = {
        "B": [[{
            "B": 0
        }], [{
            "B": 1
        }]],
        "C": [[{
            "C": 0
        }], [{
            "C": 1
        }]],
        "A": [[{
            "B": 0,
            "C": 1
        }], [{
            "C": 0
        }, {
            "B": 1
        }]]
    }

    assert primes_are_equal(primes, primes_expected), str(primes)
Пример #5
0
def test_bnet2primes_constants():
    fname_in = get_tests_path_in(fname="fileexchange_constants.bnet")
    fname_out = get_tests_path_out(fname="fileexchange_constants.primes")

    primes = bnet2primes(bnet=fname_in, fname_primes=fname_out)
    primes_expected = {"A": [[{}], []], "B": [[], [{}]]}

    assert primes_are_equal(primes, primes_expected), str(primes)
Пример #6
0
def test_bnet2primes_operatorbinding():
    fname_in = get_tests_path_in(fname="fileexchange_operatorbinding.bnet")
    fname_out = get_tests_path_out(fname="fileexchange_operatorbinding.primes")

    primes = bnet2primes(bnet=fname_in, fname_primes=fname_out)
    names = "abcde"
    results = []
    for x in names:
        for y in names:
            name = x
            results.append(
                primes_are_equal({name: primes[x]}, {name: primes[y]}))

    assert all(results)
Пример #7
0
def test_bnet2primes_results():
    fname_in = get_tests_path_in(fname="fileexchange_feedback.bnet")
    fname_out = get_tests_path_out(fname="fileexchange_feedback.primes")
    primes = bnet2primes(bnet=fname_in, fname_primes=fname_out)
    primes_expected = {
        "v1": [[{
            "v2": 0
        }], [{
            "v2": 1
        }]],
        "v2": [[{
            "v2": 0
        }, {
            "v1": 1
        }], [{
            "v1": 0,
            "v2": 1
        }]]
    }

    assert primes_are_equal(primes, primes_expected)
Пример #8
0
def test_read_write_primes():
    fname = get_tests_path_out(fname="fileexchange_read_write.primes")
    primes_write = {
        "B": [[{}], []],
        "C": [[{
            "C": 0
        }], [{
            "C": 1
        }]],
        "A": [[{
            "B": 0,
            "C": 1
        }], [{
            "C": 0
        }, {
            "B": 1
        }]]
    }
    write_primes(primes=primes_write, fname_json=fname)
    primes_read = read_primes(fname_json=fname)

    assert primes_are_equal(primes_read, primes_write)