Level extends ArrayList<Placement> { public void validate() { for(int i = 0; i < size(); i++) { for(int j = 0; j < size(); j++) { if(j == i) { if(!get(i).intersects(get(j))) { throw new IllegalArgumentException(); } } else { if(get(i).intersects(get(j))) { throw new IllegalArgumentException(i + " vs " + j + ": " + get(i) + " vs " + get(j)); } } } } }  int getHeight(); int getWeight(); void validate();  }
@Test void testValidator() { Level level = new Level(); Placement a = new Placement(new Space(1, 1, 1, 0, 0, 0), new Box(1, 1, 1, 0)); level.add(a); Placement b = new Placement(new Space(1, 1, 1, 1, 0, 0), new Box(1, 1, 1, 0)); level.add(b); level.validate(); }
@Test void testValidatorThrowsException() { Level level = new Level(); Placement a = new Placement(new Space(1, 1, 1, 0, 0, 0), new Box(2, 1, 1, 0)); level.add(a); Placement b = new Placement(new Space(1, 1, 1, 1, 0, 0), new Box(1, 1, 1, 0)); level.add(b); assertThrows(IllegalArgumentException.class, () -> { level.validate(); }); }