本文整理汇总了Python中bag.Bag类的典型用法代码示例。如果您正苦于以下问题:Python Bag类的具体用法?Python Bag怎么用?Python Bag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add
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')
示例2: test_equal
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.")
示例3: info_cmd
def info_cmd(argv):
parser = optparse.OptionParser(usage='rosbag info [options] BAGFILE1 [BAGFILE2 BAGFILE3 ...]',
description='Summarize the contents of one or more bag files.')
parser.add_option('-y', '--yaml', dest='yaml', default=False, action='store_true', help='print information in YAML format')
parser.add_option('-k', '--key', dest='key', default=None, action='store', help='print information on the given key')
parser.add_option( '--freq', dest='freq', default=False, action='store_true', help='display topic message frequency statistics')
(options, args) = parser.parse_args(argv)
if len(args) == 0:
parser.error('You must specify at least 1 bag file.')
if options.key and not options.yaml:
parser.error('You can only specify key when printing in YAML format.')
for i, arg in enumerate(args):
try:
b = Bag(arg, 'r', skip_index=not options.freq)
if options.yaml:
info = b._get_yaml_info(key=options.key)
if info is not None:
print info
else:
print b
b.close()
if i < len(args) - 1:
print '---'
except ROSBagUnindexedException, ex:
print >> sys.stderr, 'ERROR bag unindexed: %s. Run rosbag reindex.' % arg
except ROSBagException, ex:
print >> sys.stderr, 'ERROR reading %s: %s' % (arg, str(ex))
示例4: test_add
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)
示例5: test_add
def test_add(self):
temp_list = [random.randint(1,10) for i in range(1,1001)]
b1 = Bag(temp_list)
b2 = Bag()
random.shuffle(temp_list)
for i in temp_list:
b2.add(i)
self.assertEqual(b1,b2)
示例6: test_eq
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)
示例7: test_add
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.")
示例8: test_equals
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)
示例9: test_equal
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')
示例10: testEqual
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)
示例11: test_add
def test_add(self):
bag2 = []
for i in range(0,1000):
bag2.append((random.randint(1,10)))
check_bag = Bag(bag2)
check_bag2 = Bag()
random.shuffle(bag2)
for i in check_bag:
check_bag2.add(i)
self.assertEqual(check_bag,check_bag2)
示例12: test_eq
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)
示例13: test_remove
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)
示例14: evaluate_pathway
def evaluate_pathway(list_of_paths):
scores = []
# create a set of all participating enzymes, and count the number of enzymes that are not trivial
total_path_length = 0
enzyme_bag = Bag()
enzyme_type_bag = Bag()
for path in list_of_paths:
for enzyme in path_to_enzyme_list(path):
if (not enzyme in pp_enzymes):
total_path_length += 1
enzyme_bag[enzyme] += 1
enzyme_type_bag[enzyme_types[enzyme]] += 1
scores.append((params['TL'], total_path_length))
scores.append((params['NE'], enzyme_type_bag['EPI']))
scores.append((params['NI'], enzyme_type_bag['ISO']))
scores.append((params['NK'], enzyme_type_bag['KIN']))
scores.append((params['ND'], enzyme_type_bag['DHG']))
num_isoenzymes = 0
for (enzyme, count) in enzyme_bag.itercounts():
if (count > 1):
num_isoenzymes += 1
scores.append((params['MIE'], num_isoenzymes))
total_phosphorilation_distance = 0
for path in list_of_paths:
for enzyme in path_to_enzyme_list(path):
if (enzyme_types[enzyme] == "KIN"):
break
else:
total_phosphorilation_distance += 1
scores.append((params['TPD'], total_phosphorilation_distance))
# NTE - Number maximum number of same-product epimerases
G = pathway_to_graph(list_of_paths)
max_epimerase_count = 0
max_split = 0
for v in G.itervertices():
epimerase_count = 0
for child in G[v]:
if (enzyme_types[(v, child)] == "EPI"):
epimerase_count += 1
max_epimerase_count = max(max_epimerase_count, epimerase_count)
max_split = max(max_split, len(G[v]))
scores.append((params['NTE'], max_epimerase_count))
# copy on the scores that have a parameter which is not None.
chosen_scores = []
for (p, s) in scores:
if (p != None):
chosen_scores.append((p, s))
chosen_scores.sort()
return tuple([s[1] for s in chosen_scores])
示例15: test_remove
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)