Ejemplo n.º 1
0
 def test_allow_nan_with_bounds(self):
     validate_float(
         float('nan'),
         min_value=-1.0,
         max_value=1.0,
         allow_nan=True,
     )
     validate_float(
         float('nan'),
         min_value=float('-inf'),
         max_value=float('inf'),
         allow_nan=True,
     )
Ejemplo n.º 2
0
 def with_betas(self, lower_limit: float, upper_limit: float) -> 'GraphBuilder':
     # Switch limits if lower is larger than upper
     if lower_limit > upper_limit:
         tmp = upper_limit
         upper_limit = lower_limit
         lower_limit = tmp
     validate_float(lower_limit, min_value=0.0)
     if lower_limit <= 0.0:
         raise ValueError(f'Range of beta has to be within (0, Inf), ' +
                          f'but is {lower_limit} and {upper_limit}')
     validate_float(upper_limit, min_value=lower_limit)
     self.beta_lower_limit = lower_limit
     self.beta_upper_limit = upper_limit
     return self
Ejemplo n.º 3
0
def withdraw(user, account, trans_type, over_min=False):
    if not over_min:
        clear_output()
    amount = validation.validate_float("withdrawal amount")
    if enforce_min(user, account, amount):
        account.withdraw(amount, trans_type)
        balance(user, account, True)
    else:
        withdraw(user, account, trans_type, True)
    main_menu_prompt(user, account)
Ejemplo n.º 4
0
 def test_repr_1(self):  # type: () -> None
     validator = validate_float(
         min_value=1.0,
         max_value=1.0,
         required=False,
     )
     self.assertEqual(
         repr(validator),
         'validate_float(min_value=1.0, max_value=1.0, required=False)',
     )
Ejemplo n.º 5
0
    def test_check_requested_bounds(self):
        with self.assertRaises(TypeError):
            validate_float(min_value=1)

        with self.assertRaises(TypeError):
            validate_float(max_value=1)

        with self.assertRaises(ValueError):
            validate_float(min_value=10.0, max_value=9.0)
Ejemplo n.º 6
0
def transfer(user, account):
    target_user, target_account = get_accounts()
    if account.account_id == target_account.account_id:
        input(
            "\nYou cannot transfer to the same account, press enter to select a different account"
        )
        transfer(user, account)
    amount = validation.validate_float("withdrawal amount")
    if enforce_min(user, account, amount):
        account.withdraw(amount, "Transfer")
        pass
    else:
        withdraw(user, account, "Transfer")
    target_account.deposit(amount, "Transfer")
    balance(user, account, True)
    main_menu_prompt(user, account)
Ejemplo n.º 7
0
    def test_allow_negative_inf_with_bounds(self):
        validate_float(float('-inf'), max_value=0.0, allow_infinite=True)

        with self.assertRaises(ValueError):
            validate_float(float('-inf'), min_value=0.0, allow_infinite=True)

        # Passing infinite as the lower bound suggests that the user doesn't
        # want a lower bound.  Negative infinite should be acceptable.
        validate_float(
            float('-inf'),
            min_value=float('-inf'),
            allow_infinite=True,
        )
        # Allowing only negative infinite when the maximum value is negative
        # infinite is the only behaviour that could reasonably be considered
        # useful.
        validate_float(
            float('-inf'),
            max_value=float('-inf'),
            allow_infinite=True,
        )
Ejemplo n.º 8
0
    def test_disallow_infinite(self):  # type: () -> None
        with self.assertRaises(ValueError):
            validate_float(float('inf'))

        with self.assertRaises(ValueError):
            validate_float(float('-inf'))
Ejemplo n.º 9
0
 def test_valid(self):  # type: () -> None
     validate_float(1.0)
     validate_float(math.pi)
Ejemplo n.º 10
0
 def test_allow_nan(self):  # type: () -> None
     validate_float(float('nan'), allow_nan=True)
Ejemplo n.º 11
0
 def with_discrete_signal_to_noise_ratio(self,
                                         discrete_signal_to_noise_ratio: float) -> 'GraphBuilder':
     validate_float(discrete_signal_to_noise_ratio, min_value=0.0, max_value=1.0)
     self.discrete_signal_to_noise_ratio = discrete_signal_to_noise_ratio
     return self
Ejemplo n.º 12
0
def create_account(user):
    initial_deposit = validation.validate_float("initial deposit amount")
    return Account(user.customer_id, initial_deposit)
Ejemplo n.º 13
0
 def test_not_required(self):  # type: () -> None
     validate_float(None, required=False)
Ejemplo n.º 14
0
 def test_disallow_nan(self):  # type: () -> None
     with self.assertRaises(ValueError):
         validate_float(float('nan'))
Ejemplo n.º 15
0
 def test_closure(self):  # type: () -> None
     validator = validate_float(min_value=0.0)
     with self.assertRaises(ValueError):
         validator(-1.0)
Ejemplo n.º 16
0
 def test_int(self):
     with self.assertRaises(TypeError):
         validate_float(1)
Ejemplo n.º 17
0
 def test_required(self):
     with self.assertRaises(TypeError):
         validate_float(None)
Ejemplo n.º 18
0
    def test_max(self):  # type: () -> None
        validate_float(5.0, max_value=5.5)

        with self.assertRaises(ValueError):
            validate_float(5.0, max_value=4.5)
Ejemplo n.º 19
0
 def test_repr_2(self):  # type: () -> None
     validator = validate_float(allow_infinite=True, allow_nan=True)
     self.assertEqual(
         repr(validator),
         'validate_float(allow_infinite=True, allow_nan=True)',
     )
Ejemplo n.º 20
0
 def with_edge_density(self, edge_density: float) -> 'GraphBuilder':
     validate_float(edge_density, min_value=0.0, max_value=1.0)
     self.edge_density = edge_density
     return self
Ejemplo n.º 21
0
 def test_allow_inf(self):  # type: () -> None
     validate_float(float('inf'), allow_infinite=True)
     validate_float(float('-inf'), allow_infinite=True)
Ejemplo n.º 22
0
 def with_continuous_noise_std(self, continuous_noise_std: float) -> 'GraphBuilder':
     validate_float(continuous_noise_std, min_value=0.0)
     self.continuous_noise_std = continuous_noise_std
     return self
Ejemplo n.º 23
0
def deposit(user, account, trans_type):
    clear_output()
    amount = validation.validate_float("deposit amount")
    account.deposit(amount, trans_type)
    balance(user, account, True)
    main_menu_prompt(user, account)