Array2D { public T get(int x, int y) { if (x >= width || y >= height || x < 0 || y < 0) { throw new IndexOutOfBoundsException(); } return arr.get(y * width + x); } Array2D(int width, int height); void initialise(int x, int y, T val); T get(int x, int y); void set(int x, int y, T val); int getWidth(); int getHeight(); @SuppressWarnings("unchecked") void setDimensions(int width, int height);  }
@Test public void testGet() { assertEquals((Integer) 2902, arr.get(2, 29)); assertEquals((Integer) 1416, arr.get(16, 14)); assertEquals((Integer) 305, arr.get(5, 3)); assertEquals((Integer) 0, arr.get(0, 0)); assertEquals((Integer) 2900, arr.get(0, arr.getHeight() - 1)); assertEquals((Integer) 29, arr.get(arr.getWidth() - 1, 0)); assertEquals((Integer) 2929, arr.get(arr.getWidth() - 1, arr.getHeight() - 1)); }
@Test(expected = IndexOutOfBoundsException.class) public void testGetFail() { arr.get(40, 50); }