def test_add_cd(self): cd = CD() cd_1 = CD_files("1" , "cd1") cd_2 = CD_files("2", "cd2") cd.add_cd(cd_1) cd.add_cd(cd_2) self.assertEqual(len(cd.cd_list), 2)
def test_add_cd(self): cd = CD() cd_1 = CD_files("1", "cd1") cd_2 = CD_files("2", "cd2") cd.add_cd(cd_1) cd.add_cd(cd_2) self.assertEqual(len(cd.cd_list), 2)
def apply_strategy(self, item: CdItem): found_cd = False for used_cd in self.used_cd_list: if used_cd.remaining_capacity >= item.get_size(): used_cd.add_data(item) found_cd = True break if found_cd is False: new_cd = CD(len(self.used_cd_list)) new_cd.add_data(item) self.used_cd_list.append(new_cd)
def test_get_checkout_record(self): cd_rent = CD_rental() cd_list1 = CDList() cd1 = CD("Beatles", "Unrented") customer1 = Customer("001", "Kringot") checkout1 = Checkout(customer1.customer_id, customer1.name, cd1.cd_id, "11/25/14", "11/27/14") cd_list1.add_cd(cd1) cd1.is_rented() cd_rent.add_checkout(checkout1) cd1.change_status() self.assertEqual(cd_rent.get_checkout_record(checkout1).customer_id, "001") self.assertEqual(cd_rent.get_checkout_record(checkout1).name, "Kringot") self.assertEqual(cd_rent.get_checkout_record(checkout1).cd_id, "Beatles") self.assertEqual(cd_rent.get_checkout_record(checkout1).date, "11/25/14") self.assertEqual(cd_rent.get_checkout_record(checkout1).due_date, "11/27/14")
def apply_strategy(self, item: CdItem): best_cd_index = 0 min_cd_space = sys.maxsize for index, used_cd in enumerate(self.used_cd_list): if used_cd.remaining_capacity >= item.get_size( ) and used_cd.remaining_capacity - item.get_size() < min_cd_space: best_cd_index = index min_cd_space = used_cd.remaining_capacity - item.get_size() if min_cd_space == sys.maxsize: new_cd = CD(len(self.used_cd_list)) new_cd.add_data(item) self.used_cd_list.append(new_cd) else: self.used_cd_list[best_cd_index].add_data(item)
def them(): global var_ten, var_ca_sy, var_gia, var_bai_hat, var_hinh ten = var_ten.get() ca_sy = var_ca_sy.get() so_bai_hat = int(var_bai_hat.get()) gia_thanh = float(var_gia.get()) hinh = var_hinh.get() cd = CD(ten, ca_sy, so_bai_hat, gia_thanh, hinh) result = insert_cd(cd) if result: messagebox.showinfo("Success", "Thêm mới thành công!") else: messagebox.showinfo("Fail", "Thêm mới không thành công!")
def test_cd_identity_created(self): cd = CD() self.assertEqual({}, cd.cd_list) self.assertEqual(len(cd.cd_list), 0)
def test_get_cd(self): cd = CD() cd_1 = CD_files("1", "cd") cd.add_cd(cd_1) self.assertEqual(cd.get_cd("1"), "cd")
def test_get_cd(self): cd =CD() cd_1 = CD_files("1", "cd") cd.add_cd(cd_1) self.assertEqual(cd.get_cd("1"), "cd")
def add_item(self, cd_item: CdItem, cd_index): if cd_index < 0 or cd_index >= len(self.used_cd_list): cd_index = len(self.used_cd_list) self.used_cd_list.append(CD(cd_index)) self.used_cd_list[cd_index].add_data(cd_item)
def test_buy_cd_in_stock(self): cd = CD(10) cd.buy(5) self.assertEqual(5, cd.get_stock_count())