def test_addCycleSuccessorThatAlreadyExists(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 = CycleNode(float(Fraction(0))) add_node = CycleNode(float(Fraction(0))) with self.assertRaises(Exception): test_node.add_cycle_successor(add_node, float(Fraction(0))) test_node.add_cycle_successor(add_node, float(Fraction(0)))
def test_addCycleSuccessors(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 = CycleNode(float(Fraction(0))) test_node.add_cycle_successor = MagicMock() node_list = [(Node(), float(Fraction(0))) for _ in range(10)] test_node.add_cycle_successors(node_list) for elem in node_list: self.assertIn((elem,), test_node.add_cycle_successor.call_args_list)
def test_addCycleSuccessor(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 = CycleNode(float(Fraction(0))) 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_cycle_successor( new_node, Fraction.from_float(val) ) else: test_node.add_cycle_successor( new_node, Fraction.from_float(val) )