Beispiel #1
0
    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)
Beispiel #2
0
    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)))
Beispiel #3
0
    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, )))
Beispiel #4
0
    def test_store_and_retrieve_in_3d_grid(self):
        grid = MultiDimensionalGrid(grid_shape=(2, 4, 3))
        pos = (1, 2, 2)

        item = 35
        self.assertEqual(0, grid.get_item(pos))
        grid.put_item(pos, item)
        self.assertEqual(item, grid.get_item(pos))
Beispiel #5
0
    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)
Beispiel #6
0
    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)))
Beispiel #7
0
 def setUp(self):
     self.grid = MultiDimensionalGrid(grid_shape=(4, 2))
Beispiel #8
0
    def test_1d(self):
        grid = MultiDimensionalGrid(grid_shape=(3, ))
        grid.set_grid([1, 2, 3])

        self.assertEqual(2, grid.get_item((1, )))
Beispiel #9
0
 def test_for_2d_grid(self):
     grid = MultiDimensionalGrid(grid_shape=(2, 3))
     all_positions = list(grid.get_positions())
     expected = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)]
     self.assertEqual(expected, all_positions)
Beispiel #10
0
 def test_for_1d_grid(self):
     grid = MultiDimensionalGrid(grid_shape=(3, ))
     all_positions = list(grid.get_positions())
     self.assertEqual([(0, ), (1, ), (2, )], all_positions)
Beispiel #11
0
    def test_filling_10d_grid_and_retrieving_all_entries_back(self):
        shape = tuple([2] * 10)
        grid = MultiDimensionalGrid(shape)
        a = np.arange(2**10).reshape(shape).tolist()

        self.assert_retrieved_items_match_stored_ones(grid, a, shape)
Beispiel #12
0
    def test_store_and_retrieve_in_3d_grid_after_initialization(self):
        grid = MultiDimensionalGrid(grid_shape=(2, 4, 3))
        pos = (1, 2, 2)

        self.assertEqual(0, grid.get_item(pos))
Beispiel #13
0
    def test_get_tensor_after_initialization_returns_zeros(self):
        self.grid = MultiDimensionalGrid(grid_shape=(2, ))

        self.assertEqual(0, self.grid.get_item((0, )))