def test_addSuccessorThatAlreadyExists(self): """ Adds the same node multiple times to another node and expects it to raise an Exception. :return: """ # TODO: Specify type of Exception. test_node = Node() add_node = Node() with self.assertRaises(Exception): test_node.add_successor(add_node, float(Fraction(0))) test_node.add_successor(add_node, float(Fraction(0)))
def test_addSuccessor(self): """ Generates 100 random values from -1 to 2. Creates new nodes for every value and adds them using the generated value as the weight. Checks, that for values below zero and above one a ValueError is raised. :return: """ test_node = Node() for val in [self.rand.uniform(-1, 2) for _ in range(100)]: new_node = Node() if val < 0 or val > 1: with self.assertRaises(ValueError): test_node.add_successor(new_node, Fraction.from_float(val)) else: test_node.add_successor(new_node, Fraction.from_float(val))
def test_addSuccessors(self): """ Generates a list of nodes, appends it to a test node and checks, if add_successor was called for every node. :return: """ test_node = Node() test_node.add_successor = MagicMock() node_list = [(Node(), float(Fraction(0))) for _ in range(10)] test_node.add_successors(node_list) for elem in node_list: self.assertIn((elem,), test_node.add_successor.call_args_list)