parking_test.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import parking
  2. print(parking.today().__class__)
  3. print(parking.now().__class__)
  4. print("Today is", parking.today())
  5. print("Now is", parking.now())
  6. print("Testing basic Day creation")
  7. assert parking.Day('Monday') == parking.Day('Monday'), "Monday is not equal to Monday"
  8. assert parking.Day('Monday') != parking.Day('Tuesday'), "Monday is not equal to Tuesday"
  9. assert parking.Day('Tuesday'), "Unable to create Day"
  10. print("Testing today() function")
  11. assert parking.today, "Unable to create Today"
  12. parking._today = 'wed'
  13. print("Testing today() function for comparisons")
  14. assert parking.day_compare('IS', parking.today(), "wed"), "Today is wednesday"
  15. assert not parking.day_compare('IS', parking.today(), "sat"), "Today is not saturday"
  16. assert not parking.day_compare('IS', parking.Day('Tuesday'), "sat"), "Tuesday is saturday"
  17. assert parking.day_compare('IS', parking.Day('Saturday'), "sat"), "Saturday is not saturday"
  18. print("Testing comparisons for day")
  19. assert parking.day_compare('IS', parking.today(), "wed"), "Wednesday == Wednesday"
  20. assert not parking.day_compare('IS', parking.today(), "sun"), "Wednesday == Sunday"
  21. assert not parking.day_compare('IS', parking.today(), "mon"), "Wednesday == Monday"
  22. assert parking.today() == parking.Day("Wed"), "Wednesday == Wednesday"
  23. assert not parking.today() == parking.Day("Sun"), "Wednesday == Sunday"
  24. assert not parking.today() == parking.Day("Mon"), "Wednesday == Monday"
  25. assert not parking.day_compare('BEFORE', parking.today(), "wed"), "Wednesday < Wednesday"
  26. assert not parking.day_compare('BEFORE', parking.today(), "mon"), "Wednesday < Monday"
  27. assert parking.day_compare('BEFORE', parking.today(), "saturday"), "Wednesday < Saturday"
  28. assert not parking.today() < parking.Day("Wed"), "Wednesday < Wednesday"
  29. assert not parking.today() < parking.Day("Monday"), "Wednesday < Monday"
  30. assert parking.today() < parking.Day("Sat"), "Wednesday < Saturday"
  31. assert parking.day_compare('BEFORE_EQUAL', parking.today(), "wed"), "Wednesday <= Wednesday"
  32. assert not parking.day_compare('BEFORE_EQUAL', parking.today(), "mon"), "Wednesday <= Monday"
  33. assert parking.day_compare('BEFORE_EQUAL', parking.today(), "saturday"), "Wednesday <= Saturday"
  34. assert parking.today() <= parking.Day("Wed"), "Wednesday <= Wednesday"
  35. assert not parking.today() <= parking.Day("Monday"), "Wednesday <= Monday"
  36. assert parking.today() <= parking.Day("Sat"), "Wednesday <= Saturday"
  37. assert not parking.day_compare('AFTER', parking.today(), "wed"), "Wednesday > Wednesday"
  38. assert parking.day_compare('AFTER', parking.today(), "mon"), "Wednesday > Monday"
  39. assert not parking.day_compare('AFTER', parking.today(), "saturday"), "Wednesday > Saturday"
  40. assert not parking.today() > parking.Day("Wed"), "Wednesday > Wednesday"
  41. assert parking.today() > parking.Day("Monday"), "Wednesday > Monday"
  42. assert not parking.today() > parking.Day("Sat"), "Wednesday > Saturday"
  43. assert parking.day_compare('AFTER_EQUAL', parking.today(), "wed"), "Wednesday >= Wednesday"
  44. assert parking.day_compare('AFTER_EQUAL', parking.today(), "mon"), "Wednesday >= Monday"
  45. assert not parking.day_compare('AFTER_EQUAL', parking.today(), "saturday"), "Wednesday >= Saturday"
  46. assert parking.today() >= parking.Day("Wed"), "Wednesday >= Wednesday"
  47. assert parking.today() >= parking.Day("Monday"), "Wednesday >= Monday"
  48. assert not parking.today() >= parking.Day("Sat"), "Wednesday >= Saturday"
  49. assert not parking.day_compare('IS_NOT', parking.today(), "wed"), "Wednesday != Wednesday"
  50. assert parking.day_compare('IS_NOT', parking.today(), "mon"), "Wednesday != Monday"
  51. assert parking.day_compare('IS_NOT', parking.today(), "saturday"), "Wednesday != Saturday"
  52. assert not parking.today() != parking.Day("Wed"), "Wednesday != Wednesday"
  53. assert parking.today() != parking.Day("Monday"), "Wednesday != Monday"
  54. assert parking.today() != parking.Day("Sat"), "Wednesday != Saturday"
  55. print("Testing basic Time creation")
  56. assert parking.Time(9, 30, 'pm'), "Create a night time"
  57. assert parking.Time(9, 30, 'am'), "Create a morning time"
  58. assert parking.Time(0, 20, 'pm'), "Create an afternoon time"
  59. print("Testing today() function")
  60. assert parking.now(), "Unable to create Today"
  61. print("Testing comparisons for time")
  62. parking._hour = 2
  63. parking._minute = 30
  64. parking._meridian = 'pm'
  65. assert parking.time_compare('IS', parking.now(), 2, 30, 'pm'), "2:30pm == 2:30pm"
  66. assert not parking.time_compare('IS', parking.now(), 9, 00, 'am'), "2:30pm == 9:00am"
  67. assert not parking.time_compare('IS', parking.now(), 5, 00, 'pm'), "2:30pm == 5:00pm"
  68. assert parking.now() == parking.Time(2, 30, 'pm'), "2:30pm == 2:30pm"
  69. assert not parking.now() == parking.Time(9, 00, 'am'), "2:30pm == 9:00am"
  70. assert not parking.now() == parking.Time(5, 00, 'pm'), "2:30pm == 5:00pm"
  71. assert not parking.time_compare('BEFORE', parking.now(), 2, 30, 'pm'), "2:30pm < 2:30pm"
  72. assert not parking.time_compare('BEFORE', parking.now(), 9, 00, 'am'), "2:30pm < 9:00am"
  73. assert parking.time_compare('BEFORE', parking.now(), 5, 00, 'pm'), "2:30pm < 5:00pm"
  74. assert not parking.now() < parking.Time(2, 30, 'pm'), "2:30pm < 2:30pm"
  75. assert not parking.now() < parking.Time(9, 00, 'am'), "2:30pm < 9:00am"
  76. assert parking.now() < parking.Time(5, 00, 'pm'), "2:30pm < 5:00pm"
  77. assert parking.time_compare('BEFORE_EQUAL', parking.now(), 2, 30, 'pm'), "2:30pm <= 2:30pm"
  78. assert not parking.time_compare('BEFORE_EQUAL', parking.now(), 9, 00, 'am'), "2:30pm <= 9:00am"
  79. assert parking.time_compare('BEFORE_EQUAL', parking.now(), 5, 00, 'pm'), "2:30pm <= 5:00pm"
  80. assert parking.now() <= parking.Time(2, 30, 'pm'), "2:30pm <= 2:30pm"
  81. assert not parking.now() <= parking.Time(9, 00, 'am'), "2:30pm <= 9:00am"
  82. assert parking.now() <= parking.Time(5, 00, 'pm'), "2:30pm <= 5:00pm"
  83. assert not parking.time_compare('AFTER', parking.now(), 2, 30, 'pm'), "2:30pm > 2:30pm"
  84. assert parking.time_compare('AFTER', parking.now(), 9, 00, 'am'), "2:30pm > 9:300am"
  85. assert not parking.time_compare('AFTER', parking.now(), 5, 00, 'pm'), "2:30pm > 5:00pm"
  86. assert not parking.now() > parking.Time(2, 30, 'pm'), "2:30pm > 2:30pm"
  87. assert parking.now() > parking.Time(9, 00, 'am'), "2:30pm > 9:00am"
  88. assert not parking.now() > parking.Time(5, 00, 'pm'), "2:30pm > 5:00pm"
  89. assert parking.time_compare('AFTER_EQUAL', parking.now(), 2, 30, 'pm'), "2:30pm >= 2:30pm"
  90. assert parking.time_compare('AFTER_EQUAL', parking.now(), 9, 00, 'am'), "2:30pm >= 9:00am"
  91. assert not parking.time_compare('AFTER_EQUAL', parking.now(), 5, 00, 'pm'), "2:30pm >= 5:00pm"
  92. assert parking.now() >= parking.Time(2, 30, 'pm'), "2:30pm >= 2:30pm"
  93. assert parking.now() >= parking.Time(9, 00, 'am'), "2:30pm >= 9:00am"
  94. assert not parking.now() >= parking.Time(5, 00, 'pm'), "2:30pm >= 5:00pm"
  95. assert not parking.time_compare('IS_NOT', parking.now(), 2, 30, 'pm'), "2:30pm != 2:30pm"
  96. assert parking.time_compare('IS_NOT', parking.now(), 9, 00, 'am'), "2:30pm != 9:00am"
  97. assert parking.time_compare('IS_NOT', parking.now(), 5, 00, 'pm'), "2:30pm != 5:00pm"
  98. assert not parking.now() != parking.Time(2, 30, 'pm'), "2:30pm != 2:30pm"
  99. assert parking.now() != parking.Time(9, 00, 'am'), "2:30pm != 9:00am"
  100. assert parking.now() != parking.Time(5, 00, 'pm'), "2:30pm != 5:00pm"
  101. assert not parking.time_compare('BEFORE', parking.now(), 12, 00, 'pm'), "2:30pm < 12:00pm"
  102. assert parking.time_compare('AFTER', parking.now(), 12, 00, 'pm'), "2:30pm > 12:00pm"
  103. assert not parking.now() < parking.Time(12, 00, 'pm'), "2:30pm < Noon"
  104. assert parking.now() > parking.Time(12, 00, 'pm'), "2:30pm > Noon"
  105. print("Illegal Comparisons")
  106. assert parking.today() != 5, "Should't be able to compare Day and number"
  107. assert parking.now() != 5, "Should't be able to compare Time and number"
  108. assert parking.now() != parking.today(), "Should't be able to compare Time and Day"
  109. assert parking.today() != parking.now(), "Should't be able to compare Day and Time"