def test_overriding_of_identical_currencies_in_currencies_vector(self):
     currency = CurrencyBuilder() \
         .set_name("adam") \
         .set_name("wojtek") \
         .add_currency("euro", 123) \
         .add_currency("euro", 124) \
         .build()
     self.assertEqual(1, len(currency.get_all_related_currencies_as_list()))
 def test_setting_same_name_twice(self):
     currency = CurrencyBuilder() \
         .set_name("wojtek") \
         .set_name("wojtek") \
         .add_currency("euro", 123) \
         .add_currency("euro", 124) \
         .build()
     self.assertEqual("wojtek", currency.get_name())
 def test_name_changing(self):
     currency = CurrencyBuilder() \
         .set_name("adam") \
         .set_name("wojtek") \
         .add_currency("euro", 123) \
         .add_currency("euro", 124) \
         .build()
     self.assertEqual("wojtek", currency.get_name())
 def test_case_sensitivity_in_currencies_name(self):
     currency = CurrencyBuilder() \
         .set_name("adam") \
         .set_name("wojtek") \
         .add_currency("euro", 123) \
         .add_currency("Euro", 124) \
         .build()
     self.assertEqual(
         123,
         currency.get_related_currency_by_name("euro").get_value())
 def test_overriding_of_identical_currencies_in_currencies_vector2(self):
     currency = CurrencyBuilder() \
         .set_name("adam") \
         .set_name("wojtek") \
         .add_currency("euro", 123) \
         .add_currency("euro", 124) \
         .build()
     self.assertEqual(
         124,
         currency.get_related_currency_by_name("euro").get_value())
 def test_add_currency(self):
     exchange = CurrenciesExchange()
     builder = CurrencyBuilder()
     currency = builder.set_name('USD').add_currency('EUR',
                                                     1.45).add_currency(
                                                         'JEN', 2).build()
     exchange.add_currency(currency, 'USD')
     self.assertEqual(exchange.get_exchange_rate('USD', 'EUR'), 1.45)
     self.assertEqual(exchange.get_exchange_rate('USD', 'JEN'), 2)
     self.assertEqual(exchange.get_exchange_rate('JEN', 'EUR'), 2.9)
示例#7
0
def __let_user_define_new_currency():
    currencyName = input("Provide name for your currency")
    while True:
        mainExchangeCurrency = input(
            "Provide currency name for evaluating not provided exchange rates: "
        )
        if mainExchangeCurrency in currenciesExchange.get_currencies_names():
            break
        print("You've provided unknown currency name")

    currencyBuilder = CurrencyBuilder()
    currencyBuilder.set_name(currencyName)
    mainExchangeCurrencyExchangeRate = float(
        input("Please provide exchange rate for main exchange currency: "))
    currencyBuilder.add_currency(mainExchangeCurrency,
                                 mainExchangeCurrencyExchangeRate)

    while True:
        print("P x - if you want to add new exchange rate ")
        userDecision = input("Press ENTER otherwise ")
        if userDecision.__eq__("x"):
            currencyExchangeName = __infinitely_ask_for_valid_currency_name()
            currencyExchangeRate = float(
                input("Provide exchange rate for given currency: "))
            currencyBuilder.add_currency(currencyExchangeName,
                                         currencyExchangeRate)
        else:
            break

    newCurrency = currencyBuilder.build()
    currenciesExchange.add_currency(newCurrency, mainExchangeCurrency)
    print("New currency added")
    __print_currency_exchange(currencyName,
                              currenciesExchange.get_currencies_names())
 def test_get_name(self):
     name = CurrencyBuilder() \
         .set_name("wojtek") \
         .add_currency("www", 123) \
         .build() \
         .get_name()
     self.assertEqual("wojtek", name)
    def test_get_currencies(self):
        exchange = CurrenciesExchange()

        builder = CurrencyBuilder()
        builder.set_name('USD')
        builder.add_currency('EUR', 1.45)
        currency = builder.build()
        exchange.add_currency(currency, 'USD')

        self.assertEqual(exchange.get_currencies_names(), ['USD', 'EUR'])
示例#10
0
 def get_currencies_list(self):
     if not self._exchanges:
         raise Exception("Class not initialized")
     else:
         currencies_list = []
         for curr_code in list(self._currencies.values()):
             curr_list = list(self._currencies.values())
             curr_list.remove(curr_code)
             builder = CurrencyBuilder()
             builder.set_name(curr_code)
             for to_calculate in curr_list:
                 builder.add_currency(
                     to_calculate,
                     self.get_exchange_ratio(curr_code, to_calculate))
             currencies_list.append(builder.build())
         return currencies_list
 def test_currencies_vector_of_empty_currency(self):
     currency = CurrencyBuilder().build()
     self.assertEqual([], currency.get_all_related_currencies_as_list())
 def test_name_of_empty_currency(self):
     currency = CurrencyBuilder().build()
     self.assertEqual('', currency.get_name())
 def test_number_of_added_currencies(self):
     currency = CurrencyBuilder() \
         .add_currency("euro", 123) \
         .add_currency("dolar", 321) \
         .build()
     self.assertEqual(2, len(currency.get_all_related_currencies_as_list()))
def step_impl(context):
    builder = CurrencyBuilder()
    builder.set_name('USD')
    builder.add_currency('EUR', 0.75)
    context.exchange = CurrenciesExchange()
    context.exchange.add_currency(builder.build(), 'USD')
def step_impl(context):
    builder = CurrencyBuilder()
    builder.set_name('BTC')
    builder.add_currency('EUR', 5)
    currency = builder.build()
    context.exchange.add_currency(currency, 'EUR')