Пример #1
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))
Пример #2
0
class StoringTests(TestCase):
    def assert_retrieved_items_match_stored_ones(self, grid, a, shape):
        for position in grid.get_positions():
            inner_list = get_inner_most_list(a, position)
            item = inner_list[position[-1]]
            grid.put_item(position, item)

        for position in grid.get_positions():
            inner_list = get_inner_most_list(a, position)
            expected_item = inner_list[position[-1]]
            item = grid.get_item(position)
            self.assertEqual(expected_item, item)

    def setUp(self):
        self.grid = MultiDimensionalGrid(grid_shape=(4, 2))

    def test_store_and_retrieve_item(self):
        position = (2, 1)

        t = 2

        self.grid.put_item(position, t)

        actual = self.grid.get_item(position)
        self.assertEqual(t, actual)

    def test_store_and_retrieve_two_items(self):
        pos1 = (2, 1)
        pos2 = (1, 0)

        t1 = 4
        t2 = 7

        self.grid.put_item(pos1, t1)
        self.grid.put_item(pos2, t2)

        actual = self.grid.get_item(pos1)
        self.assertEqual(t1, actual)

        actual = self.grid.get_item(pos2)
        self.assertEqual(t2, actual)

    def test_filling_2d_grid_completely_and_retrieving_all_entries(self):
        a = np.arange(4 * 2).reshape(4, 2)
        self.assert_retrieved_items_match_stored_ones(self.grid, a, (4, 2))

    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))

    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)