コード例 #1
0
 def IfNotCondTest(self, cond_net, expect, cond_on_blob):
     if cond_on_blob:
         step = control.Do(
             control.Do(cond_net),
             control.IfNot(cond_net.Proto().external_output[-1],
                           self.cnt_net_))
     else:
         step = control.IfNot(cond_net, self.cnt_net_)
     self.BuildAndRunPlan(step)
     self.CheckNetOutput([(self.cnt_net_, expect)])
コード例 #2
0
 def IfNotElseCondTest(self, cond_net, expect, cond_on_blob):
     true_step = control.For(self.cnt_net_, self.N_)
     false_step = control.For(self.cnt_net_, 2 * self.N_)
     if cond_on_blob:
         step = control.Do(
             control.Do(cond_net),
             control.IfNot(cond_net.Proto().external_output[-1], true_step,
                           false_step))
     else:
         step = control.IfNot(cond_net, true_step, false_step)
     self.BuildAndRunPlan(step)
     self.CheckNetOutput([(self.cnt_net_, expect)])
コード例 #3
0
    def testMergeConditionNets(self):
        # merged by 'Or'
        merge_net = control.MergeConditionNets(
            'test', [self.true_cond_net_, self.false_cond_net_], 'Or')
        step = control.Do('merge', merge_net)
        self.BuildAndRunPlan(step)
        self.CheckNetOutput([(merge_net, True)])

        # merged by 'And'
        merge_net = control.MergeConditionNets(
            'test', [self.true_cond_net_, self.false_cond_net_], 'And')
        step = control.Do('merge', merge_net)
        self.BuildAndRunPlan(step)
        self.CheckNetOutput([(merge_net, False)])
コード例 #4
0
    def testBoolNet(self):
        bool_net = control.BoolNet(('a', True))
        step = control.Do('bool', bool_net)
        self.BuildAndRunPlan(step)
        self.CheckNetAllOutput(bool_net, [True])

        bool_net = control.BoolNet(('a', True), ('b', False))
        step = control.Do('bool', bool_net)
        self.BuildAndRunPlan(step)
        self.CheckNetAllOutput(bool_net, [True, False])

        bool_net = control.BoolNet([('a', True), ('b', False)])
        step = control.Do('bool', bool_net)
        self.BuildAndRunPlan(step)
        self.CheckNetAllOutput(bool_net, [True, False])
コード例 #5
0
    def testCombineConditions(self):
        # combined by 'Or'
        combine_net = control.CombineConditions(
            'test', [self.true_cond_net_, self.false_cond_net_], 'Or')
        step = control.Do('combine', self.true_cond_net_, self.false_cond_net_,
                          combine_net)
        self.BuildAndRunPlan(step)
        self.CheckNetOutput([(combine_net, True)])

        # combined by 'And'
        combine_net = control.CombineConditions(
            'test', [self.true_cond_net_, self.false_cond_net_], 'And')
        step = control.Do('combine', self.true_cond_net_, self.false_cond_net_,
                          combine_net)
        self.BuildAndRunPlan(step)
        self.CheckNetOutput([(combine_net, False)])
コード例 #6
0
 def IfNotElseCondTest(self, cond_net, cond_value, expect, cond_on_blob):
     if cond_value:
         run_net = self.cnt_2_net_
     else:
         run_net = self.cnt_net_
     if cond_on_blob:
         step = control.Do(
             'if-not-else', control.Do('count', cond_net),
             control.IfNot('myIfNotElse',
                           cond_net.Proto().external_output[-1],
                           self.cnt_net_, self.cnt_2_net_))
     else:
         step = control.IfNot('myIfNotElse', cond_net, self.cnt_net_,
                              self.cnt_2_net_)
     self.BuildAndRunPlan(step)
     self.CheckNetOutput([(run_net, expect)])
コード例 #7
0
 def testDoUntilLoopWithStep(self):
     step = control.Do('count', self.cnt_net_)
     self.DoUntilLoopTest(step)
     self.DoUntilLoopTest([self.idle_net_, step])
コード例 #8
0
 def testWhileLoopWithStep(self):
     step = control.Do('count', self.cnt_net_)
     self.WhileLoopTest(step)
     self.WhileLoopTest([step, self.idle_net_])
コード例 #9
0
 def BuildAndRunPlan(self, step):
     plan = core.Plan("test")
     plan.AddStep(control.Do('init', self.init_net_))
     plan.AddStep(step)
     self.assertEqual(workspace.RunPlan(plan), True)
コード例 #10
0
 def testUntilLoopWithStep(self):
     step = control.Do(self.cnt_net_)
     self.UntilLoopTest(step)
コード例 #11
0
 def testWhileLoopWithStep(self):
     step = control.Do(self.cnt_net_)
     self.WhileLoopTest(step)
コード例 #12
0
 def testForLoopWithStep(self):
     step = control.Do(self.cnt_net_)
     self.ForLoopTest(step)