本文整理汇总了Python中kitty.model.GraphModel.get_sequence方法的典型用法代码示例。如果您正苦于以下问题:Python GraphModel.get_sequence方法的具体用法?Python GraphModel.get_sequence怎么用?Python GraphModel.get_sequence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kitty.model.GraphModel
的用法示例。
在下文中一共展示了GraphModel.get_sequence方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GraphModelTests
# 需要导入模块: from kitty.model import GraphModel [as 别名]
# 或者: from kitty.model.GraphModel import get_sequence [as 别名]
class GraphModelTests(unittest.TestCase):
def setUp(self):
self.logger = get_test_logger()
self.logger.debug('TESTING METHOD: %s', self._testMethodName)
self.model = GraphModel()
self.templates = self.get_templates()
self.todo = []
def get_templates(self):
res = []
res.append(Template(name='t1', fields=[String('data1')]))
res.append(Template(name='t2', fields=[String('data2'), UInt32(300)]))
res.append(Template(name='t3', fields=[UInt32(400)]))
return res
def _check_sequences(self, expected_sequences):
self.logger.debug('check num_mutations()')
t_num_mutations = sum(s[-1].num_mutations() for s in expected_sequences)
m_num_mutations = self.model.num_mutations()
self.assertEqual(t_num_mutations, m_num_mutations)
sequences = {}
while self.model.mutate():
sequence = tuple(self.model.get_sequence())
if sequence not in sequences:
sequences[sequence] = 1
else:
sequences[sequence] += 1
self.assertEqual(len(sequences), len(expected_sequences))
self.logger.debug('check that each sequence appears the appropriate number of times')
for sequence, count in sequences.items():
seq_templates = [e.dst for e in sequence]
self.assertIn(seq_templates, expected_sequences)
last = seq_templates[-1]
last_num_mutations = last.num_mutations()
self.assertEqual(count, last_num_mutations)
def test_sequence_single_template(self):
t = self.templates[0]
self.model.connect(t)
expected_sequences = [[t]]
self._check_sequences(expected_sequences)
def test_sequence_direct_path(self):
'''
root -> t1
'''
self.model.connect(self.templates[0])
for i in range(len(self.templates) - 1):
self.model.connect(self.templates[i], self.templates[i + 1])
expected_sequences = list(self.templates[:i + 1] for i in range(len(self.templates)))
self._check_sequences(expected_sequences)
def test_sequence_complex_path(self):
'''
root -> t1
root -> t1 -> t2
root -> t1 -> t3
root -> t1 -> t2 -> t3
'''
self.model.connect(self.templates[0])
self.model.connect(self.templates[0], self.templates[1])
self.model.connect(self.templates[0], self.templates[2])
self.model.connect(self.templates[1], self.templates[2])
expected_sequences = [
[self.templates[0]],
[self.templates[0], self.templates[1]],
[self.templates[0], self.templates[2]],
[self.templates[0], self.templates[1], self.templates[2]]
]
self._check_sequences(expected_sequences)
def test_multi_head_path(self):
'''
root -> t1
root -> t2
root -> t3
'''
expected_sequences = []
for t in self.templates:
expected_sequences.append([t])
self.model.connect(t)
self._check_sequences(expected_sequences)
def _check_skip(self, to_skip, expected_skipped, expected_mutated):
skipped = self.model.skip(to_skip)
self.assertEqual(expected_skipped, skipped)
mutated = 0
while self.model.mutate():
mutated += 1
self.assertEqual(expected_mutated, mutated)
def test_skip_zero_single_template(self):
self.model.connect(self.templates[0])
m_num_mutations = self.model.num_mutations()
to_skip = 0
expected_skipped = to_skip
expected_mutated = m_num_mutations
self._check_skip(to_skip, expected_skipped, expected_mutated)
#.........这里部分代码省略.........