当前位置: 首页>>代码示例>>Python>>正文


Python Bag.remove方法代码示例

本文整理汇总了Python中bag.Bag.remove方法的典型用法代码示例。如果您正苦于以下问题:Python Bag.remove方法的具体用法?Python Bag.remove怎么用?Python Bag.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bag.Bag的用法示例。


在下文中一共展示了Bag.remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_equal

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
 def test_equal(self):
     to_bag = [random.randrange(1, 11) for i in range(1000)]
     bag1 = Bag(to_bag)
     bag2 = Bag(to_bag)
     self.assertEqual(bag1, bag2, "Bags are not equal.")
     bag1.remove(to_bag[0])
     self.assertNotEqual(bag1, bag2, "Bags should not be equal.")
开发者ID:ztza,项目名称:Class-Projects,代码行数:9,代码来源:q82solution.py

示例2: test_equals

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
 def test_equals(self):
     alist = [random.randint(1,10) for i in range(1000)]
     b1 = Bag(alist)
     random.shuffle(alist)
     b2 = Bag(alist)
     self.assertEqual(b1,b2)
     b1.remove(alist[0])
     self.assertNotEquals(b1,b2)
开发者ID:solomc1,项目名称:python,代码行数:10,代码来源:q82solution.py

示例3: test_eq

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
 def test_eq(self):
     temp_list = [random.randint(1,10) for i in range(1,1001)]
     b1 = Bag(temp_list)
     random.shuffle(temp_list)
     b2 = Bag(temp_list)
     self.assertEqual(b1,b2)
     b2.remove(temp_list[0])
     self.assertNotEqual(b1,b2)
开发者ID:dblam,项目名称:Duy-s-Python-Projects,代码行数:10,代码来源:q83solution.py

示例4: test_equal

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
 def test_equal(self):
     print('Checking for equal')
     alist = [random.randint(1,10) for i in range(1000)]
     bag1 = Bag(alist)
     random.shuffle(alist)
     bag2 = Bag(alist)
     self.assertEqual(bag1, bag2, 'Two back must be equal initially')
     bag2.remove(alist[0])
     self.assertNotEqual(bag1, bag2, 'Two back must not be equal after removing the first element of bag2')
开发者ID:shwilliams,项目名称:ICS33,代码行数:11,代码来源:q82solution.py

示例5: testEqual

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
 def testEqual(self):
     test_list = [random.randint(1,10) for i in range(1000)]
     test_bag1 = Bag(test_list)
     random.shuffle(test_list)
     test_bag2 = Bag(test_list)
     
     self.assertTrue(test_bag1==test_bag2)
     test_bag2.remove(test_list[0])
     self.assertFalse(test_bag1==test_bag2)
开发者ID:cmarch314,项目名称:PythonProjects,代码行数:11,代码来源:q82solution.py

示例6: test_eq

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
 def test_eq(self):
     bag2 = []
     for i in range(0,1000):
         bag2.append((random.randint(1,10)))
     check_bag = Bag(bag2)
     random.shuffle(bag2)
     check_bag2 = Bag(bag2)
     self.assertEqual(check_bag,check_bag2)
     check_bag.remove(bag2[0])
     self.assertNotEqual(check_bag,check_bag2)
开发者ID:solomc1,项目名称:python,代码行数:12,代码来源:q82solution.py

示例7: test_remove

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
 def test_remove(self):
     alist = [random.randint(1,10) for i in range(1000)]
     b1 = Bag(alist)
     self.assertRaises(ValueError,b1.remove,11)
     b2 = Bag(alist)
     random.shuffle(alist)
     for v in alist:
         b2.add(v)
     for v in alist:
         b2.remove(v)
     self.assertEqual(b1,b2)
开发者ID:solomc1,项目名称:python,代码行数:13,代码来源:q82solution.py

示例8: test_remove

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
 def test_remove(self):
     temp_list = []
     for i in range(1,1001):
         temp_list.append(random.randint(1,10))
     b1 = Bag(temp_list)
     self.assertRaises(ValueError,self.bag.remove,33)
     b2 = Bag(temp_list)
     for i in temp_list:
         b2.add(i)
         b2.remove(i)
     self.assertEqual(b1,b2)
开发者ID:dblam,项目名称:Duy-s-Python-Projects,代码行数:13,代码来源:q83solution.py

示例9: test_remove

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
 def test_remove(self):
     to_bag = [random.randrange(1, 11) for i in range(1000)]
     bag1 = Bag(to_bag)
     self.assertRaises(ValueError, Bag.remove, bag1, 32)
     bag2 = Bag(to_bag)
     for i in to_bag:
         bag2.add(i)
     for i in to_bag:
         bag2.remove(i)
     self.assertEqual(bag1, bag2, "Bags are not equal.")
     
     
开发者ID:ztza,项目名称:Class-Projects,代码行数:12,代码来源:q82solution.py

示例10: test_remove

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
 def test_remove(self):
     print('Checking for remove')
     alist = [random.randint(1,10) for i in range(1000)]
     bag1 = Bag(alist)
     self.assertRaises(ValueError, Bag.remove,bag1,32)
     bag2 = Bag(alist)
     
     for el in alist:
         bag2.add(el)
     for el in alist:
         bag2.remove(el)
     
     self.assertEqual(bag1,bag2, 'Two bag must be same after removing elements from bag2')
开发者ID:shwilliams,项目名称:ICS33,代码行数:15,代码来源:q82solution.py

示例11: testRemove

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
 def testRemove(self):
     
     test_list = [random.randint(1,10) for i in range(1000)]
     test_bag1 = Bag(test_list)
     
     self.assertRaises(ValueError,test_bag1.remove, 21)
     
     test_bag2 = Bag(test_list)
     for i in test_list:
         test_bag2.add(i)
     for i in test_list:
         test_bag2.remove(i)
     
     self.assertEqual(test_bag1,test_bag2)
开发者ID:cmarch314,项目名称:PythonProjects,代码行数:16,代码来源:q82solution.py

示例12: test_remove

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
 def test_remove(self):
     bag2 = []
     for i in range(0,1000):
         bag2.append((random.randint(1,10)))
     check_bag = Bag(bag2)
     self.assertRaises(ValueError, check_bag.remove,21)
     check_bag2 = Bag(bag2)
     for i in bag2:
         check_bag2.add(i)
     for i in bag2:
         check_bag2.remove(i)
     self.assertEqual(check_bag,check_bag2)
     
     
     
         
                     
                      
     
开发者ID:solomc1,项目名称:python,代码行数:14,代码来源:q82solution.py

