Answer the question
In order to leave comments, you need to log in
Python Unittest How to check if a number is Integer and Not negative?
Let's say I have a function
def isPrime(n):
'''Check if integer n is a prime'''
n = abs(int(n))
if n < 2:
return False
if n == 2:
return True
if not n & 1:
return False
for x in range(3, n):
if n % x == 0:
return False
return True
import unittest
class PrimeUnityTest(unittest.TestCase):
def test_Int(self):
self.assertTrue(isPrime(5.8), 'N is not Integer!')
def test_neg(self)
self.assertTrue(isPrime(-2), 'N is Negative Number!')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question