def test_get_direction_negative(self): """ Test getting the direction between two points. """ viz = drawable.Drawable(plt.figure(figsize=(10, 5))) graph = Graph(viz) self.assertEqual((-1 / math.sqrt(2), -1 / math.sqrt(2)), graph._get_direction((0, 0), (-1, -1))) self.assertEqual((-2 / math.sqrt(5), -1 / math.sqrt(5)), graph._get_direction((0, 0), (-2, -1))) self.assertEqual((0, 1), graph._get_direction((-1, -2), (-1, -1))) self.assertEqual((1 / math.sqrt(2), 1 / math.sqrt(2)), graph._get_direction((-3, -2), (-2, -1)))
def test_get_direction_not_symmetric(self): """ Test that the direction between two points is not symmetric. """ viz = drawable.Drawable(plt.figure(figsize=(10, 5))) graph = Graph(viz) self.assertEqual((1 / math.sqrt(2), 1 / math.sqrt(2)), graph._get_direction((-1, -1), (0, 0))) self.assertEqual((-1 / math.sqrt(2), -1 / math.sqrt(2)), graph._get_direction((0, 0), (-1, -1))) self.assertEqual((2 / math.sqrt(5), 1 / math.sqrt(5)), graph._get_direction((-2, -1), (0, 0))) self.assertEqual((-2 / math.sqrt(5), -1 / math.sqrt(5)), graph._get_direction((0, 0), (-2, -1)))
def test_get_direction_same_y_normalized(self): """ Test that when getting the direction between two points with the same y-coordinate, the normalized x-direction is returned. """ viz = drawable.Drawable(plt.figure(figsize=(10, 5))) graph = Graph(viz) self.assertEqual((1, 0), graph._get_direction((0, 0), (2, 0)))
def test_get_direction_same(self): """ Test that when getting the direction between the same point, a zero tuple is returned. """ viz = drawable.Drawable(plt.figure(figsize=(10, 5))) graph = Graph(viz) self.assertEqual((0, 0), graph._get_direction((1, 1), (1, 1)))