def test_addresses_are_cut_to_match_arity(): """Test that even if a list of addresses longer than the node arity is provided, Node.addresses only returns the initial <arity> addresses, ignoring the inactive genes. """ idx = 0 addresses = [1, 2, 3, 4] node = cgp.ConstantFloat(idx, addresses) assert node.addresses == [] node = cgp.node_input_output.OutputNode(idx, addresses) assert node.addresses == addresses[:1] node = cgp.Add(idx, addresses) assert node.addresses == addresses[:2]
def test_inputs_are_cut_to_match_arity(): """Test that even if a list of inputs longer than the node arity is provided, Node.inputs only returns the initial <arity> inputs, ignoring the inactive genes. """ idx = 0 inputs = [1, 2, 3, 4] node = cgp.ConstantFloat(idx, inputs) assert node.inputs == [] node = cgp.node.OutputNode(idx, inputs) assert node.inputs == inputs[:1] node = cgp.Add(idx, inputs) assert node.inputs == inputs[:2]
def test_repr(): idx = 0 addresses = [1, 2, 3, 4] # Test example of OperatorNode with arity 0 node = cgp.ConstantFloat(idx, addresses) node_repr = str(node) assert node_repr == "ConstantFloat(idx: 0, active: False, arity: 0, addresses of inputs []" # Test OutputNode node = cgp.node_input_output.OutputNode(idx, addresses) node_repr = str(node) assert node_repr == "OutputNode(idx: 0, active: False, arity: 1, addresses of inputs [1]" # Test example of OperatorNode with arity 2 node = cgp.Add(idx, addresses) node_repr = str(node) assert node_repr == "Add(idx: 0, active: False, arity: 2, addresses of inputs [1, 2]"
def test_init_with_instance_raises(): with pytest.raises(TypeError): Primitives((cgp.Add(0, []), ))