def test_dijsktra_step_internals(self): """ Test for dijkstra's results after the first step """ """test if the start point is added to the open node list""" myFlaeche = main.Flaeche(xdim=300, ydim=300, scale=10) myD_step_zero = Dijkstra(myFlaeche, (0, 0), (20, 10)) myD_step_zero.step() self.assertEqual(myD_step_zero.get_open_nodes('tuples'), [(0, 0)]) self.assertEqual(myD_step_zero.get_closed_nodes('tuples'), []) """ test if nodes are added to the closed list """ myFlaeche = main.Flaeche(xdim=300, ydim=300, scale=10) myD = Dijkstra(myFlaeche, (0, 0), (20, 10)) myD.step() myD.step(visual=False) self.assertEqual(myD.get_open_nodes('tuples'), [(0, 1), (1, 0), (1, 1)]) self.assertEqual(myD.get_closed_nodes('tuples'), [(0, 0)]) """test that nodes in the closed nodes list are omitted""" myD_fake_closed = Dijkstra(myFlaeche, (0, 0), (20, 10)) myDN_1 = StarNode(xx=0, yy=0, tt=4, dd=5, lastNode=None) myDN_2 = StarNode(xx=1, yy=1, tt=4, dd=5, lastNode=None) myD_fake_closed.open_nodes_list.append(myDN_1) myD_fake_closed.closed_nodes_list.append(myDN_2) # should find myDN_2 as suspicious node # and reject as it alrerady is in closed node list myD_fake_closed.step() self.assertEqual(myD_fake_closed.get_open_nodes('tuples'), [(0, 1), (1, 0)]) """test that nodes in the open lists are updated""" myD_fake_open = Dijkstra(myFlaeche, (0, 0), (20, 10)) myDN_0 = StarNode(xx=1, yy=1, tt=400, dd=500, lastNode=None) myDN_1 = StarNode(xx=0, yy=0, tt=4, dd=5, lastNode=None) myD_fake_open.open_nodes_list.append(myDN_0) myD_fake_open.open_nodes_list.append(myDN_1) # should now take myDN_1 as next node # and finding a shorter path to myDN_0 # and should update the open list after the step self.assertEqual(sorted(myD_fake_open.get_open_nodes('tuples')), [(0, 0), (1, 1)]) long_way = DNList(myD_fake_open.open_nodes_list).get_by_tuple( (1, 1)).full_costs """test the unfished return value""" self.assertFalse(myD_fake_open.step()) short_way = DNList(myD_fake_open.open_nodes_list).get_by_tuple( (1, 1)).full_costs self.assertGreater(long_way, short_way) """test that the algo stops if the end is reached - manipulated lists""" myD_fake_end = Dijkstra(myFlaeche, (0, 0), (20, 10)) myDN_1 = StarNode(xx=20, yy=10, tt=4, dd=0, lastNode=None) myDN_2 = StarNode(xx=12, yy=10, tt=4, dd=7, lastNode=None) # dest point in open and the shortest myD_fake_end.open_nodes_list.append(myDN_1) myD_fake_end.open_nodes_list.append(myDN_2) # some point the longest self.assertTrue(myD_fake_end.step())
def test_dikstra_get_nodes_list(self): """test the getter of the nodes lists""" start = (10, 10) end = (20, 10) myFlaeche = main.Flaeche(xdim=30, ydim=30, scale=1) myD = Dijkstra(myFlaeche, start, end) self.assertEqual(myD.get_open_nodes(), []) myDN_1 = StarNode(xx=3, yy=3, tt=4, dd=5, lastNode=None) myDN_2 = StarNode(xx=4, yy=3, tt=4, dd=5, lastNode=None) myDN_3 = StarNode(xx=5, yy=5, tt=4, dd=5, lastNode=None) myDN_4 = StarNode(xx=5, yy=6, tt=4, dd=5, lastNode=None) """get the nodes tuples""" myD.open_nodes_list[0:0] = [myDN_1, myDN_2] self.assertEqual( sorted(myD.get_open_nodes('tuples')), sorted([(3, 3), (4, 3)])) """get the node them self """ self.assertEqual( sorted(myD.get_open_nodes()), sorted([myDN_1, myDN_2])) """get the node tuples of closed list """ myD.closed_nodes_list[0:0] = [myDN_3, myDN_4] self.assertEqual( sorted(myD.get_closed_nodes('tuples')), sorted([(5, 5), (5, 6)]))
def test_dikstra_get_nodes_list(self): """test the getter of the nodes lists""" start = (10, 10) end = (20, 10) myFlaeche = main.Flaeche(xdim=30, ydim=30, scale=1) myD = Dijkstra(myFlaeche, start, end) self.assertEqual(myD.get_open_nodes(), []) myDN_1 = StarNode(xx=3, yy=3, tt=4, dd=5, lastNode=None) myDN_2 = StarNode(xx=4, yy=3, tt=4, dd=5, lastNode=None) myDN_3 = StarNode(xx=5, yy=5, tt=4, dd=5, lastNode=None) myDN_4 = StarNode(xx=5, yy=6, tt=4, dd=5, lastNode=None) """get the nodes tuples""" myD.open_nodes_list[0:0] = [myDN_1, myDN_2] self.assertEqual( sorted(myD.get_open_nodes('tuples')), sorted([(3, 3), (4, 3)])) """get the node them self """ self.assertEqual( sorted(myD.get_open_nodes()), sorted([myDN_1, myDN_2])) """get the node tuples of closed list """ myD.closed_nodes_list[0:0] = [myDN_3, myDN_4] self.assertEqual( sorted(myD.get_closed_nodes('tuples')), sorted([(5, 5), (5, 6)]))
def test_dijsktra_step_internals(self): """ Test for dijkstra's results after the first step """ """test if the start point is added to the open node list""" myFlaeche = main.Flaeche(xdim=300, ydim=300, scale=10) myD_step_zero = Dijkstra(myFlaeche, (0, 0), (20, 10)) myD_step_zero.step() self.assertEqual(myD_step_zero.get_open_nodes('tuples'), [(0, 0)]) self.assertEqual(myD_step_zero.get_closed_nodes('tuples'), []) """ test if nodes are added to the closed list """ myFlaeche = main.Flaeche(xdim=300, ydim=300, scale=10) myD = Dijkstra(myFlaeche, (0, 0), (20, 10)) myD.step() myD.step(visual=False) self.assertEqual( myD.get_open_nodes('tuples'), [(0, 1), (1, 0), (1, 1)]) self.assertEqual(myD.get_closed_nodes('tuples'), [(0, 0)]) """test that nodes in the closed nodes list are omitted""" myD_fake_closed = Dijkstra(myFlaeche, (0, 0), (20, 10)) myDN_1 = StarNode(xx=0, yy=0, tt=4, dd=5, lastNode=None) myDN_2 = StarNode(xx=1, yy=1, tt=4, dd=5, lastNode=None) myD_fake_closed.open_nodes_list.append(myDN_1) myD_fake_closed.closed_nodes_list.append(myDN_2) # should find myDN_2 as suspicious node # and reject as it alrerady is in closed node list myD_fake_closed.step() self.assertEqual( myD_fake_closed.get_open_nodes('tuples'), [(0, 1), (1, 0)]) """test that nodes in the open lists are updated""" myD_fake_open = Dijkstra(myFlaeche, (0, 0), (20, 10)) myDN_0 = StarNode(xx=1, yy=1, tt=400, dd=500, lastNode=None) myDN_1 = StarNode(xx=0, yy=0, tt=4, dd=5, lastNode=None) myD_fake_open.open_nodes_list.append(myDN_0) myD_fake_open.open_nodes_list.append(myDN_1) # should now take myDN_1 as next node # and finding a shorter path to myDN_0 # and should update the open list after the step self.assertEqual( sorted(myD_fake_open.get_open_nodes('tuples')), [(0, 0), (1, 1)]) long_way = DNList(myD_fake_open.open_nodes_list).get_by_tuple( (1, 1)).full_costs """test the unfished return value""" self.assertFalse(myD_fake_open.step()) short_way = DNList(myD_fake_open.open_nodes_list).get_by_tuple( (1, 1)).full_costs self.assertGreater(long_way, short_way) """test that the algo stops if the end is reached - manipulated lists""" myD_fake_end = Dijkstra(myFlaeche, (0, 0), (20, 10)) myDN_1 = StarNode(xx=20, yy=10, tt=4, dd=0, lastNode=None) myDN_2 = StarNode(xx=12, yy=10, tt=4, dd=7, lastNode=None) # dest point in open and the shortest myD_fake_end.open_nodes_list.append(myDN_1) myD_fake_end.open_nodes_list.append(myDN_2) # some point the longest self.assertTrue(myD_fake_end.step())