Question on HM8

DavideC. (1350 points)
3 6 9
asked Dec 9, 2021 in News by DavideC. (1,350 points)
Hi, I had a question about the instructions for homework 8, at the end the text it says that the main function should return a list of valid images where each image is a tuple of tuples, but looking at the expected results from the json the result is a list of lists where each image is a list and not a tuple. I got a bit confused by this. Should we return it as the final list as tuples or lists?
146 views

2 Answers

Luigi Pizza (6120 points)
11 20 65
answered Dec 9, 2021 by Luigi Pizza (6,120 points)
edited Dec 9, 2021 by Luigi Pizza

In the test_01.py You can find the following code at line 78:

result   = program.ex(**parameters)     # what is returned by your function

-

self.assertEqual(type(result),  list,     
                         'il risultato prodotto deve essere una lista / '
                         f' the expected result should be a list (got {type(result)} instead)')


Ergo, the result should be a list

------------------------------------------------------------------------------------------------------------------------------

But the images should be a tuple: (line 82)

if result:
            self.assertEqual(type(result[0]),  tuple,     
                             'le immagini devono essere tuple / '
                             f'the image should be a tuple (got {type(result[0])} instead)')

------------------------------------------------------------------------------------------------------------------------------

So the result should be a list of tuples

DavideC. (1350 points)
3 6 9
commented Dec 9, 2021 by DavideC. (1,350 points)
Thanks for the clarification
Luigi Pizza (6120 points)
11 20 65
commented Dec 9, 2021 by Luigi Pizza (6,120 points)
If this has been useful, please consider choosing it as the best answer!
andrea.sterbini (172780 points)
513 935 1789
answered Dec 9, 2021 by andrea.sterbini (172,780 points)

You cannot represent tuples in JSON files, thus the json structures are lists of lists of lists, but they are converted to list of tuples of tuples before comparison (in testlib)

expected_s = tuple(tuple(tuple(c for c in row) for row in mat) for mat in expected)