示例13: Test_Bag

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
class Test_Bag(unittest.TestCase):
    def setUp(self):
        self.original = ['d', 'a', 'b', 'd', 'c', 'b', 'd']
        self.bag = Bag(['d', 'a', 'b', 'd', 'c', 'b', 'd'])
        
    def test_len(self):
        self.assertEqual(len(self.bag), 7, msg = "Length of constructed bag is not 7.")
        
        my_list = self.original.copy()
        for i in range(6, -1, -1):
            s = random.choice(my_list)
            self.bag.remove(s)
            my_list.remove(s)
            self.assertEqual(len(self.bag), i, msg = "Length of constructed bag is not " + str(i) +".")
            
        self.assertEqual(len(self.bag), 0, msg = "Final length of constructed bag is not 0.")
        
    def test_unique(self):
        comp_set = set(self.original)
        self.assertIs(self.bag.unique(), 4, msg = "Bag is not unique.")
        my_list = self.original.copy()
        while len(comp_set) != 0:
            s = random.choice(my_list)
            self.bag.remove(s)
            my_list.remove(s)
            comp_set = set(my_list)
            self.assertIs(self.bag.unique(), len(comp_set), msg = "Bag is not unique.")
        
    def test_contains(self):
        comp_set = ['a', 'b', 'c', 'd']
        while len(comp_set) != 0:
            self.assertTrue(Bag.__contains__(self.bag, comp_set[0]), "'{}' not in bag.".format(str(comp_set[0])))
            comp_set.remove(comp_set[0])
        self.assertFalse(Bag.__contains__(self.bag, 'x'), "'x' is in bag.")
        
    def test_count(self):
        self.assertEqual(self.bag.count('a'), 1, msg = "count('a') should be 1")
        self.assertEqual(self.bag.count('b'), 2, msg = "count('b') should be 2")
        self.assertEqual(self.bag.count('c'), 1, msg = "count('c') should be 1")
        self.assertEqual(self.bag.count('d'), 3, msg = "count('d') should be 3")
        self.assertEqual(self.bag.count('x'), 0, msg = "count('x') should be 0")
        
        total_count = self.bag.count('a') + self.bag.count('b') + self.bag.count('c') + self.bag.count('d')
        my_list = self.original.copy()
        while total_count != 0:
            total_count -= 1
            s = random.choice(my_list)
            self.bag.remove(s)
            my_list.remove(s)
            self.assertEqual(self.bag.count('a') + self.bag.count('b') + self.bag.count('c') + self.bag.count('d'), total_count, "Sum of counts not equal " + str(total_count))
        self.assertEqual(self.bag.count('a') + self.bag.count('b') + self.bag.count('c') + self.bag.count('d'), total_count, "Final sum of counts not equal to 0.")
        
    def test_equal(self):
        to_bag = [random.randrange(1, 11) for i in range(1000)]
        bag1 = Bag(to_bag)
        bag2 = Bag(to_bag)
        self.assertEqual(bag1, bag2, "Bags are not equal.")
        bag1.remove(to_bag[0])
        self.assertNotEqual(bag1, bag2, "Bags should not be equal.")
        
    def test_add(self):
        to_bag = [random.randrange(1, 11) for i in range(1000)]
        bag1 = Bag(to_bag)
        random.shuffle(to_bag)
        bag2 = Bag()
        for i in to_bag:
            bag2.add(i)
        self.assertEqual(bag1, bag2, "Bags are not equal.")
        
    def test_remove(self):
        to_bag = [random.randrange(1, 11) for i in range(1000)]
        bag1 = Bag(to_bag)
        self.assertRaises(ValueError, Bag.remove, bag1, 32)
        bag2 = Bag(to_bag)
        for i in to_bag:
            bag2.add(i)
        for i in to_bag:
            bag2.remove(i)
        self.assertEqual(bag1, bag2, "Bags are not equal.")
        
        
开发者ID:ztza,项目名称:Class-Projects,代码行数:81,代码来源:q82solution.py

示例14: Test_Bag

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
class Test_Bag(unittest.TestCase):
    def setUp(self):
        self.alist = ['d','a','b','d','c','b','d']
        self.bag = Bag(self.alist)
    
    def test_len(self):
        self.assertEqual(len(self.bag),7)
        size = 7
        random.shuffle(self.alist)
        for i in self.alist:
            self.bag.remove(i)
            size -= 1
            self.assertEqual(len(self.bag),size)
        self.assertEqual(len(self.bag),0)
        
    def test_unique(self):
        self.assertEqual(self.bag.unique(),4)
        random.shuffle(self.alist)
        for i in self.alist:
            self.bag.remove(i)
            self.assertEqual(self.bag.unique(),len(set(self.bag)))
        
    def test_contains(self):
        for v in ['a','b','c','d']:
            self.assertIn(v,self.bag)
        self.assertNotIn('x',self.bag)
        
    def test_count(self):
        for v,c in zip(('a','b','c','d'), (1,2, 1, 3)):
            self.assertEqual(self.bag.count(v),c)
        random.shuffle(self.alist)
        size = 7
        for i in self.alist:
            self.bag.remove(i)
            size -= 1
            sum_count = sum([self.bag.count(c) for c in ['a','b','c','d']])
            self.assertEqual(sum_count,size)
        self.assertEqual(len(self.bag),0)
        
    def test_equals(self):
        alist = [random.randint(1,10) for i in range(1000)]
        b1 = Bag(alist)
        random.shuffle(alist)
        b2 = Bag(alist)
        self.assertEqual(b1,b2)
        b1.remove(alist[0])
        self.assertNotEquals(b1,b2)
        
    def test_add(self):
        alist = [random.randint(1,10) for i in range(1000)]
        b1 = Bag(alist)
        random.shuffle(alist)
        b2 = Bag()
        for v in alist:
            b2.add(v)
        self.assertEqual(b1,b2)
        
    def test_remove(self):
        alist = [random.randint(1,10) for i in range(1000)]
        b1 = Bag(alist)
        self.assertRaises(ValueError,b1.remove,11)
        b2 = Bag(alist)
        random.shuffle(alist)
        for v in alist:
            b2.add(v)
        for v in alist:
            b2.remove(v)
        self.assertEqual(b1,b2)
