def test_process_branch_rtn(self): bb = BranchAndBound(small_branch) node = BaseNode(small_branch.lp, small_branch.integerIndices, idx=0) node.bound() rtn = node.branch(next_node_idx=1) left_node = rtn['left'] right_node = rtn['right'] bb._process_branch_rtn(node.idx, rtn) # check attributes self.assertTrue(isinstance(bb._node_queue.get(), BaseNode)) self.assertTrue(isinstance(bb._node_queue.get(), BaseNode)) self.assertTrue(bb._node_queue.empty()) children = bb.tree.get_children(node.idx) self.assertTrue(len(children) == 2, 'there should be two kids created') for child in children: self.assertFalse(bb.tree.get_children(child), 'children shouldnt have kids') self.assertTrue(bb.tree.get_node(1).attr['node'] is left_node) self.assertTrue(bb.tree.get_node(2).attr['node'] is right_node) # check function calls bb = BranchAndBound(small_branch) node = BaseNode(small_branch.lp, small_branch.integerIndices, 0) node.bound() rtn = node.branch() with patch.object(bb, '_process_rtn') as pr, \ patch.object(bb.tree, 'add_left_child') as alc, \ patch.object(bb.tree, 'add_right_child') as arc: bb._process_branch_rtn(0, rtn) self.assertTrue(pr.call_count == 1, 'should call process rtn') self.assertTrue(alc.call_count == 1, 'should call add left child') self.assertTrue(arc.call_count == 1, 'should call add right child')
def test_process_branch_rtn(self): bb = BranchAndBound(small_branch) node = BaseNode(small_branch.lp, small_branch.integerIndices) node.bound() rtn = node.branch() bb._process_branch_rtn(rtn) # check attributes self.assertTrue(isinstance(bb._node_queue.get(), BaseNode)) self.assertTrue(isinstance(bb._node_queue.get(), BaseNode)) self.assertTrue(bb._node_queue.empty()) # check function calls bb = BranchAndBound(small_branch) node = BaseNode(small_branch.lp, small_branch.integerIndices) node.bound() rtn = node.branch() with patch.object(bb, '_process_rtn') as pr: bb._process_branch_rtn(rtn) self.assertTrue(pr.call_count == 1, 'should call rtn')