Viewport { public boolean contains(int x, int y) { return x >= this.x && x < this.x + this.width && y >= this.y && y < this.y + this.height; } Viewport();  Viewport(int x, int y, int width, int height);  Viewport(Viewport viewport); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); Viewport set(int x, int y, int width, int height); Viewport set(Viewport viewport); Viewport setEmpty(); boolean isEmpty(); boolean intersects(int x, int y, int width, int height); @SuppressWarnings("UnnecessaryLocalVariable") boolean intersects(Viewport viewport); boolean intersect(int x, int y, int width, int height); @SuppressWarnings("UnnecessaryLocalVariable") boolean intersect(Viewport viewport); boolean contains(int x, int y); public int x; public int y; public int width; public int height; }
@Test public void testContains() throws Exception { Viewport viewport = new Viewport(1, 2, 3, 4); assertTrue("contains x, y", viewport.contains(viewport.x, viewport.y)); assertTrue("contains x+width-1, y+height-1", viewport.contains(viewport.x + viewport.width - 1, viewport.y + viewport.height - 1)); assertFalse("does not contain x+width, y+height", viewport.contains(viewport.x + viewport.width, viewport.y + viewport.height)); assertFalse("does not contain x-1, y", viewport.contains(viewport.x - 1, viewport.y)); assertFalse("does not contain x, y-1", viewport.contains(viewport.x, viewport.y - 1)); }
@Test public void testContains_Empty() throws Exception { Viewport empty = new Viewport(1, 2, 0, 0); Viewport emptyWidth = new Viewport(1, 2, 3, 0); Viewport emptyHeight = new Viewport(1, 2, 0, 3); assertFalse("empty does not contain x, y", empty.contains(empty.x, empty.y)); assertFalse("empty width not contain x, y", emptyWidth.contains(emptyWidth.x, emptyWidth.y)); assertFalse("empty width not contain x, y", emptyHeight.contains(emptyHeight.x, emptyHeight.y)); }