def test_tags_and_angle_brackets(self): with self.assertRaisesRegex( Exception, "can't process tags and angle brackets simultaneously"): Balance(tags=True, symmetrical=['{-', '≥', '>']) with self.assertRaisesRegex( Exception, "can't process tags and angle brackets simultaneously"): Balance(tags=True, pairs=[['(', '>'], ['({', '})']])
def test_ignore_case(self): balance_case_sensitive = Balance(tags=True) balance_case_insensitive = Balance(tags=True, ignore_case=True) self.assertIsNotNone( balance_case_sensitive.is_unbalanced( self.string_closed.format('<i>', '</I>'))) self.assertIsNone( balance_case_insensitive.is_unbalanced( self.string_closed.format('<i>', '</I>'))) self.assertIsNone( balance_case_insensitive.is_unbalanced( self.string_closed.format('<i>', '</i>')))
def test_sequences_in_pairs_and_symmetrical(self): with self.assertRaisesRegex( Exception, ".* found both in symmetrical and in pairs"): Balance(symmetrical=['{', '≥', '>']) with self.assertRaisesRegex( Exception, ".* found both in symmetrical and in pairs"): Balance(pairs=[['(+', '>'], ['({', '})']], symmetrical=['({', '-a']) with self.assertRaisesRegex( Exception, ".* found both in symmetrical and in pairs"): Balance(pairs=[['(+', '>'], ['({', '})'], ['"', '-"']], straight=True)
def test_apply_discount_balance_with_more_than_ten(self): # Create balance with $11 worth of fruits => discounts $10 b = Balance() b.add_balance(6_00, Category.FRUITS, "a six dollar banana") b.add_balance(5_00, Category.VEGGIES, "five dollars of celery") self.assertTrue(TenOffPromo.can_use(b)) self.assertEqual(TenOffPromo.apply_discount(b), 10_00)
def test_Balance_defaultConstructor(self): testBalance = Balance() self.assertEqual(testBalance.id, '') self.assertEqual(testBalance.date, '') self.assertEqual(testBalance.amount, 0)
def test_apply_discount_balance_with_more_than_five(self): # Create balance with $7 worth of fruits + veggies => discounts $5 b = Balance() b.add_balance(2_00, Category.FRUITS, "a two dollar banana") b.add_balance(5_00, Category.VEGGIES, "five dollars of celery") self.assertTrue(FiveForFive.can_use(b)) self.assertEqual(FiveForFive.apply_discount(b), 5_00)
def state_from_genesis_declaration(genesis_data, env, block=None, allow_empties=False, executing_on_head=False, pytricia={}): if block: assert isinstance(block, Block) else: block = block_from_genesis_declaration(genesis_data, env) state = State(env=env) #convert list to dictionary alloc_data = {} for elem in genesis_data["alloc"]: alloc_data[elem.keys()[0]] = elem[elem.keys()[0]] #print alloc_data for addr, data in alloc_data.iteritems(): addr = normalize_address(addr) assert len(addr) == 20 if 'balance' in data: balance = Balance(data['balance']['own_ips']) state.set_balance(addr, balance) for ip in data['balance']['own_ips']: pytricia[ip] = normalize_address(addr) if executing_on_head: state.executing_on_head = True state.commit(allow_empties=allow_empties) rdb = RefcountDB(state.db) block.header.state_root = state.trie.root_hash state.changed = {} state.prev_headers = [block.header] return state
def delBalance(self): index = self.tableWidget.currentRow() if index == -1: return Balance(index).removeBalance() self.fillTableBalance() pass
def get_balance(self): dic_balance = defaultdict(lambda: None) data = self.fcoin_api.get_balance() for item in data['data']: dic_balance[item['currency']] = \ Balance(float(item['available']), float(item['frozen']),float(item['balance'])) return dic_balance
def test_can_be_used_without_fruits_or_veggies(self): # Create balance without fruits or veggies => cannot use b = Balance() b.add_balance(10_00, Category.DAIRY, "some high quality milk") b.add_balance(1_00, Category.SNACKS, "Cookies n' Cream Hershey's Bar") b.add_balance(20_00, Category.HEALTH, "Med Kit") b.add_balance(2_00, Category.DRINKS, "coke") self.assertFalse(FiveForFive.can_use(b))
def test_using_other_coupons(self): # Already used another coupon => can't apply this coupon type b = Balance() b.add_balance(25_00, Category.FRUITS, "yum") self.assertTrue(HalfOffHealthyPurchases.can_use(b)) b.subtract_balance(0, Category.COUPON, "the worst coupon ever") self.assertFalse(HalfOffHealthyPurchases.can_use(b))
def test_incomplete_tags(self): balance = Balance(tags=True, straight=True) for string, opening_length, opening_position, closing_length, closing_position in self.incomplete_tags: with self.subTest(msg=string): unbalanced = balance.is_unbalanced(string) self._unbalanced_assertions(unbalanced, opening_length, opening_position, closing_length, closing_position)
def test_balance(self): "Balance dataclass" b = Balance("test") b.money_in(23) b.money_out(12) b.money_in(5) b.money_out(7) self.assertEqual(b.balance, 9)
def test_simple_unbalanced(self): balance = Balance(tags=True) for string, opening_length, opening_position, closing_length, closing_position \ in self.simple_unbalanced_strings: with self.subTest(msg=string): unbalanced = balance.is_unbalanced(string) self._unbalanced_assertions(unbalanced, opening_length, opening_position, closing_length, closing_position)
def test_math(self): balance_with_math = Balance(math=True) self.assertIsNotNone( self.balance_without_flags.is_unbalanced( self.string_closed.format('(', ']'))) self.assertIsNone( balance_with_math.is_unbalanced(self.string_closed.format( '(', ']')))
def __init__( self, customer: Customer, store: Store, store_manager: StoresManager = StoresManager()) -> None: self.customer = customer self.store = store self.balance = Balance() self.store_manager = store_manager
def test_cjk(self): balance_with_cjk = Balance(cjk=True) self.assertIsNone( self.balance_without_flags.is_unbalanced( self.string_not_closed.format('「'))) self.assertIsNotNone( balance_with_cjk.is_unbalanced(self.string_not_closed.format('「'))) self.assertIsNone( balance_with_cjk.is_unbalanced(self.string_closed.format('「', '」')))
def create_new_account(request): """:return True on success, False otherwise""" if request.account in accounts: eprint("account name '{}' already exists".format(request.account)) return False if request.amount < Balance(10 * 100): eprint("initial balance {} must be at least 10.00".format( request.amount)) return False accounts[request.account] = Account(request.card_pin, request.amount) return True
def test_tags(self): balance_with_tags = Balance(tags=True) self.assertIsNone( self.balance_without_flags.is_unbalanced( self.string_not_closed.format('<i>'))) self.assertIsNotNone( balance_with_tags.is_unbalanced( self.string_not_closed.format('<i>'))) self.assertIsNone( balance_with_tags.is_unbalanced( self.string_closed.format('<i>', '</i>')))
def test_basic_discount(self): # Adding $20 worth of fruits b = Balance() b.add_balance(10_00, Category.FRUITS, "a very expensive apple") b.add_balance(3_00, Category.OTHER, "a frog") b.add_balance(6_00, Category.FRUITS, "organic cage-free grapes") b.add_balance(12_00, Category.VEGGIES, "beef") self.assertFalse(HalfOffHealthyPurchases.can_use(b)) b.add_balance(4_00, Category.FRUITS, "do fruit snacks count as fruit?") self.assertTrue(HalfOffHealthyPurchases.can_use(b))
def test_custom(self): balance_with_custom = Balance(custom=True) self.assertIsNotNone( self.balance_without_flags.is_unbalanced( self.string_not_closed.format('('))) self.assertIsNone( balance_with_custom.is_unbalanced( self.string_not_closed.format('('))) self.assertIsNone( self.balance_without_flags.is_unbalanced( self.string_closed.format('(', ')')))
def test_straight(self): balance_with_straight = Balance(straight=True) self.assertIsNone( self.balance_without_flags.is_unbalanced( self.string_not_closed.format('"'))) self.assertIsNotNone( balance_with_straight.is_unbalanced( self.string_not_closed.format('"'))) self.assertIsNone( balance_with_straight.is_unbalanced( self.string_closed.format('"', '"')))
def add_balance(self, program_id, current_balance): """ Convenient add_balance wrapper """ action_id = Action.query.filter( Action.action_type == 'New').one().action_id balance = Balance(user_id=self.user_id, program_id=program_id, current_balance=current_balance, action_id=action_id) db.session.add(balance) return balance
def test_pairs(self): balance_with_pairs = Balance(pairs=[['begin', 'end']]) self.assertIsNone( self.balance_without_flags.is_unbalanced( self.string_not_closed.format('begin'))) self.assertIsNotNone( balance_with_pairs.is_unbalanced( self.string_not_closed.format('begin'))) self.assertIsNone( balance_with_pairs.is_unbalanced( self.string_closed.format('begin', 'end')))
def test_five_for_five_number_to_reward(self): b = Balance() b.add_balance(1_00, Category.DAIRY, "milk") self.assertEqual( FiveForFive.number_to_reward(b), 0, "If the total price is less than $5.00, we reward 0 " "FiveForFive coupons.") b.add_balance(6_00, Category.DRINKS, "orange juice") self.assertEqual( FiveForFive.number_to_reward(b), 1, "If the total price is more than $5.00, we reward only 1 " "FiveForFive coupon.")
def test_symmetrical(self): balance_with_symmetrical = Balance(symmetrical=['--']) self.assertIsNone( self.balance_without_flags.is_unbalanced( self.string_not_closed.format('--'))) self.assertIsNotNone( balance_with_symmetrical.is_unbalanced( self.string_not_closed.format('--'))) self.assertIsNone( balance_with_symmetrical.is_unbalanced( self.string_closed.format('--', '--')))
def deposit(request): """:return True on success, False otherwise""" if not check_account_name_exists(request.account): return False account = accounts[request.account] if not check_pin(request, account): return False if request.amount <= Balance(0): eprint("amount {} must be larger than 0.00".format(request.amount)) return False account.balance += request.amount return True
def test_five_for_five_can_use(self): b = Balance() b.add_balance(1_20, Category.DAIRY) b.add_balance(4_34, Category.DRINKS) self.assertFalse(FiveForFive.can_use(b)) b.add_balance(0, Category.VEGGIES, "carrot") b.add_balance(0, Category.FRUITS, "grapes") self.assertFalse(FiveForFive.can_use(b)) b.add_balance(3_50, Category.FRUITS, "apple") b.add_balance(3_50, Category.FRUITS, "banana") self.assertTrue(FiveForFive.can_use(b))
def get_days(): offset = utils.get_int_arg('offset', 0) count = utils.get_int_arg('count') items = dbutil.get_items() balance = Balance(items) if offset or count: days = balance.days[offset:offset + count] else: days = balance.days return { 'days': days, }
def test_five_for_five_apply_discount(self): b = Balance() b.add_balance(2_30, Category.FRUITS, "watermelon") b.add_balance(6_00, Category.VEGGIES, "lettuce") self.assertEqual( FiveForFive.apply_discount(b), 5_00, "If the total price of fruits and veggies is greater than " "$5.00, we discount $5.00 from the price") self.assertEqual( FiveForFive.apply_discount(b), 3_30, "If the price so far of fruits and veggies is less than " "$5.00 but still greater than $0.00, we discount the" "remaining price of fruits and veggies. This is meant to " "test whether we can track the discounted fruits and " "veggies so far.")