Esempio n. 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'
Esempio n. 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'
Esempio n. 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'
Esempio n. 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'
Esempio n. 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'
Esempio n. 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'
Esempio n. 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
Esempio n. 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))
Esempio n. 9
0
def test_empty_model():
    model = {}

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