def test_retrieve_from_10d_grid(self): shape = tuple([2] * 10) grid = MultiDimensionalGrid(grid_shape=shape) a = np.arange(2**10).reshape(shape).tolist() grid.set_grid(a) self.assert_all_retrievals_are_correct(grid, a, shape)
def test_retrieve_from_2d_grid(self): grid = MultiDimensionalGrid(grid_shape=(2, 3)) a = [[1, 2, 3], [4, 5, 6]] grid.set_grid(a) self.assertEqual(4, grid.get_item((1, 0))) self.assertEqual(3, grid.get_item((0, 2)))
def test_all_retrievals_from_1d_grid_return_correct_items(self): grid = MultiDimensionalGrid(grid_shape=(3, )) a = [1, 2, 3] grid.set_grid(a) for i in range(3): self.assertEqual(a[i], grid.get_item((i, )))
def test_all_retrievals_from_3d_grid_return_correct_items(self): shape = (5, 3, 2) grid = MultiDimensionalGrid(grid_shape=shape) a = np.arange(5 * 3 * 2).reshape(shape).tolist() grid.set_grid(a) self.assert_all_retrievals_are_correct(grid, a, shape)
def test_all_retrievals_from_2d_grid_return_correct_items(self): grid = MultiDimensionalGrid(grid_shape=(2, 3)) a = [[1, 2, 3], [4, 5, 6]] grid.set_grid(a) for i in range(2): for j in range(3): self.assertEqual(a[i][j], grid.get_item((i, j)))
def test_1d(self): grid = MultiDimensionalGrid(grid_shape=(3, )) grid.set_grid([1, 2, 3]) self.assertEqual(2, grid.get_item((1, )))