def test_inequality_between_nodes_with_different_states(): """Test that Nodes with different states are inequivalent.""" from electric_slide.scripts.priority_q import Node node1 = Node([[1, 2, 3], [4, 5, 6], [9, 7, 8]], (1, 2), None) node2 = Node([[9, 2, 3], [1, 5, 6], [4, 7, 8]], (1, 2), None) assert node1 is not node2 assert node1 != node2
def test_equality_between_nodes_with_the_same_state(n1): """Test that Nodes with the same state are equivalent.""" from electric_slide.scripts.priority_q import Node node1 = Node([[1, 2, 3], [4, 5, 6], [9, 7, 8]], (1, 2), None) node2 = Node([[1, 2, 3], [4, 5, 6], [9, 7, 8]], (3, 1), n1) assert node1 is not node2 assert node1 == node2
def chain7(n0, n1): """A chain of 5 nodes.""" from electric_slide.scripts.priority_q import Node n2 = Node([[1, 2, 3], [4, 5, 6], [9, 7, 8]], (1, 3), n1) n3 = Node([[1, 2, 3], [9, 5, 6], [4, 7, 8]], (1, 2), n2) n4 = Node([[9, 2, 3], [1, 5, 6], [4, 7, 8]], (1, 1), n3) n5 = Node([[2, 9, 3], [1, 5, 6], [4, 7, 8]], (2, 1), n4) return Node([[2, 5, 3], [1, 9, 6], [4, 7, 8]], (2, 2), n5)
def test_construct_a_new_start_node(): """Test that a starting node can be constructed.""" from electric_slide.scripts.priority_q import Node n = Node([[1, 2, 3], [4, 5, 6], [7, 8, 9]], None, None) assert n.move is None assert n.prev is None assert n.state == [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
def test_construct_a_new_child_node(n1): """Test that creating a child Node points to parent.""" from electric_slide.scripts.priority_q import Node next_state = [[1, 2, 3], [4, 5, 6], [9, 7, 8]] n = Node(next_state, (1, 3), n1) assert n.move == (1, 3) assert n.prev is n1 assert n.state == next_state
def n1(n0): """A child Node after n0.""" from electric_slide.scripts.priority_q import Node next_state = [[1, 2, 3], [4, 5, 6], [7, 9, 8]] return Node(next_state, (2, 3), n0)
def n0(): """A starting Node.""" from electric_slide.scripts.priority_q import Node return Node([[1, 2, 3], [4, 5, 6], [7, 8, 9]], None, None)