开发者ID:solomc1,项目名称:python,代码行数:70,代码来源:q82solution.py

示例15: Test_Bag

# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import remove [as 别名]
class Test_Bag(unittest.TestCase):
    def setUp(self):
        self.alist = ['d','a','b','d','c','b','d']
        self.bag = Bag(self.alist)
    
    
    def test_len(self):
        print('Checking for length:',self.alist)
        self.assertEqual(len(self.bag),7, 'Initial length of the self.bag is not 7')
        bag_length = 7
        for l in self.alist:
            self.bag.remove(l)
            bag_length -= 1
            self.assertEqual(len(self.bag),bag_length, 'length of bag object is {lenbag} but it is supposed to be {good}'.format(lenbag = str(len(self.bag)), good = str(bag_length)))
        
        
    def test_unique(self):
        print('Checking for length:',self.alist)
        self.assertEqual(self.bag.unique(), 4, 'Intial unique values in self.bag is not 4')
        alist = self.alist
        for i in range(len(self.alist)):
            self.bag.remove(self.alist[i])
            alist = self.alist[i+1:]
            self.assertEqual(self.bag.unique(),len(set(alist)), 'Number of unique value in bag is {uniqueb} but should be {setlength}'.format(uniqueb = str(self.bag.unique()) ,setlength = str(len(set(alist)))))
            
            
    def test_contains(self):
        print('Checking for contains:',self.alist)       
        for el in ['a', 'b', 'c','d']:
            self.assertTrue(el in self.bag, '{el} is not in self.bag')
        self.assertFalse('x' in self.bag, 'x is in self.bag')
        
    
    def test_count(self):
        print('Checking for counts:',self.alist)
        for num, el in [(1,'a'), (2, 'b'), (1, 'c'), (3, 'd'), (0, 'x')]:
            self.assertEqual(num, self.bag.count(el), 'Initially self.bag contains {num}{el} but it contains {numb}'.format(num = str(num), el = str(el), numb = str(self.bag.count(el))))
        init_sum = 7
        for l in self.alist:
            self.bag.remove(l)
            init_sum -= 1
            bag_sum = sum([self.bag.count(i) for i in ['a','b','c','d']])
            self.assertEqual(init_sum, bag_sum , 'sum of the counts of abcd should {init_sum} but it is {bag_sum}'.format(init_sum = init_sum, bag_sum = bag_sum))
    
    def test_equal(self):
        print('Checking for equal')
        alist = [random.randint(1,10) for i in range(1000)]
        bag1 = Bag(alist)
        random.shuffle(alist)
        bag2 = Bag(alist)
        self.assertEqual(bag1, bag2, 'Two back must be equal initially')
        bag2.remove(alist[0])
        self.assertNotEqual(bag1, bag2, 'Two back must not be equal after removing the first element of bag2')
        
    
    def test_add(self):
        print('Checking for add')
        bag1 = Bag([random.randint(1,10) for i in range(1000)])
        bag2 = Bag()
        for el in iter(bag1):
            bag2.add(el)
        self.assertEqual(bag1,bag2, 'bag1 and bag 2 must be equal after adding all terms')
        
    
    def test_remove(self):
        print('Checking for remove')
        alist = [random.randint(1,10) for i in range(1000)]
        bag1 = Bag(alist)
        self.assertRaises(ValueError, Bag.remove,bag1,32)
        bag2 = Bag(alist)
        
        for el in alist:
            bag2.add(el)
        for el in alist:
            bag2.remove(el)
        
        self.assertEqual(bag1,bag2, 'Two bag must be same after removing elements from bag2')
开发者ID:shwilliams,项目名称:ICS33,代码行数:79,代码来源:q82solution.py


注:本文中的bag.Bag.remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。