Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

Question on HM8

DavideC. (1350 points)
4 6 9
in News by (1.4k 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?
263 views

2 Answers

Luigi Pizza (6120 points)
14 20 65
by (6.1k points)
edited by

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)
4 6 9
by (1.4k points)
Thanks for the clarification
Luigi Pizza (6120 points)
14 20 65
by (6.1k points)
If this has been useful, please consider choosing it as the best answer!
andrea.sterbini (207920 points)
750 1267 2373
by (208k 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)