Esempio n. 1
0
 def test_cancel_contract_negative_balance(self):
     """ Test that $0 is charged as the cancellation fee if the contract is
     cancelled while the balance is negative (aka some credit exists).
     """
     pc = PrepaidContract(datetime.date(2000, 9, 29), 25)
     pc.new_month(month=10, year=2000, bill=Bill())
     self.assertAlmostEqual(pc.balance, -25)
     cancel = pc.cancel_contract()
     # since the balance is negative, it should be forfeited, so the cost for
     # the month should be $0
     self.assertAlmostEqual(cancel, 0)
Esempio n. 2
0
def create_customers(log: Dict[str, List[Dict]]) -> List[Customer]:
    """ Returns a list of Customer instances for each customer from the input
    dataset from the dictionary <log>.

    Precondition:
    - The <log> dictionary contains the input data in the correct format,
    matching the expected input format described in the handout.
    """
    customer_list = []
    for cust in log['customers']:
        customer = Customer(cust['id'])
        for line in cust['lines']:
            contract = None
            # TODO:
            # 1) Uncomment the piece of code below once you've implemented
            #    all types of contracts.
            # 2) Make sure to import the necessary contract classes in this file
            # 3) Remove this TODO list when you're done.

            if line['contract'] == 'prepaid':
                # start with $100 credit on the account
                contract = PrepaidContract(datetime.date(2017, 12, 25), 100)
            elif line['contract'] == 'mtm':
                contract = MTMContract(datetime.date(2017, 12, 25))
            elif line['contract'] == 'term':
                contract = TermContract(datetime.date(2017, 12, 25),
                                        datetime.date(2019, 6, 25))
            else:
                print("ERROR: unknown contract type")

            line = PhoneLine(line['number'], contract)
            customer.add_phone_line(line)
        customer_list.append(customer)
    return customer_list
def create_customers(log: Dict[str, List[Dict]]) -> List[Customer]:
    """ Returns a list of Customer instances for each customer from the input
    dataset from the dictionary <log>.

    Precondition:
    - The <log> dictionary contains the input data in the correct format,
    matching the expected input format described in the handout.
    """
    customer_list = []
    for cust in log['customers']:
        customer = Customer(cust['id'])
        for line in cust['lines']:
            contract = None
            if line['contract'] == 'prepaid':

                contract = PrepaidContract(datetime.date(2017, 12, 25), 100)
            elif line['contract'] == 'mtm':
                contract = MTMContract(datetime.date(2017, 12, 25))
            elif line['contract'] == 'term':
                contract = TermContract(datetime.date(2017, 12, 25),
                                        datetime.date(2019, 6, 25))
            else:
                print("ERROR: unknown contract type")

            line = PhoneLine(line['number'], contract)

            customer.add_phone_line(line)
        customer_list.append(customer)
    return customer_list
Esempio n. 4
0
def create_two_customer_with_all_lines() -> List[Customer]:
    """ Create a customer with one of each type of PhoneLine
    """
    contracts = [
        TermContract(start=datetime.date(year=2017, month=12, day=25),
                     end=datetime.date(year=2019, month=6, day=25)),
        MTMContract(start=datetime.date(year=2017, month=12, day=25)),
        PrepaidContract(start=datetime.date(year=2017, month=12, day=25),
                        balance=100)
    ]
    numbers = ['123-4567', '987-6543', '654-3210', '246-8101', '135-7911',
               '112-3581']
    customer1 = Customer(cid=6666)
    customer2 = Customer(cid=7777)

    for i in range(len(contracts)):
        customer1.add_phone_line(PhoneLine(numbers[i], contracts[i]))

    # create another customer with different phone number but same contracts
    for i in range(len(contracts)):
        customer2.add_phone_line(PhoneLine(numbers[i + 3], contracts[i]))

    customer1.new_month(12, 2017)
    customer2.new_month(12, 2017)
    return [customer1, customer2]
Esempio n. 5
0
 def test_cancel_contract_positive_balance(self):
     """ Test that the balance is charged as the cancellation fee if the
     contract is cancelled while the balance is positive.
     """
     pc = PrepaidContract(datetime.date(2000, 9, 29), 10)
     pc.new_month(month=10, year=2000, bill=Bill())
     # make a call that costs $15
     c1 = Call(src_nr="123-4567",
               dst_nr="987-6543",
               calltime=datetime.datetime(year=2000,
                                          month=10,
                                          day=31,
                                          hour=20,
                                          minute=30,
                                          second=0),
               duration=ceil(15 / PREPAID_MINS_COST * 60),
               src_loc=(-79.45188229255568, 43.62186408875219),
               dst_loc=(-79.36866519485261, 43.680793196449336))
     pc.bill_call(c1)
     # since the call was very long, the balance should be positive now
     self.assertAlmostEqual(pc.balance, 5)
     cancel = pc.cancel_contract()
     # since the balance is positive, it should be billed, so the cost for
     # the month should be the balance
     self.assertAlmostEqual(cancel, pc.balance)
