Guest User

Untitled

a guest
Jan 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. # It might be better to invert the conditional
  2. # putting the early exit at the top of the
  3. # function
  4.  
  5. # BEFORE
  6. # Passes test for f(0), f(1)
  7. def f(term):
  8. # assert term >= 0
  9. if term > 2:
  10. # This part of the implementation
  11. # does not return a correct value,
  12. # BUT preserves the behavior that
  13. # passed the test.
  14. return term
  15.  
  16. if term > 1:
  17. # This is the block of code that we
  18. # expect to change when we make the
  19. # RED -> GREEN transition for f(2)
  20. return term
  21.  
  22. # This part of the implementation
  23. # returns the correct value
  24. return term
  25. end
  26.  
  27. # AFTER
  28. # Passes test for f(0), f(1), f(2)
  29. def f(term):
  30. # assert term >= 0
  31. if term > 2:
  32. # This part of the implementation
  33. # does not return a correct value,
  34. # BUT preserves the behavior that
  35. # passed the test.
  36. return term
  37.  
  38. if term > 1:
  39. # Simplest thing that could possibly work?
  40. return 1
  41.  
  42. # This part of the implementation
  43. # returns the correct value
  44. return term
  45. end
Add Comment
Please, Sign In to add comment