### Question:
TextureAtlasGenerator { @Nullable public Result addImage(final int imageWidth, final int imageHeight, @Nonnull final String imageName) { if (imageWidth < 0) { throw new IllegalArgumentException("image width must be non-negative"); } else if (imageHeight < 0) { throw new IllegalArgumentException("image height must be non-negative"); } if (! shouldAddImage(imageWidth, imageHeight)) { return null; } Node node = root.insert(imageWidth, imageHeight, atlasPadding); if (node == null) { return null; } rectangleMap.put(imageName, node); return new Result(node.rect.x, node.rect.y, imageWidth, imageHeight); } TextureAtlasGenerator(final int atlasWidth,
                               final int atlasHeight,
                               final int atlasPadding,
                               final float atlasTolerance); @Nullable Result addImage(final int imageWidth, final int imageHeight, @Nonnull final String imageName); boolean shouldAddImage(final int imageWidth, final int imageHeight); @Nullable Result removeImage(@Nonnull final String name); int getAtlasWidth(); int getAtlasHeight(); @Nonnull List<Result> rebuild(
      final int width,
      final int height); void reset();  }### Answer:
@Test public void testAddingValidImageReturnsValidResult() { Result result = GENERATOR.addImage(30, 30, "image"); assertResult(0, 0, 30, 30, result); }
@Test public void testAddingTwoValidImagesReturnsValidResultForSecondImage() { GENERATOR.addImage(5, 5, "image-1"); Result result = GENERATOR.addImage(30, 20, "image-2"); assertResult(0, 10, 30, 20, result); }
@Test public void testAddingThreeValidImagesReturnsValidResultForThirdImage() { GENERATOR.addImage(5, 5, "image-1"); GENERATOR.addImage(30, 20, "image-2"); Result result = GENERATOR.addImage(90, 1, "image-3"); assertResult(10, 0, 90, 1, result); }
@Test public void testAddingImageWiderAndTallerThanAtlasReturnsNull() { assertNull(GENERATOR.addImage(101, 101, "image")); }
@Test public void testAddingImageOnlyWiderThanAtlasReturnsNull() { assertNull(GENERATOR.addImage(101, 1, "image")); }
@Test public void testAddingImageOnlyTallerThanAtlasReturnsNull() { assertNull(GENERATOR.addImage(1, 101, "image")); }
@Test public void testAddingImageOnlyWiderThanAtlasWithPaddingReturnsNull() { assertNull(GENERATOR.addImage(96, 1, "image")); }
@Test public void testAddingImageOnlyTallerThanAtlasWithPaddingReturnsNull() { assertNull(GENERATOR.addImage(1, 96, "image")); }
@Test public void testAddingImageWiderAndTallerThanAtlasWithPaddingReturnsNull() { assertNull(GENERATOR.addImage(96, 96, "image")); }
@Test public void testAddingImageThatCouldFitInAtlasButNotWithinToleranceReturnsNull() { assertNull(GENERATOR.addImage(50, 50, "image")); }