def setUp(self):
     self.telephone_operator_one = TelephoneOperator.TelephoneOperator()
     self.telephone_operator_one.setPrefixPrice(722, 0.5)
     self.telephone_operator_one.setPrefixPrice(7223, 1.0)
     self.telephone_operator_one.setPrefixPrice(7221, 2.0)
     self.telephone_operator_two = TelephoneOperator.TelephoneOperator()
     self.telephone_operator_two.setPrefixPrice(922, 0.5)
     self.telephone_operator_two.setPrefixPrice(233, 1.0)
     self.telephone_operator_two.setPrefixPrice(7221, 2.0)
 def test_setPrefixPrice(self):
     prefix = '1234'
     price = 2.0
     telephone_operator = TelephoneOperator.TelephoneOperator()
     input_dic = {prefix: price}
     telephone_operator.setPrefixPrice(prefix, price)
     self.assertDictEqual(telephone_operator.prefix_price_dic, input_dic)
 def test_getPriceForPrefix(self):
     prefix = 1234
     price = 1.2
     telephone_operator = TelephoneOperator.TelephoneOperator()
     input_dic = {prefix: price}
     telephone_operator.setPrefixPrice(prefix, price)
     output_prefix = '1234'
     self.assertEqual(telephone_operator.getPriceForPrefix(output_prefix),
                      price)
 def test_getPrefixPriceDic(self):
     prefix = 1234
     price = 1.2
     telephone_operator = TelephoneOperator.TelephoneOperator()
     input_dic = {prefix: price}
     telephone_operator.setPrefixPrice(prefix, price)
     output_dic = {'1234': 1.2}
     self.assertDictEqual(telephone_operator.getPrefixPriceDic(),
                          output_dic)
 def test_getPrefixesWithMaximumMatch_negative(self):
     telephone_number = '12234567'
     telephone_operator = TelephoneOperator.TelephoneOperator()
     telephone_operator.setPrefixPrice(722, 0.5)
     telephone_operator.setPrefixPrice(7223, 1.0)
     telephone_operator.setPrefixPrice(7221, 2.0)
     output_prefix = '-1'
     self.assertEqual(
         telephone_operator.getPrefixesWithMaximumMatch(telephone_number),
         output_prefix)
 def test_updateOperator(self):
     telephone_operator_collection = TelephoneOperatorCollection.TelephoneOperatorCollection(
     )
     telephone_operator_collection.setListOfOperators(
         [self.telephone_operator_one, self.telephone_operator_two])
     telephone_operator_three = TelephoneOperator.TelephoneOperator()
     telephone_operator_three.setPrefixPrice(6789, 0.5)
     telephone_operator_three.setPrefixPrice(1223, 1.0)
     telephone_operator_three.setPrefixPrice(9876, 2.0)
     telephone_operator_collection.updateOperator(telephone_operator_three)
     self.assertListEqual(telephone_operator_collection.list_of_operators, [
         self.telephone_operator_one, self.telephone_operator_two,
         telephone_operator_three
     ])
Beispiel #7
0
import traceback
import sys
import TelephoneOperator
import TelephoneOperatorCollection

try:
    # Taking input for the number of operators
    number_of_operating_units = int(
        input("Please enter the number of operators:"))
    operators = TelephoneOperatorCollection.TelephoneOperatorCollection()

    # Taking input for the prefix and price for each operator
    for index_of_unit in range(number_of_operating_units):
        prefix_price_list = TelephoneOperator.TelephoneOperator()
        print "\nPlease enter price list for operator {}:".format(
            index_of_unit + 1)
        number_of_prefixes = int(
            input(
                "Please enter the number of prefixes for operator {}:".format(
                    index_of_unit + 1)))
        for index_of_prefixes in range(number_of_prefixes):
            prefix_price_list.readPrefixPrice()
        operators.updateOperator(prefix_price_list)

    #Taking the telephone number input
    telephone_number = raw_input("Please enter the telephone number:")

    # Finding the list of operators that can support the above telephone number
    # If an operator does not support, the list has -1 at its index
    # Ex operator 0 does not support but operator 1 supports with prefix 722,
    # then the list_of_operators_eligible_with_prefix = ['-1','722']