samedi 19 octobre 2019

How can I test for a number of matrices and their respective expected outputs in python 3?

I'm trying to write a test function with which I want to see if a number of matrices will output expected values.

My test function is:

def test_f():
    test_cases = {
        M1 : expected1,
        M2 : expected2
        ...
    }

    for matrix, expected_result in test_cases.items():
        assert f(matrix) == expected_result    

I tried to write the test function like above to go through a dictionary of matrix : expected_output type, with matrices in regular list notation, and that did not work because apparently lists cannot be keys in dictionaries as keys must be immutable, and yet, lists are not.

How can I then make my function f goes through a list of pairs of matrix : expected_outcome and check for every other pair?

Aucun commentaire:

Enregistrer un commentaire