unit testing with doctest in python 2.7 -
i started programming in python , gotten far functions. have experience in java according course took. understand, unit testing practice test see if functions working properly. here coding question given:
click here
i have far:
def compare(a,b): """ >>> compare(5,4) 1 >>> compare(7,7) 0 >>> compare(2,3) -1 >>> compare(42,1) 1 """ if > b: return 1 elif == b: return 0 elif < b: return -1 if __name__== '__main__': import doctest doctest.testmod() file "ch05.py", line 7, in __main__.compare failed example: compare(2,3) expected: -1 got: -1 what missing or how correct code? thought suppose using true/false booleans not actual integers.
like @sam said, comparisons represented integers 1 (greater than), 0 (equal to), -1 (less than). need modify code reflect attribute. also, may easier if follow unittest conventions covered here https://docs.python.org/2/library/unittest.html. logic pretty easy follow.
also - not sure if copy/paste error, indention off.
Comments
Post a Comment