def test_get_direction_symmetric(self): """ Test that the distance between two points is symmetric. """ viz = drawable.Drawable(plt.figure(figsize=(10, 5))) graph = Graph(viz) self.assertEqual(round(graph._get_distance((-1, -1), (0, 0)), 5), round(graph._get_distance((0, 0), (-1, -1)), 5)) self.assertEqual(round(graph._get_distance((-2, -1), (0, 0)), 5), round(graph._get_distance((0, 0), (-2, -1)), 5))
def test_get_direction_negative(self): """ Test getting the distance between two points. """ viz = drawable.Drawable(plt.figure(figsize=(10, 5))) graph = Graph(viz) self.assertEqual(round(math.sqrt(2), 5), round(graph._get_distance((0, 0), (-1, -1)), 5)) self.assertEqual(round(math.sqrt(5), 5), round(graph._get_distance((0, 0), (-2, -1)), 5)) self.assertEqual(1, round(graph._get_distance((-1, -2), (-1, -1)), 5)) self.assertEqual(round(math.sqrt(2), 5), round(graph._get_distance((-3, -2), (-2, -1)), 5))
def test_get_direction_same_y(self): """ Test that when getting the distance between two points with the same y-coordinate, the x-distance is returned. """ viz = drawable.Drawable(plt.figure(figsize=(10, 5))) graph = Graph(viz) self.assertEqual(1, round(graph._get_distance((0, 0), (1, 0)), 5))
def test_get_distance_same(self): """ Test that when getting the distance between the same point, 0 is returned. """ viz = drawable.Drawable(plt.figure(figsize=(10, 5))) graph = Graph(viz) self.assertEqual(0, round(graph._get_distance((1, 1), (1, 1)), 5))