Exemplo n.º 1
0
    def testCallbackGenerator(self):
        self.src_templates = []
        self.dst_templates = []
        self.cb_call_count = 0

        def cb_gen(src, dst):
            self.src_templates.append(src)
            self.dst_templates.append(dst)
            self.cb_call_count += 1
            return self.cb_call_count
        first_time = True

        model = StagedSequenceModel(name='uut', callback_generator=cb_gen, num_mutations=100)
        for stage in self.stages:
            model.add_stage(stage)
        while model.mutate():
            sequence = model.get_sequence()
            # this ugly piece of code is needed because we want to ignore the
            # default sequence generation
            delta = 0
            def_len = len(model._default_sequence)
            if first_time:
                self.src_templates = self.src_templates[def_len:]
                self.dst_templates = self.dst_templates[def_len:]
                self.cb_call_count -= def_len
                delta = def_len
                first_time = False
            self.assertEqual(len(sequence), self.cb_call_count)
            for i in range(len(sequence)):
                self.assertEqual(self.src_templates[i], sequence[i].src)
                self.assertEqual(self.dst_templates[i], sequence[i].dst)
                self.assertEqual(delta + i + 1, sequence[i].callback)
            self.src_templates = []
            self.dst_templates = []
            self.cb_call_count = 0
Exemplo n.º 2
0
 def test_sequence_length_single_stage(self):
     for stage in self.stages:
         expected_length = self.stage_lengths[stage]
         model = StagedSequenceModel(num_mutations=100)
         model.add_stage(stage)
         while model.mutate():
             sequence = model.get_sequence()
             sequence_length = len(sequence)
             self.assertEqual(expected_length, sequence_length)
Exemplo n.º 3
0
 def test_skip_too_much(self):
     model = StagedSequenceModel(num_mutations=120)
     model.add_stage(self.stages[0])
     model.add_stage(self.stages[1])
     m_num_mutations = model.num_mutations()
     to_skip = m_num_mutations + 10
     expected_skipped = m_num_mutations
     expected_mutated = m_num_mutations - expected_skipped
     self._check_skip(model, to_skip, expected_skipped, expected_mutated)
Exemplo n.º 4
0
 def testSkipTooMuch(self):
     model = StagedSequenceModel(num_mutations=120)
     model.add_stage(self.stages[0])
     model.add_stage(self.stages[1])
     m_num_mutations = model.num_mutations()
     to_skip = m_num_mutations + 10
     expected_skipped = m_num_mutations
     expected_mutated = m_num_mutations - expected_skipped
     self._check_skip(model, to_skip, expected_skipped, expected_mutated)
Exemplo n.º 5
0
 def testSkipHalf(self):
     model = StagedSequenceModel(num_mutations=120)
     model.add_stage(self.stages[0])
     model.add_stage(self.stages[1])
     m_num_mutations = model.num_mutations()
     to_skip = m_num_mutations / 2
     expected_skipped = to_skip
     expected_mutated = m_num_mutations - expected_skipped
     self._check_skip(model, to_skip, expected_skipped, expected_mutated)
Exemplo n.º 6
0
 def test_num_mutations_single_stage(self):
     num_mutation_list = [0, 1, 500, 1000, 10000]
     for expected_num_mutations in num_mutation_list:
         model = StagedSequenceModel(num_mutations=expected_num_mutations)
         model.add_stage(self.stages[0])
         m_num_mutations = model.num_mutations()
         self.assertEqual(expected_num_mutations, m_num_mutations)
         actual_mutations = 0
         while model.mutate():
             actual_mutations += 1
         self.assertEqual(expected_num_mutations, actual_mutations)
Exemplo n.º 7
0
 def testNumMutationsMultiStage(self):
     num_mutation_list = [0, 1, 500, 1000, 10000]
     for expected_num_mutations in num_mutation_list:
         model = StagedSequenceModel(num_mutations=expected_num_mutations)
         for stage in self.stages:
             model.add_stage(stage)
         m_num_mutations = model.num_mutations()
         self.assertEqual(expected_num_mutations, m_num_mutations)
         actual_mutations = 0
         while model.mutate():
             actual_mutations += 1
         self.assertEqual(expected_num_mutations, actual_mutations)
