Пример #1
0
def test_do_select_all(test_dao):
    """ do_select_all() should return a treelib Tree() on success when selecting Allocations. """
    DUT = dtmAllocation(test_dao)
    _tree = DUT.do_select_all(revision_id=1)

    assert isinstance(_tree, Tree)
    assert isinstance(_tree.get_node(2).data, RAMSTKAllocation)
Пример #2
0
def test_do_calculate_foo_apportionment(test_dao):
    """ do_calculate() should return False on success when using FOO apportionment. """
    DUT = dtmAllocation(test_dao)
    DUT.do_select_all(revision_id=1)

    # The [parent, child 1, child 2, child 3, child 4] hazard rates.
    _hazard_rates = [0.005862, 0.000392, 0.000168, 0.0000982, 0.000212]

    _parent = DUT.do_select(1)
    _parent.method_id = 4
    _parent.goal_measure_id = 2
    _parent.hazard_rate_goal = 2.5003126e-06
    _children = DUT.do_select_children(1)

    i = 1
    for _child in _children:
        _child.data.int_factor = 2 * i
        _child.data.soa_factor = 3 * i
        _child.data.op_time_factor = 3 * i + 1
        _child.data.env_factor = i + 1
        i += 1

    assert not DUT.do_calculate(1)
    assert _parent.weight_factor == 8952
    assert _parent.reliability_goal == pytest.approx(0.99975)
    assert _parent.mtbf_goal == pytest.approx(399949.9979165)
    assert _children[0].data.reliability_alloc == pytest.approx(0.9999987)
    assert _children[1].data.reliability_alloc == pytest.approx(0.9999859)
    assert _children[2].data.reliability_alloc == pytest.approx(0.9999397)
    assert _children[3].data.reliability_alloc == pytest.approx(0.9998257)
Пример #3
0
def test_do_calculate_arinc_apportionment(test_dao):
    """ do_calculate() should return False on success when using ARINC apportionment. """
    DUT = dtmAllocation(test_dao)
    DUT.do_select_all(revision_id=1)

    # The [parent, child 1, child 2, child 3, child 4] hazard rates.
    _hazard_rates = [0.005862, 0.000392, 0.000168, 0.0000982, 0.000212]

    _parent = DUT.do_select(1)
    _parent.method_id = 3
    _parent.reliability_goal = 0.99975
    _children = DUT.do_select_children(1)

    _children[0].data.weight_factor = 0.2
    _children[1].data.weight_factor = 0.4
    _children[2].data.weight_factor = 0.6
    _children[3].data.weight_factor = 0.7

    assert not DUT.do_calculate(1, hazard_rates=_hazard_rates)
    assert _parent.hazard_rate_goal == pytest.approx(2.5003126e-06)
    assert _parent.mtbf_goal == pytest.approx(399949.9979165)
    assert _children[0].data.reliability_alloc == pytest.approx(0.9999833)
    assert _children[1].data.reliability_alloc == pytest.approx(0.9999928)
    assert _children[2].data.reliability_alloc == pytest.approx(0.9999958)
    assert _children[3].data.reliability_alloc == pytest.approx(0.9999910)
Пример #4
0
def test_create_allocation_data_model(test_dao):
    """ __init__ should return instance of Allocation data model. """
    DUT = dtmAllocation(test_dao)

    assert isinstance(DUT, dtmAllocation)
    assert isinstance(DUT.tree, Tree)
    assert isinstance(DUT.dao, DAO)
Пример #5
0
def test_do_select_non_existent_id(test_dao):
    """ do_select() should return None when a non-existent Allocation ID is requested. """
    DUT = dtmAllocation(test_dao)
    DUT.do_select_all(revision_id=1)

    _allocation = DUT.do_select(100)

    assert _allocation is None
Пример #6
0
def test_do_select_children(test_dao):
    """ do_select_children() should return the immediate subtree of the passed node ID. """
    DUT = dtmAllocation(test_dao)
    DUT.do_select_all(revision_id=1)

    _nodes = DUT.do_select_children(1)

    assert isinstance(_nodes, list)
    assert isinstance(_nodes[0].data, RAMSTKAllocation)
    assert _nodes[0].identifier == 2
Пример #7
0
def test_do_update_non_existent_id(test_dao):
    """ do_update() should return a non-zero error code when passed an Allocation ID that doesn't exist. """
    DUT = dtmAllocation(test_dao)
    DUT.do_select_all(revision_id=1)

    _error_code, _msg = DUT.do_update(100)

    assert _error_code == 2207
    assert _msg == ("RAMSTK ERROR: Attempted to save non-existent Allocation "
                    "ID 100.")
Пример #8
0
def test_do_delete(test_dao):
    """ do_delete() should return a zero error code on success. """
    DUT = dtmAllocation(test_dao)
    DUT.do_select_all(revision_id=1)

    _error_code, _msg = DUT.do_delete(DUT.last_id)

    assert _error_code == 0
    assert _msg == ("RAMSTK SUCCESS: Deleting an item from the RAMSTK Program "
                    "database.")
    assert DUT.last_id == 8
Пример #9
0
def test_do_select(test_dao):
    """ do_select() should return an instance of the RAMSTKAllocation data model on success. """
    DUT = dtmAllocation(test_dao)
    DUT.do_select_all(revision_id=1)

    _allocation = DUT.do_select(2)

    assert isinstance(_allocation, RAMSTKAllocation)
    assert _allocation.hardware_id == 2
    assert _allocation.availability_alloc == 0.0
    assert _allocation.parent_id == 1
Пример #10
0
def test_do_update_all(test_dao):
    """ do_update_all() should return a zero error code on success. """
    DUT = dtmAllocation(test_dao)
    DUT.do_select_all(revision_id=1)

    _error_code, _msg = DUT.do_update_all()

    assert _error_code == 0
    assert _msg == (
        "RAMSTK SUCCESS: Updating all line items in the reliability "
        "allocation analysis worksheet.")
Пример #11
0
def test_do_update(test_dao):
    """ do_update() should return a zero error code on success. """
    DUT = dtmAllocation(test_dao)
    DUT.do_select_all(revision_id=1)

    _allocation = DUT.do_select(1)
    _allocation.n_sub_systems = 2

    _error_code, _msg = DUT.do_update(1)

    assert _error_code == 0
    assert _msg == ("RAMSTK SUCCESS: Updating the RAMSTK Program database.")
Пример #12
0
def test_do_insert(test_dao):
    """ do_insert() should return a zero error code on success. """
    DUT = dtmAllocation(test_dao)
    DUT.do_select_all(revision_id=1)

    _error_code, _msg = DUT.do_insert(revision_id=1,
                                      hardware_id=9,
                                      parent_id=1)

    assert _error_code == 0
    assert _msg == ("RAMSTK SUCCESS: Adding one or more items to the RAMSTK "
                    "Program database.")
    assert DUT.last_id == 9
Пример #13
0
def test_do_calculate_equal_apportionment(test_dao):
    """ do_calculate() should return False on success when using equal apportionment. """
    DUT = dtmAllocation(test_dao)
    DUT.do_select_all(revision_id=1)

    _parent = DUT.do_select(1)
    _parent.reliability_goal = 0.99975
    _children = DUT.do_select_children(1)

    assert not DUT.do_calculate(1)
    assert _parent.hazard_rate_goal == pytest.approx(2.5003126e-06)
    assert _parent.mtbf_goal == pytest.approx(399949.9979165)
    for _child in _children:
        assert _child.data.reliability_alloc == pytest.approx(0.9999375)
        assert _child.data.mtbf_alloc == pytest.approx(1599799.9916666)
Пример #14
0
def test_do_calculate_agree_apportionment(test_dao):
    """ do_calculate() should return False on success when using AGREE apportionment. """
    DUT = dtmAllocation(test_dao)
    DUT.do_select_all(revision_id=1)

    _parent = DUT.do_select(1)
    _parent.method_id = 2
    _parent.reliability_goal = 0.99975
    _children = DUT.do_select_children(1)

    _children[0].data.weight_factor = 0.2
    _children[1].data.weight_factor = 0.4
    _children[2].data.weight_factor = 0.6
    _children[3].data.weight_factor = 0.7

    assert not DUT.do_calculate(1)
    assert _parent.hazard_rate_goal == pytest.approx(2.5003126e-06)
    assert _parent.mtbf_goal == pytest.approx(399949.9979165)
    assert _children[0].data.reliability_alloc == pytest.approx(0.9996875)
    assert _children[1].data.reliability_alloc == pytest.approx(0.9998437)
    assert _children[2].data.reliability_alloc == pytest.approx(0.9998958)
    assert _children[3].data.reliability_alloc == pytest.approx(0.9999107)
Пример #15
0
def test_do_calculate_all(test_dao):
    """ do_calculate_all() should return False on success. """
    DUT = dtmAllocation(test_dao)
    DUT.do_select_all(revision_id=1)

    assert not DUT.do_calculate_all()