Exemplo n.º 1
0
 def test_build_cannot_evaluate(self) -> None:
     sequencer = DummySequencer()
     block = DummyInstructionBlock()
     
     delegator = DummySequencingElement()
     body = DummySequencingElement()
     
     condition = SoftwareCondition(lambda loop_iteration: None)
     
     self.assertTrue(condition.requires_stop())
     self.assertRaises(ConditionEvaluationException, condition.build_sequence_loop, delegator, body, sequencer, {}, {}, block)
     self.assertRaises(ConditionEvaluationException, condition.build_sequence_branch, delegator, body, body, sequencer, {}, {}, block)
     self.assertEqual(str(ConditionEvaluationException()), "The Condition can currently not be evaluated.")
Exemplo n.º 2
0
 def test_build_sequence_loop_false(self):
     sequencer = DummySequencer()
     block = DummyInstructionBlock()
     
     delegator = DummySequencingElement()
     body = DummySequencingElement()
     callback = IterationCallbackDummy(False)
     
     condition = SoftwareCondition(lambda loop_iteration: callback.callback(loop_iteration))
     condition.build_sequence_loop(delegator, body, sequencer, {}, {},  block)
     
     self.assertEqual(0, callback.loop_iteration)
     self.assertFalse(block.instructions)
     self.assertFalse(sequencer.sequencing_stacks)
     
     condition.build_sequence_loop(delegator, body, sequencer, {}, {}, block)
     self.assertEqual(0, callback.loop_iteration)
Exemplo n.º 3
0
 def test_build_sequence_branch_true(self):
     sequencer = DummySequencer()
     block = DummyInstructionBlock()
     
     delegator = DummySequencingElement()
     if_branch = DummySequencingElement()
     else_branch = DummySequencingElement()
     callback = IterationCallbackDummy(True)
     
     condition = SoftwareCondition(lambda loop_iteration: callback.callback(loop_iteration))
     condition.build_sequence_branch(delegator, if_branch, else_branch, sequencer, {}, {}, block)
     
     self.assertEqual(0, callback.loop_iteration)
     self.assertFalse(block.instructions)
     self.assertEqual({block: [(if_branch, {}, {})]}, sequencer.sequencing_stacks)
     
     condition.build_sequence_branch(delegator, if_branch, else_branch, sequencer, {}, {}, block)
     self.assertEqual(0, callback.loop_iteration)
Exemplo n.º 4
0
    def test_build_cannot_evaluate(self) -> None:
        sequencer = DummySequencer()
        block = DummyInstructionBlock()

        delegator = DummySequencingElement()
        body = DummySequencingElement()

        condition = SoftwareCondition(lambda loop_iteration: None)

        self.assertTrue(condition.requires_stop())
        with self.assertRaises(ConditionEvaluationException):
            condition.build_sequence_loop(delegator, body, sequencer, {}, {},
                                          {}, {}, block)
        with self.assertRaises(ConditionEvaluationException):
            condition.build_sequence_branch(delegator, body, body, sequencer,
                                            {}, {}, {}, {}, block)
        self.assertEqual(str(ConditionEvaluationException()),
                         "The Condition can currently not be evaluated.")
Exemplo n.º 5
0
    def test_build_sequence_loop_false(self):
        sequencer = DummySequencer()
        block = DummyInstructionBlock()

        delegator = DummySequencingElement()
        body = DummySequencingElement()
        callback = IterationCallbackDummy(False)

        condition = SoftwareCondition(
            lambda loop_iteration: callback.callback(loop_iteration))
        condition.build_sequence_loop(delegator, body, sequencer, {}, {}, {},
                                      {}, block)

        self.assertEqual(0, callback.loop_iteration)
        self.assertFalse(block.instructions)
        self.assertFalse(sequencer.sequencing_stacks)

        condition.build_sequence_loop(delegator, body, sequencer, {}, {}, {},
                                      {}, block)
        self.assertEqual(0, callback.loop_iteration)
Exemplo n.º 6
0
    def test_build_sequence_branch_true(self):
        sequencer = DummySequencer()
        block = DummyInstructionBlock()

        delegator = DummySequencingElement()
        if_branch = DummySequencingElement()
        else_branch = DummySequencingElement()
        callback = IterationCallbackDummy(True)

        condition = SoftwareCondition(
            lambda loop_iteration: callback.callback(loop_iteration))
        condition.build_sequence_branch(delegator, if_branch, else_branch,
                                        sequencer, {}, {}, {}, {}, block)

        self.assertEqual(0, callback.loop_iteration)
        self.assertFalse(block.instructions)
        self.assertEqual({block: [(if_branch, {}, {}, {}, {})]},
                         sequencer.sequencing_stacks)

        condition.build_sequence_branch(delegator, if_branch, else_branch,
                                        sequencer, {}, {}, {}, {}, block)
        self.assertEqual(0, callback.loop_iteration)