def create_customers(log: Dict[str, List[Dict]]) -> List[Customer]:
    """ Returns a list of Customer instances for each customer from the input
    dataset from the dictionary <log>.

    Precondition:
    - The <log> dictionary contains the input data in the correct format,
    matching the expected input format described in the handout.
    """
    customer_list = []
    for cust in log['customers']:
        customer = Customer(cust['id'])
        for line in cust['lines']:
            contract = None
            if line['number'] == '100-1200': #Term: Test Free Min
                contract = TermContract(datetime.date(2018, 11, 1), datetime.date(2019, 1, 1))
            elif line['number'] == '200-1200': #Term: Test Cancel After
                contract = TermContract(datetime.date(2018, 11, 1), datetime.date(2018, 12, 1))
            elif line['number'] == '100-2101': #Term: Test Cancel On
                contract = TermContract(datetime.date(2018, 11, 1),
                                        datetime.date(2019, 1, 25))
            elif line['number'] == '100-3111': #Term: Test Cancel Before
                contract = TermContract(datetime.date(2018, 11, 1),
                                        datetime.date(2019, 2, 1))
            elif line['number'] == '001-2101': #Prepaid: positive balance
                contract = PrepaidContract(datetime.date(2018, 11, 1), 25)
            elif line['number'] == '001-3111':  # Prepaid: negative balance
                contract = PrepaidContract(datetime.date(2018, 11, 1), 25)
            elif line['number'] == '001-2011':  # Prepaid: mixed balance
                contract = PrepaidContract(datetime.date(2018, 11, 1), 25)
            elif line['contract'] == 'prepaid':
                # start with $100 credit on the account
                contract = PrepaidContract(datetime.date(2018, 11, 1), 100)
            elif line['contract'] == 'mtm':
                contract = MTMContract(datetime.date(2018, 11, 1))
            elif line['contract'] == 'term':
                contract = TermContract(datetime.date(2018, 11, 1),
                                        datetime.date(2019, 6, 25))
            else:
                print("ERROR: unknown contract type")

            line = PhoneLine(line['number'], contract)
            customer.add_phone_line(line)
        customer_list.append(customer)
    return customer_list
def create_customer() -> Customer:
    """ Create a customer with one of each type of PhoneLine
    """
    contracts = [
        TermContract(start=datetime.date(year=2017, month=12, day=1),
                     end=datetime.date(year=2018, month=12, day=30)),
        MTMContract(start=datetime.date(year=2017, month=12, day=1)),
        PrepaidContract(start=datetime.date(year=2017, month=12, day=1),
                        balance=100)
    ]
    numbers = ['867-5309', '273-8255', '649-2568']
    customer = Customer(cid=5555)

    for i in range(len(contracts)):
        customer.add_phone_line(PhoneLine(numbers[i], contracts[i]))

    customer.new_month(12, 2017)
    return customer
Esempio n. 8
0
 def test_new_month_no_top_off(self):
     """ Test that the new_month function works in general, aka test that it
     sets up the bill and rate correctly, and that it sets up and bills the
     balance correctly. Test that the balance is NOT topped off if there is
     >=$10 of credit.
     """
     pc = PrepaidContract(datetime.date(2000, 9, 29), 100)
     bill1 = Bill()
     pc.new_month(month=10, year=2000, bill=bill1)
     assert pc.bill is bill1
     # the balance should not have changed
     self.assertAlmostEqual(pc.balance, -100)
     # the bill cost should be the balance
     self.assertAlmostEqual(pc.bill.get_cost(), pc.balance)
     bill2 = Bill()
     pc.new_month(month=11, year=2000, bill=bill2)
     assert pc.bill is bill2
     # the balance still should not have changed
     self.assertAlmostEqual(pc.balance, -100)
     self.assertAlmostEqual(pc.bill.get_cost(), pc.balance)
Esempio n. 9
0
 def test_new_month_top_off(self):
     """ Test that the new_month function works in general, aka test that it
     sets up the bill and rate correctly, and that it sets up and bills the
     balance correctly. Test that the balance is topped off if there is
     <$10 of credit, and not unnecessarily topped off after that.
     """
     pc = PrepaidContract(datetime.date(2000, 9, 29), 0)
     bill1 = Bill()
     pc.new_month(month=10, year=2000, bill=bill1)
     assert pc.bill is bill1
     self.assertEqual(pc.bill.min_rate, PREPAID_MINS_COST)
     # the balance should have decreased by $25 because of the top off
     self.assertEqual(pc.balance, -25)
     # the customer should not be billed for the top off, their bill should
     # simply reflect the new balance
     self.assertAlmostEqual(pc.bill.get_cost(), pc.balance)
     bill2 = Bill()
     pc.new_month(month=11, year=2000, bill=bill2)
     assert pc.bill is bill2
     self.assertEqual(pc.bill.min_rate, PREPAID_MINS_COST)
     # the balance should not have changed
     self.assertEqual(pc.balance, -25)
     self.assertAlmostEqual(pc.bill.get_cost(), pc.balance)