Creating a unit test function factorize. The factorize (x) function is given with the following contract:

def factorize(x): """ Factorize positive integer and return its factors. :type x: int,>=0 :rtype: tuple[N],N>0 """ pass 

Write a test suite:

 test_wrong_types_raise_exception test_negative test_zero_and_one_cases test_simple_numbers test_two_simple_multipliers test_many_multipliers 

Check them accordingly:

That the types float and str (values ​​are 'string', 1.5) raise a TypeError exception. That for negative numbers -1, -10 and -100, a ValueError exception is thrown. That for the number 0 returns a tuple (0,), and for number 1 a tuple (1,) That for primes 3, 13, 29 returns a tuple containing one given number. That for numbers 6, 26, 121, the tuples are (2, 3), (2, 13) and (11, 11), respectively. For the numbers 1001 and 9699690, the tuples (7, 11, 13) and (2, 3, 5, 7, 11, 13, 17, 19) are returned respectively. In this case, several different checks within the same test must be processed as subcases with x: subTest (x = ...).

IMPORTANT! The variable name in the test case should be exactly "x". All input data must be as specified in the condition. In the task it is necessary to implement ONLY the TestFactorize class, other than that, nothing needs to be implemented. You also don't need to import unittest and call unittest.main () in the solution.

Posted by:

 import unittest def factorize(x): """ Factorize integer positive and return its factors. :type x: int,>=0 :rtype: tuple[N],N>0 """ pass class MyTest(unittest.TestCase): def test_wrong_types_raise_exception(self): for x in ('string', 1.5): with self.subTest(x=x): self.assertRaises(TypeError, factorize, x) def test_negative(self): for x in (-1, -10, -100): with self.subTest(x=x): self.assertRaises(ValueError, factorize, x) def test_zero_and_one_cases(self): for x in (0, 1): with self.subTest(x=x): self.assertEqual(factorize(x), (x,)) def test_simple_numbers(self): for x in (3, 13, 29): with self.subTest(x=x): self.assertEqual(factorize(x), (x,)) def test_two_simple_multipliers(self): for x, answer in ((6, (2,3)), (26, (2,13)), (121, (11,11))): with self.subTest(x=x): self.assertEqual(factorize(x), answer) def test_many_multipliers(self): for x, answer in ((1001, (7, 11, 13)), (9699690, (2, 3, 5, 7, 11, 13, 17, 19))): with self.subTest(x=x): self.assertEqual(factorize(x), answer) if __name__ != "__main__": unittest.main() 

Gives an error! RuntimeErrorElement (RuntimeError, Error in grading script. See raw output log for details.) Help to fix the error. Thank you in advance!

Closed due to the fact that off-topic participants Xander , 0xdb , andreymal , Eugene Krivenja , MarianD Jan 15 at 23:27 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - 0xdb, andreymal, Eugene Krivenja, MarianD
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    The text "See raw output log for details" as ba hints ... - Xander
  • I'm just learning .. - Valerii

1 answer 1

It's bad that you didn't write how you run this code and what version of python you have.

I tried all the options that occurred to me, but I could not get such an error like yours.

But, at a minimum, if you run this code directly, and do not import somewhere else, then in this line

 if __name__ != "__main__": 

Need to replace != ==