Created
April 2, 2014 08:05
-
-
Save alvintamie/9929902 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import os | |
import time | |
class Clock: | |
WORK_DAYS = 22 | |
AVERAGE_SALARY = 4000.0 | |
WORK_HOURS = 8 | |
def __init__(self, minutes = 0): | |
self.minutes = minutes | |
self.cost = 0 | |
def running_cost(self, person): | |
return round(Clock.minute_rate(person) * self.minutes, 2) | |
def tick(self): | |
self.minutes+=1 | |
@classmethod | |
def hourly_rate(cls, person = 1): | |
return (cls.AVERAGE_SALARY/cls.WORK_DAYS/cls.WORK_HOURS) * person | |
@classmethod | |
def minute_rate(cls, person = 1): | |
return (cls.hourly_rate()/60) * person | |
@classmethod | |
def start(cls, person): | |
clock = Clock() | |
while True: | |
os.system('clear') | |
print "We've been here for %d minutes and it has cost us $%.2f" % (clock.minutes, clock.running_cost(person)) | |
clock.tick() | |
time.sleep(60) | |
class TestClock(unittest.TestCase): | |
def setUp(self): | |
self.minutes = 5 | |
self.clock = Clock(self.minutes) | |
def test_work_days_has_correct_value(self): | |
self.assertEqual(Clock.WORK_DAYS, 22, "assumes that there are 22 working days in a month") | |
def test_average_salary_has_correct_value(self): | |
self.assertEqual(Clock.AVERAGE_SALARY, 4000.0, "assumes that the average salary is 4000 a month") | |
def test_work_hours_has_correct_value(self): | |
self.assertEqual(Clock.WORK_HOURS, 8, "assumes that people work for 8 hours a day") | |
def test_hourly_rate_calculation(self): | |
self.assertEqual(Clock.hourly_rate(), self.hourly_rate(), "computes how much a person earns per hour") | |
def test_single_person_minute_rate(self): | |
self.assertEqual(Clock.minute_rate(1), self.minute_rate(),"computes how much this meeting costs given 1 person") | |
def test_two_persons_minute_rate(self): | |
self.assertEqual(Clock.minute_rate(2), self.minute_rate()*2,"computes how much this meeting costs given 2 persons") | |
def test_running_cost_calculation_for_single_person(self): | |
self.assertEqual(self.clock.running_cost(1), round(self.minute_rate() * 1 * self.minutes, 2), 'knows the running cost given the # of minutes given 1 persons') | |
def test_running_cost_calculation_for_two_persons(self): | |
self.assertEqual(self.clock.running_cost(2), round(self.minute_rate() * 2 * self.minutes, 2), 'knows the running cost given the # of minutes given 2 persons') | |
def hourly_rate(self): | |
return 4000.0/22/8 | |
def minute_rate(self): | |
return self.hourly_rate()/60 | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment