Skip to content

Instantly share code, notes, and snippets.

@tobyweston
Created August 9, 2013 09:41
Show Gist options
  • Save tobyweston/6192446 to your computer and use it in GitHub Desktop.
Save tobyweston/6192446 to your computer and use it in GitHub Desktop.
Work out the size of a grid required to display n tiles whilst keeping some sort of visual balance. The physical dimensions of the display region and tiles are unimportant.
@Test
public void nTilesRequireGridToDisplay() {
assertThat(tiles(1), requiresGridOf(1, 1));
assertThat(tiles(2), requiresGridOf(1, 2));
assertThat(tiles(3), requiresGridOf(2, 3));
assertThat(tiles(4), requiresGridOf(2, 4));
assertThat(tiles(5), requiresGridOf(2, 3));
assertThat(tiles(6), requiresGridOf(2, 3));
assertThat(tiles(7), requiresGridOf(3, 3));
assertThat(tiles(8), requiresGridOf(3, 3));
assertThat(tiles(9), requiresGridOf(3, 3));
assertThat(tiles(10), requiresGridOf(3, 4));
assertThat(tiles(11), requiresGridOf(3, 4));
assertThat(tiles(12), requiresGridOf(3, 4));
assertThat(tiles(13), requiresGridOf(4, 4));
assertThat(tiles(14), requiresGridOf(4, 4));
assertThat(tiles(15), requiresGridOf(4, 4));
assertThat(tiles(16), requiresGridOf(4, 4));
}
@tobyweston
Copy link
Author

mistake in the above;

    assertThat(tiles(3), requiresGridOf(2, 2));
    assertThat(tiles(4), requiresGridOf(2, 2));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment