示例#1
0
def test_non_dict_model():
    model = []

    with pytest.raises(AHPTypeMismatchError) as err:
        parse(model)

    assert err.value.var == 'model'
    assert err.value.expected == 'dict'
    assert err.value.actual == 'list'
示例#2
0
def test_model_with_missing_method():
    model = {
        'criteria': ['A', 'B'],
        'subCriteria': {},
        'alternatives': ['D', 'E', 'F'],
        'preferenceMatrices': {
            'criteria': [[1, 2], [0.5, 1]],
            'alternatives:A': [[1, 1, 1], [1, 1, 1], [1, 1, 1]],
            'alternatives:B': [[1, 1, 1], [1, 1, 1], [1, 1, 1]]
        }
    }

    with pytest.raises(AHPFieldEmptyError) as err:
        parse(model)

    assert err.value.var == 'method'
示例#3
0
def test_model_with_unsupported_method():
    model = {
        'method': 'ahp',
        'criteria': ['A', 'B'],
        'subCriteria': {},
        'alternatives': ['D', 'E', 'F'],
        'preferenceMatrices': {
            'criteria': [[1, 2], [0.5, 1]],
            'alternatives:A': [[1, 1, 1], [1, 1, 1], [1, 1, 1]],
            'alternatives:B': [[1, 1, 1], [1, 1, 1], [1, 1, 1]]
        }
    }

    with pytest.raises(AHPMethodUnsupportedError) as err:
        parse(model)

    assert err.value.actual == 'ahp'
示例#4
0
def test_model_with_missing_alternative_pm():
    model = {
        'method': 'geometric',
        'criteria': ['A', 'B'],
        'subCriteria': {},
        'alternatives': ['C', 'D', 'E'],
        'preferenceMatrices': {
            'criteria': [[1, 2], [0.5, 1]],
            'alternatives:A': [[1, 1, 1], [1, 1, 1], [1, 1, 1]],
        }
    }

    with pytest.raises(AHPMissingPreferenceMatrixError) as err:
        parse(model)

    assert err.value.kind == 'alternatives'
    assert err.value.name == 'B'
示例#5
0
def test_model_with_non_string_criteria():
    model = {
        'method': 'geometric',
        'criteria': [1, 2],
        'subCriteria': {},
        'alternatives': ['D', 'E', 'F'],
        'preferenceMatrices': {
            'criteria': [[1, 2], [0.5, 1]],
            'alternatives:1': [[1, 1, 1], [1, 1, 1], [1, 1, 1]],
            'alternatives:2': [[1, 1, 1], [1, 1, 1], [1, 1, 1]]
        }
    }

    with pytest.raises(AHPTypeMismatchError) as err:
        parse(model)

    assert err.value.var == 'criteria'
    assert err.value.expected == 'str'
    assert err.value.actual == 'int'
示例#6
0
def test_model_with_non_string_method():
    model = {
        'method': ['eigenvalue'],
        'criteria': ['A', 'B'],
        'subCriteria': {},
        'alternatives': ['D', 'E', 'F'],
        'preferenceMatrices': {
            'criteria': [[1, 2], [0.5, 1]],
            'alternatives:A': [[1, 1, 1], [1, 1, 1], [1, 1, 1]],
            'alternatives:B': [[1, 1, 1], [1, 1, 1], [1, 1, 1]]
        }
    }

    with pytest.raises(AHPTypeMismatchError) as err:
        parse(model)

    assert err.value.var == 'method'
    assert err.value.expected == 'str'
    assert err.value.actual == 'list'
示例#7
0
def test_model_with_non_square_alternative_pm():
    model = {
        'method': 'geometric',
        'criteria': ['A', 'B'],
        'subCriteria': {},
        'alternatives': ['C', 'D', 'E'],
        'preferenceMatrices': {
            'criteria': [[1, 2], [0.5, 1]],
            'alternatives:A': [[1, 1], [1, 1], [1, 1]],
            'alternatives:B': [[1, 1, 1], [1, 1, 1], [1, 1, 1]]
        }
    }

    with pytest.raises(AHPNonSquarePreferenceMatrixError) as err:
        parse(model)

    assert err.value.kind == 'alternatives'
    assert err.value.name == 'A'
    assert err.value.side == 3
    assert err.value.actual_width == 3
    assert err.value.actual_height == 2
示例#8
0
def main():
    """Main function of the script.

    This function parses the command line arguments, validates and creates the AHP models
    and prints the summary of all the AHP models.
    """
    args = parse_args()

    models = {file: json.load(open(file)) for file in args.file}

    for name, model in models.items():
        print('[+] {}'.format(model.get('name', name)))
        try:
            ahp_model = parse(model)
            print('\tMethod: {}'.format(model['method']))

            print_priorities(model['alternatives'], ahp_model.get_priorities())

        except Exception as err:
            print('\t[-] ERROR:{} {}'.format(err.__class__.__name__, err))
示例#9
0
def test_empty_model():
    model = {}

    with pytest.raises(AHPModelError):
        parse(model)