def test_key_not_in_trajectory(self):
     """Test: Expection risen when a key is not in the trajectory.
 """
     first = {
         'obses': [[0] * 16] * 10,
         'acts': [[2] * 2] * 10,
     }
     second = {
         'obses': [[1] * 16] * 10,
         'next_obses': [[2] * 16] * 10,
     }
     with self.assertRaises(ValueError):
         compare_trajectories(first, second)
 def test_compare_trajectories_different_dimensions(self):
     """Test: Calculates the norm between two trajectories of different lengths.
 """
     first = {
         'obses': [[1] * 16] * 10,
         'next_obses': [[2] * 16] * 10,
         'acts': [[4] * 2] * 10,
     }
     second = {
         'obses': [[0] * 16] * 8,
         'next_obses': [[1] * 16] * 8,
         'acts': [[2] * 2] * 8,
     }
     distances = [
         compare_trajectories(first, second),
         compare_trajectories(second, first)
     ]
     self.assertAlmostEqual(distances[0], distances[1])
     self.assertAlmostEqual(distances[0]['obses'], 8.0)
     self.assertAlmostEqual(distances[0]['next_obses'], 12.0)
     self.assertAlmostEqual(distances[0]['acts'],
                            math.sqrt(32) + math.sqrt(8))
 def test_compare_same_trajectories(self):
     """Test: Calculates the norm between two equal trajectories except one is longer.
 """
     first = {
         'obses': [[1] * 16] * 10,
         'next_obses': [[2] * 16] * 10,
         'acts': [[4] * 2] * 10,
     }
     second = {
         'obses': [[1] * 16] * 8,
         'next_obses': [[2] * 16] * 8,
         'acts': [[4] * 2] * 8,
     }
     distances = compare_trajectories(first, second)
     self.assertAlmostEqual(distances['obses'], 4.0)
     self.assertAlmostEqual(distances['next_obses'], 8.0)
     self.assertAlmostEqual(distances['acts'], math.sqrt(32))
 def test_compare_same_trajectories(self):
     """Test: Calculates the norm between two equal trajectories.
 """
     first = {
         'obses': [[1] * 16] * 10,
         'next_obses': [[2] * 16] * 10,
         'acts': [[4] * 2] * 10,
     }
     second = {
         'obses': [[1] * 16] * 10,
         'next_obses': [[2] * 16] * 10,
         'acts': [[4] * 2] * 10,
     }
     distances = compare_trajectories(first, second)
     self.assertAlmostEqual(distances['obses'], 0.0)
     self.assertAlmostEqual(distances['next_obses'], 0.0)
     self.assertAlmostEqual(distances['acts'], 0)
 def test_compare_trajectories_same_dimensions(self):
     """Test: Calculates the norm between two trajectories of the same length.
 """
     first = {
         'obses': [[1] * 16] * 10,
         'next_obses': [[2] * 16] * 10,
         'acts': [[4] * 2] * 10,
     }
     second = {
         'obses': [[0] * 16] * 10,
         'next_obses': [[1] * 16] * 10,
         'acts': [[2] * 2] * 10,
     }
     distances = compare_trajectories(first, second)
     self.assertAlmostEqual(distances['obses'], 4.0)
     self.assertAlmostEqual(distances['next_obses'], 4.0)
     self.assertAlmostEqual(distances['acts'], math.sqrt(8))