Exemplo n.º 8
0
    def testCallbackGenerator(self):
        self.src_templates = []
        self.dst_templates = []
        self.cb_call_count = 0

        def cb_gen(src, dst):
            self.src_templates.append(src)
            self.dst_templates.append(dst)
            self.cb_call_count += 1
            return self.cb_call_count

        model = StagedSequenceModel(name='uut',
                                    callback_generator=cb_gen,
                                    num_mutations=100)
        for stage in self.stages:
            model.add_stage(stage)
        while model.mutate():
            sequence = model.get_sequence()
            self.assertEqual(len(sequence), self.cb_call_count)
            for i in range(len(sequence)):
                self.assertEqual(self.src_templates[i], sequence[i].src)
                self.assertEqual(self.dst_templates[i], sequence[i].dst)
                self.assertEqual(i + 1, sequence[i].callback)
            self.src_templates = []
            self.dst_templates = []
            self.cb_call_count = 0
Exemplo n.º 9
0
 def testSequenceLengthSingleStage(self):
     for stage in self.stages:
         expected_length = self.stage_lengths[stage]
         model = StagedSequenceModel(num_mutations=100)
         model.add_stage(stage)
         while model.mutate():
             sequence = model.get_sequence()
             sequence_length = len(sequence)
             self.assertEqual(expected_length, sequence_length)
Exemplo n.º 10
0
    def test_callback_generator(self):
        self.src_templates = []
        self.dst_templates = []
        self.cb_call_count = 0

        def cb_gen(src, dst):
            self.src_templates.append(src)
            self.dst_templates.append(dst)
            self.cb_call_count += 1
            return self.cb_call_count

        model = StagedSequenceModel(name='uut', callback_generator=cb_gen, num_mutations=100)
        for stage in self.stages:
            model.add_stage(stage)
        while model.mutate():
            sequence = model.get_sequence()
            self.assertEqual(len(sequence), self.cb_call_count)
            for i in range(len(sequence)):
                self.assertEqual(self.src_templates[i], sequence[i].src)
                self.assertEqual(self.dst_templates[i], sequence[i].dst)
                self.assertEqual(i + 1, sequence[i].callback)
            self.src_templates = []
            self.dst_templates = []
            self.cb_call_count = 0
Exemplo n.º 11
0
 def testNumMutationsSingleStage(self):
     num_mutation_list = [0, 1, 500, 1000, 10000]
     for expected_num_mutations in num_mutation_list:
         model = StagedSequenceModel(num_mutations=expected_num_mutations)
         model.add_stage(self.stages[0])
         m_num_mutations = model.num_mutations()
         self.assertEqual(expected_num_mutations, m_num_mutations)
         actual_mutations = 0
         while model.mutate():
             actual_mutations += 1
         self.assertEqual(expected_num_mutations, actual_mutations)
Exemplo n.º 12
0
    def testCallbackGenerator(self):
        self.src_templates = []
        self.dst_templates = []
        self.cb_call_count = 0

        def cb_gen(src, dst):
            self.src_templates.append(src)
            self.dst_templates.append(dst)
            self.cb_call_count += 1
            return self.cb_call_count

        first_time = True

        model = StagedSequenceModel(name='uut',
                                    callback_generator=cb_gen,
                                    num_mutations=100)
        for stage in self.stages:
            model.add_stage(stage)
        while model.mutate():
            sequence = model.get_sequence()
            # this ugly piece of code is needed because we want to ignore the
            # default sequence generation
            delta = 0
            def_len = len(model._default_sequence)
            if first_time:
                self.src_templates = self.src_templates[def_len:]
                self.dst_templates = self.dst_templates[def_len:]
                self.cb_call_count -= def_len
                delta = def_len
                first_time = False
            self.assertEqual(len(sequence), self.cb_call_count)
            for i in range(len(sequence)):
                self.assertEqual(self.src_templates[i], sequence[i].src)
                self.assertEqual(self.dst_templates[i], sequence[i].dst)
                self.assertEqual(delta + i + 1, sequence[i].callback)
            self.src_templates = []
            self.dst_templates = []
            self.cb_call_count = 0