Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. def chicken_rabbit(num_heads, num_legs):
  2. lowest_num_legs = num_heads * 2 # Lowest possible amount of legs
  3. difference = num_legs - lowest_num_legs
  4. num_one = difference / 2
  5. num_two = num_heads - num_one
  6. return num_two, num_one
  7.  
  8.  
  9. def unittest_function_pass():
  10. # write assertion statements here to test the function
  11. # enumerate as many test cases you can think of to test your function
  12. # See "Additional Requirements described in the assignment" for details.
  13. listB = []
  14. listB = chicken_rabbit(31, 94)
  15. assert(listB[0] > 0)
  16. return
  17.  
  18. def unittest_function_xfail():
  19. # write assertion statements here to test the function on any expected failing cases
  20. # See "Additional Requirements described in the assignment" for details.
  21. listA = []
  22. listA = chicken_rabbit(7, 56)
  23. assert(listA[0] > 0)
  24. return
  25.  
  26. if __name__ == "__main__":
  27. num_heads = int(input("Input number of heads:\n"))
  28. num_legs = int(input("Input number of legs:\n"))
  29. n_chicken, n_rabbit = chicken_rabbit(num_heads, num_legs)
  30. if (n_chicken < 0 or n_rabbit < 0):
  31. print("Invalid inputs received. Program aborted.")
  32. else:
  33. if n_chicken == 1:
  34. print("There is 1 chicken in the cage")
  35. elif n_chicken == 0:
  36. print("There isn't any chicken in the cage")
  37. else:
  38. print("There are %d chickens in the cage" % n_chicken)
  39.  
  40. if n_rabbit == 1:
  41. print("There is 1 rabbit in the cage")
  42. elif n_rabbit == 0:
  43. print("There isn't any rabbit in the cage")
  44. else:
  45. print("There are %d rabbits in the cage" % n_rabbit)
  46.  
  47.  
  48. # TODO: complete the unittest_function so your function undergo a rigorous unittest created by yourself
  49. unittest_function_pass()
  50.  
  51. # TODO: complete the unittest_function_xfail so your function undergo a rigorous unittest created by yourself
  52. # Please note that unittest_function_xfail is ALWAYS expected to trip an error! Because it is testing on expected failing cases
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement