Guest User

exercism clock.py

a guest
Oct 20th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.23 KB | None | 0 0
  1. ........FF........................................
  2. ======================================================================
  3. FAIL: test_clocks_a_minute_apart (__main__.ClockTest)
  4. ----------------------------------------------------------------------
  5. Traceback (most recent call last):
  6.   File "clock_test.py", line 119, in test_clocks_a_minute_apart
  7.     self.assertNotEqual(Clock(15, 36), Clock(15, 37))
  8. AssertionError: <clock.Clock object at 0x7faf3d647be0> == <clock.Clock object at 0x7faf3d647ac8>
  9.  
  10. ======================================================================
  11. FAIL: test_clocks_an_hour_apart (__main__.ClockTest)
  12. ----------------------------------------------------------------------
  13. Traceback (most recent call last):
  14.   File "clock_test.py", line 122, in test_clocks_an_hour_apart
  15.     self.assertNotEqual(Clock(14, 37), Clock(15, 37))
  16. AssertionError: <clock.Clock object at 0x7faf3d647be0> == <clock.Clock object at 0x7faf3d647c18>
  17.  
  18. ----------------------------------------------------------------------
  19. Ran 50 tests in 0.003s
  20.  
  21. FAILED (failures=2)
  22.  
  23.  
  24.  
  25. #
  26. # Skeleton file for the Python "Clock" exercise.
  27. #
  28.  
  29. class Clock(object):
  30.  
  31.     def __init__(self, hours, minutes):
  32.         self.hours = hours
  33.         self.minutes = minutes
  34.         self.fix()
  35.  
  36.  
  37.     def __str__(self):
  38.         return '{0:02d}:{1:02d}'.format(self.hours, self.minutes)
  39.  
  40.  
  41.     def __eq__(self, other):
  42.         return '{0:02d}:{1:02d}'.format(self.hours, self.minutes)
  43.  
  44.  
  45.     def add(self, increment):
  46.         self.increment = increment
  47.         self.minutes += self.increment
  48.         self.fix()
  49.  
  50.         return '{0:02d}:{1:02d}'.format(self.hours, self.minutes)
  51.  
  52.  
  53.     def fix(self):
  54.         if self.minutes > 59 or self.minutes < 0:
  55.             self.hours += self.minutes // 60
  56.             self.minutes = self.minutes % 60
  57.         elif self.minutes == 60:
  58.             self.hours += 1
  59.             self.minutes = 0
  60.         else:
  61.             self.minutes = self.minutes
  62.  
  63.         if self.hours > 24 or self.hours < -24:
  64.             self.hours = self.hours % 24
  65.         elif self.hours < 0:
  66.             self.hours += 24
  67.         elif self.hours == 24 or self.hours == (-24):
  68.             self.hours = 0
  69.         else:
  70.             self.hours = self.hours
Advertisement
Add Comment
Please, Sign In to add comment