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)])
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)])
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)])
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])
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)])
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)])
def testDoUntilLoopWithStep(self): step = control.Do('count', self.cnt_net_) self.DoUntilLoopTest(step) self.DoUntilLoopTest([self.idle_net_, step])
def testWhileLoopWithStep(self): step = control.Do('count', self.cnt_net_) self.WhileLoopTest(step) self.WhileLoopTest([step, self.idle_net_])
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)
def testUntilLoopWithStep(self): step = control.Do(self.cnt_net_) self.UntilLoopTest(step)
def testWhileLoopWithStep(self): step = control.Do(self.cnt_net_) self.WhileLoopTest(step)
def testForLoopWithStep(self): step = control.Do(self.cnt_net_) self.ForLoopTest(step)