method2testcases stringlengths 118 3.08k |
|---|
### Question:
Medias { public static synchronized List<Media> getByExtension(String extension, Media folder) { Check.notNull(extension); Check.notNull(folder); if (!loader.isPresent()) { return getFilesByExtension(folder, extension); } final File jar = getJarResources(); final String prefix = getJarResourcesPrefix(); final String fullPath = Medias.create(prefix, folder.getPath()).getPath(); final int prefixLength = prefix.length() + 1; return getByExtension(jar, fullPath, prefixLength, extension); } private Medias(); static synchronized Media create(String... path); static synchronized void setFactoryMedia(FactoryMedia factoryMedia); static synchronized void setResourcesDirectory(String directory); static synchronized void setLoadFromJar(Class<?> clazz); static synchronized Media get(File file); static synchronized List<Media> getByExtension(String extension, Media folder); static List<Media> getByExtension(File jar, String fullPath, int prefixLength, String extension); static Media getWithSuffix(Media media, String suffix); static synchronized String getResourcesDirectory(); static synchronized Optional<Class<?>> getResourcesLoader(); static synchronized File getJarResources(); static synchronized String getJarResourcesPrefix(); static String getSeparator(); }### Answer:
@Test void testGetByExtension() { Medias.setLoadFromJar(MediasTest.class); final Collection<Media> medias = Medias.getByExtension("png", Medias.create("")); assertEquals("image.png", medias.iterator().next().getPath()); } |
### Question:
Medias { public static synchronized Media create(String... path) { if (loader.isPresent()) { return factoryMedia.create(SEPARATOR, loader.get(), path); } return factoryMedia.create(SEPARATOR, resourcesDir, path); } private Medias(); static synchronized Media create(String... path); static synchronized void setFactoryMedia(FactoryMedia factoryMedia); static synchronized void setResourcesDirectory(String directory); static synchronized void setLoadFromJar(Class<?> clazz); static synchronized Media get(File file); static synchronized List<Media> getByExtension(String extension, Media folder); static List<Media> getByExtension(File jar, String fullPath, int prefixLength, String extension); static Media getWithSuffix(Media media, String suffix); static synchronized String getResourcesDirectory(); static synchronized Optional<Class<?>> getResourcesLoader(); static synchronized File getJarResources(); static synchronized String getJarResourcesPrefix(); static String getSeparator(); }### Answer:
@Test void testGetMediasOnFile() { assertThrows(() -> Medias.create("image.png").getMedias(), "[image.png] " + MediaDefault.ERROR_PATH_DIR); } |
### Question:
Medias { public static String getSeparator() { return SEPARATOR; } private Medias(); static synchronized Media create(String... path); static synchronized void setFactoryMedia(FactoryMedia factoryMedia); static synchronized void setResourcesDirectory(String directory); static synchronized void setLoadFromJar(Class<?> clazz); static synchronized Media get(File file); static synchronized List<Media> getByExtension(String extension, Media folder); static List<Media> getByExtension(File jar, String fullPath, int prefixLength, String extension); static Media getWithSuffix(Media media, String suffix); static synchronized String getResourcesDirectory(); static synchronized Optional<Class<?>> getResourcesLoader(); static synchronized File getJarResources(); static synchronized String getJarResourcesPrefix(); static String getSeparator(); }### Answer:
@Test void testSeparator() { assertEquals(Constant.SLASH, Medias.getSeparator()); } |
### Question:
ResourceLoader { public ResourceLoader() { super(); } ResourceLoader(); synchronized void add(T key, Resource resource); synchronized void start(); synchronized void await(); synchronized Map<T, Resource> get(); boolean isFinished(); }### Answer:
@Test void testResourceLoader() { final ResourceLoader<Type> resourceLoader = new ResourceLoader<>(); final Image resource = Drawable.loadImage(Medias.create("image.png")); resourceLoader.add(Type.TEST, resource); assertFalse(resource.isLoaded()); assertNull(resource.getSurface()); assertFalse(resourceLoader.isFinished()); resourceLoader.start(); resourceLoader.await(); assertTrue(resource.isLoaded()); assertNotNull(resource.getSurface()); assertTrue(resourceLoader.isFinished()); assertEquals(resourceLoader.get().get(Type.TEST), resource); } |
### Question:
ResourceLoader { public synchronized void start() { if (started.get()) { throw new LionEngineException(ERROR_STARTED); } started.set(true); thread.start(); } ResourceLoader(); synchronized void add(T key, Resource resource); synchronized void start(); synchronized void await(); synchronized Map<T, Resource> get(); boolean isFinished(); }### Answer:
@Test void testAlreadyStarted() { final ResourceLoader<Type> resourceLoader = new ResourceLoader<>(); resourceLoader.start(); assertThrows(() -> resourceLoader.start(), ResourceLoader.ERROR_STARTED); } |
### Question:
ResourceLoader { public synchronized Map<T, Resource> get() { if (!done.get()) { throw new LionEngineException(ERROR_NOT_FINISHED); } return Collections.unmodifiableMap(resources); } ResourceLoader(); synchronized void add(T key, Resource resource); synchronized void start(); synchronized void await(); synchronized Map<T, Resource> get(); boolean isFinished(); }### Answer:
@Test void testNotStartedGet() { final ResourceLoader<Type> resourceLoader = new ResourceLoader<>(); assertThrows(() -> resourceLoader.get(), ResourceLoader.ERROR_NOT_FINISHED); } |
### Question:
ResourceLoader { public synchronized void await() { if (!started.get()) { throw new LionEngineException(ERROR_NOT_STARTED); } try { thread.join(); } catch (final InterruptedException exception) { Thread.currentThread().interrupt(); throw new LionEngineException(exception, ERROR_SKIPPED); } finally { done.set(true); } } ResourceLoader(); synchronized void add(T key, Resource resource); synchronized void start(); synchronized void await(); synchronized Map<T, Resource> get(); boolean isFinished(); }### Answer:
@Test void testNotStartedAwait() { final ResourceLoader<Type> resourceLoader = new ResourceLoader<>(); assertThrows(() -> resourceLoader.await(), ResourceLoader.ERROR_NOT_STARTED); } |
### Question:
UtilFolder { public static String getPath(String... path) { return getPathSeparator(Constant.SLASH, path); } private UtilFolder(); static List<File> getDirectories(File path); static String getPath(String... path); static String getPathSeparator(String separator, String... path); static void deleteDirectory(File element); static boolean isDirectory(String path); }### Answer:
@Test void testGetPath() { assertEquals("a" + Constant.SLASH + "b" + Constant.SLASH + "c", UtilFolder.getPath("a", "b", "c")); } |
### Question:
UtilFolder { public static String getPathSeparator(String separator, String... path) { Check.notNull(separator); Check.notNull(path); final StringBuilder fullPath = new StringBuilder(path.length); for (int i = 0; i < path.length; i++) { if (i == path.length - 1) { fullPath.append(path[i]); } else if (path[i] != null && path[i].length() > 0) { fullPath.append(path[i]); if (!fullPath.substring(fullPath.length() - 1, fullPath.length()).equals(separator)) { fullPath.append(separator); } } } return fullPath.toString(); } private UtilFolder(); static List<File> getDirectories(File path); static String getPath(String... path); static String getPathSeparator(String separator, String... path); static void deleteDirectory(File element); static boolean isDirectory(String path); }### Answer:
@Test void testGetPathSeparator() { assertEquals("this%path%next", UtilFolder.getPathSeparator("%", "this", "path", "next")); assertEquals("this%path%next", UtilFolder.getPathSeparator("%", "this%", "path%", "next")); assertEquals("this%path%", UtilFolder.getPathSeparator("%", "this%", "path%", null, "")); } |
### Question:
UtilFolder { public static List<File> getDirectories(File path) { Check.notNull(path); return Optional.ofNullable(path.listFiles()) .map(files -> Arrays.asList(files) .stream() .filter(File::isDirectory) .collect(Collectors.toList())) .orElseGet(Collections::emptyList); } private UtilFolder(); static List<File> getDirectories(File path); static String getPath(String... path); static String getPathSeparator(String separator, String... path); static void deleteDirectory(File element); static boolean isDirectory(String path); }### Answer:
@Test void testGetDirectories() throws IOException { final Path dir = Files.createTempDirectory("temp"); final Path file = Files.createTempFile(dir, "temp", ".tmp"); final List<File> expected = new ArrayList<>(); for (int i = 0; i < 5; i++) { expected.add(Files.createTempDirectory(dir, "temp").toFile()); } Collections.sort(expected); final List<File> found = UtilFolder.getDirectories(dir.toFile()); Collections.sort(found); assertEquals(expected, found); Files.delete(file); for (final File current : expected) { assertTrue(current.delete()); } Files.delete(dir); }
@Test void testGetDirectoriesError() { assertTrue(UtilFolder.getDirectories(new File("null")).isEmpty()); } |
### Question:
UtilFolder { public static boolean isDirectory(String path) { return path != null && new File(path).isDirectory(); } private UtilFolder(); static List<File> getDirectories(File path); static String getPath(String... path); static String getPathSeparator(String separator, String... path); static void deleteDirectory(File element); static boolean isDirectory(String path); }### Answer:
@Test void testIsDirectory() throws IOException { assertFalse(UtilFolder.isDirectory(null)); final Path dir = Files.createTempDirectory("temp"); assertTrue(UtilFolder.isDirectory(dir.toFile().getPath())); Files.delete(dir); assertFalse(UtilFolder.isDirectory(dir.toFile().getPath())); } |
### Question:
Version { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final Version other = (Version) object; return major == other.major && minor == other.minor && micro == other.micro; } private Version(int major, int minor, int micro); static Version create(int major, int minor, int micro); int getMajor(); int getMinor(); int getMicro(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final Version DEFAULT; }### Answer:
@Test void testEquals() { final Version version = Version.create(3, 2, 1); assertEquals(version, version); assertEquals(version, Version.create(3, 2, 1)); assertNotEquals(version, null); assertNotEquals(version, new Object()); assertNotEquals(version, Version.create(3, 2, 0)); assertNotEquals(version, Version.create(3, 0, 1)); assertNotEquals(version, Version.create(0, 2, 1)); assertNotEquals(version, Version.create(3, 0, 0)); assertNotEquals(version, Version.create(0, 0, 1)); assertNotEquals(version, Version.create(0, 0, 0)); } |
### Question:
Version { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + major; result = prime * result + minor; result = prime * result + micro; return result; } private Version(int major, int minor, int micro); static Version create(int major, int minor, int micro); int getMajor(); int getMinor(); int getMicro(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final Version DEFAULT; }### Answer:
@Test void testHashCode() { final Version version = Version.create(3, 2, 1); assertHashEquals(version, Version.create(3, 2, 1)); assertHashNotEquals(version, new Object()); assertHashNotEquals(version, Version.create(3, 2, 0)); assertHashNotEquals(version, Version.create(3, 0, 1)); assertHashNotEquals(version, Version.create(0, 2, 1)); assertHashNotEquals(version, Version.create(3, 0, 0)); assertHashNotEquals(version, Version.create(0, 0, 1)); assertHashNotEquals(version, Version.create(0, 0, 0)); } |
### Question:
Version { @Override public String toString() { return new StringBuilder(LENGTH).append(major) .append(Constant.DOT) .append(minor) .append(Constant.DOT) .append(micro) .toString(); } private Version(int major, int minor, int micro); static Version create(int major, int minor, int micro); int getMajor(); int getMinor(); int getMicro(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final Version DEFAULT; }### Answer:
@Test void testToString() { assertEquals("3.2.1", Version.create(3, 2, 1).toString()); } |
### Question:
Tick implements Updatable { public void addAction(TickAction action, long tickDelay) { toAdd.add(new TickActionDelayed(action, currentTicks + tickDelay)); } Tick(); void addAction(TickAction action, long tickDelay); void start(); void stop(); void restart(); void pause(); void resume(); boolean elapsed(long tick); boolean elapsedTime(int rate, long milli); long elapsed(); void set(long value); boolean isStarted(); @Override void update(double extrp); }### Answer:
@Test void testAddAction() { final AtomicBoolean action = new AtomicBoolean(); tick.addAction(() -> action.set(true), 2L); assertFalse(action.get()); tick.start(); assertFalse(action.get()); tick.update(1.0); assertFalse(action.get()); tick.update(1.0); assertTrue(action.get()); }
@Test void testAddActionNull() { assertThrows(() -> tick.addAction(null, 0L), Check.ERROR_NULL); } |
### Question:
Tick implements Updatable { public void start() { if (!started) { started = true; updater = updating; } } Tick(); void addAction(TickAction action, long tickDelay); void start(); void stop(); void restart(); void pause(); void resume(); boolean elapsed(long tick); boolean elapsedTime(int rate, long milli); long elapsed(); void set(long value); boolean isStarted(); @Override void update(double extrp); }### Answer:
@Test void testStart() { assertFalse(tick.isStarted()); assertFalse(tick.elapsed(0L)); assertFalse(tick.elapsedTime(0, 0L)); assertFalse(tick.elapsedTime(60, 0L)); assertEquals(0L, tick.elapsed()); tick.start(); assertTrue(tick.isStarted()); assertTrue(tick.elapsed(0L)); assertFalse(tick.elapsedTime(0, 0L)); assertTrue(tick.elapsedTime(60, 0L)); assertEquals(0L, tick.elapsed()); tick.start(); assertTrue(tick.isStarted()); assertFalse(tick.elapsed(1L)); assertFalse(tick.elapsedTime(0, 1L)); assertFalse(tick.elapsedTime(60, 1L)); assertEquals(0L, tick.elapsed()); } |
### Question:
Tick implements Updatable { public void stop() { currentTicks = 0L; started = false; updater = PAUSE; } Tick(); void addAction(TickAction action, long tickDelay); void start(); void stop(); void restart(); void pause(); void resume(); boolean elapsed(long tick); boolean elapsedTime(int rate, long milli); long elapsed(); void set(long value); boolean isStarted(); @Override void update(double extrp); }### Answer:
@Test void testStop() { assertFalse(tick.isStarted()); tick.start(); assertTrue(tick.isStarted()); tick.stop(); assertFalse(tick.isStarted()); assertFalse(tick.elapsed(0L)); assertFalse(tick.elapsedTime(60, 0L)); assertEquals(0L, tick.elapsed()); } |
### Question:
Tick implements Updatable { public void pause() { updater = PAUSE; } Tick(); void addAction(TickAction action, long tickDelay); void start(); void stop(); void restart(); void pause(); void resume(); boolean elapsed(long tick); boolean elapsedTime(int rate, long milli); long elapsed(); void set(long value); boolean isStarted(); @Override void update(double extrp); }### Answer:
@Test void testPause() { assertEquals(0L, tick.elapsed()); assertFalse(tick.elapsed(1L)); assertFalse(tick.elapsedTime(60, 15L)); tick.start(); assertEquals(0L, tick.elapsed()); assertFalse(tick.elapsed(1L)); assertFalse(tick.elapsedTime(60, 15L)); tick.update(1.0); assertEquals(1L, tick.elapsed()); assertTrue(tick.elapsed(1L)); assertTrue(tick.elapsedTime(60, 15L)); tick.pause(); assertEquals(1L, tick.elapsed()); assertTrue(tick.elapsed(1L)); assertTrue(tick.elapsedTime(60, 15L)); tick.update(1.0); assertEquals(1L, tick.elapsed()); assertTrue(tick.elapsed(1L)); assertTrue(tick.elapsedTime(60, 15L)); } |
### Question:
Tick implements Updatable { public void resume() { updater = updating; } Tick(); void addAction(TickAction action, long tickDelay); void start(); void stop(); void restart(); void pause(); void resume(); boolean elapsed(long tick); boolean elapsedTime(int rate, long milli); long elapsed(); void set(long value); boolean isStarted(); @Override void update(double extrp); }### Answer:
@Test void testResume() { tick.start(); tick.pause(); tick.update(1.0); assertEquals(0L, tick.elapsed()); assertFalse(tick.elapsed(1L)); assertFalse(tick.elapsedTime(60, 15L)); tick.resume(); assertEquals(0L, tick.elapsed()); assertFalse(tick.elapsed(1L)); assertFalse(tick.elapsedTime(60, 15L)); tick.update(1.0); assertEquals(1L, tick.elapsed()); assertTrue(tick.elapsed(1L)); assertTrue(tick.elapsedTime(60, 15L)); } |
### Question:
Tick implements Updatable { public void restart() { currentTicks = 0L; started = true; updater = updating; } Tick(); void addAction(TickAction action, long tickDelay); void start(); void stop(); void restart(); void pause(); void resume(); boolean elapsed(long tick); boolean elapsedTime(int rate, long milli); long elapsed(); void set(long value); boolean isStarted(); @Override void update(double extrp); }### Answer:
@Test void testRestart() { assertFalse(tick.isStarted()); tick.restart(); assertTrue(tick.isStarted()); assertEquals(0L, tick.elapsed()); assertFalse(tick.elapsed(1L)); assertFalse(tick.elapsedTime(60, 15L)); tick.restart(); assertTrue(tick.isStarted()); assertEquals(0L, tick.elapsed()); assertFalse(tick.elapsed(1L)); assertFalse(tick.elapsedTime(60, 15L)); } |
### Question:
Tick implements Updatable { public void set(long value) { currentTicks = value; } Tick(); void addAction(TickAction action, long tickDelay); void start(); void stop(); void restart(); void pause(); void resume(); boolean elapsed(long tick); boolean elapsedTime(int rate, long milli); long elapsed(); void set(long value); boolean isStarted(); @Override void update(double extrp); }### Answer:
@Test void testSet() { assertFalse(tick.isStarted()); assertEquals(0L, tick.elapsed()); assertFalse(tick.elapsed(1L)); assertFalse(tick.elapsedTime(60, 15L)); tick.set(1); assertFalse(tick.isStarted()); assertEquals(1L, tick.elapsed()); assertFalse(tick.elapsed(1L)); assertFalse(tick.elapsedTime(60, 15L)); tick.start(); assertTrue(tick.isStarted()); assertEquals(1L, tick.elapsed()); assertTrue(tick.elapsed(1L)); assertTrue(tick.elapsedTime(60, 15L)); } |
### Question:
Xml extends XmlReader { public void writeString(String attribute, String content) { if (content == null) { write(attribute, NULL); } else { write(attribute, content); } } Xml(Media media); Xml(String name); Xml(Document document, Element root); void save(Media media); Xml createChild(String child); void add(XmlReader node); void setText(String text); void writeBoolean(String attribute, boolean content); void writeByte(String attribute, byte content); void writeShort(String attribute, short content); void writeInteger(String attribute, int content); void writeLong(String attribute, long content); void writeFloat(String attribute, float content); void writeDouble(String attribute, double content); void writeString(String attribute, String content); void removeAttribute(String attribute); void removeChild(String child); void removeChild(Xml child); void removeChildren(String children); Xml getChild(String name); Collection<Xml> getChildren(String name); Collection<Xml> getChildren(); }### Answer:
@Test void testNodeWriteError() { final Xml node = new Xml("test"); assertThrows(() -> node.writeString("%éàç-èyrd", "error"), Xml.ERROR_WRITE_ATTRIBUTE + "%éàç-èyrd" + Xml.ERROR_WRITE_CONTENT + "error"); } |
### Question:
Xml extends XmlReader { void normalize(String expression) { final XPath xPath = XPathFactory.newInstance().newXPath(); try { final NodeList nodeList = (NodeList) xPath.evaluate(expression, document, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); ++i) { final Node node = nodeList.item(i); node.getParentNode().removeChild(node); } } catch (final XPathExpressionException exception) { Verbose.exception(exception); } } Xml(Media media); Xml(String name); Xml(Document document, Element root); void save(Media media); Xml createChild(String child); void add(XmlReader node); void setText(String text); void writeBoolean(String attribute, boolean content); void writeByte(String attribute, byte content); void writeShort(String attribute, short content); void writeInteger(String attribute, int content); void writeLong(String attribute, long content); void writeFloat(String attribute, float content); void writeDouble(String attribute, double content); void writeString(String attribute, String content); void removeAttribute(String attribute); void removeChild(String child); void removeChild(Xml child); void removeChildren(String children); Xml getChild(String name); Collection<Xml> getChildren(String name); Collection<Xml> getChildren(); }### Answer:
@Test void testBadNormalize() { Verbose.info("*********************************** EXPECTED VERBOSE ***********************************"); final Xml node = new Xml("test"); node.normalize("\\ Verbose.info("****************************************************************************************"); } |
### Question:
Rectangle implements Area { public void set(double x, double y, double w, double h) { this.x = x; this.y = y; width = w; height = h; } Rectangle(); Rectangle(double x, double y, double width, double height); void translate(double vx, double vy); void rotate(double angle); void set(double x, double y, double w, double h); double getMinX(); double getMinY(); double getMaxX(); double getMaxY(); @Override boolean intersects(Area area); @Override boolean contains(Area area); @Override boolean contains(double x, double y); @Override double getWidthReal(); @Override double getHeightReal(); @Override double getX(); @Override double getY(); @Override int getWidth(); @Override int getHeight(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testSet() { final Rectangle rectangle = new Rectangle(); rectangle.set(1.0, 2.0, 3.6, 4.6); assertEquals(1.0, rectangle.getX()); assertEquals(2.0, rectangle.getY()); assertEquals(3, rectangle.getWidth()); assertEquals(4, rectangle.getHeight()); assertEquals(3.6, rectangle.getWidthReal()); assertEquals(4.6, rectangle.getHeightReal()); assertEquals(1.0, rectangle.getMinX()); assertEquals(2.0, rectangle.getMinY()); assertEquals(4.6, rectangle.getMaxX()); assertEquals(6.6, rectangle.getMaxY()); } |
### Question:
Rectangle implements Area { public void translate(double vx, double vy) { x += vx; y += vy; } Rectangle(); Rectangle(double x, double y, double width, double height); void translate(double vx, double vy); void rotate(double angle); void set(double x, double y, double w, double h); double getMinX(); double getMinY(); double getMaxX(); double getMaxY(); @Override boolean intersects(Area area); @Override boolean contains(Area area); @Override boolean contains(double x, double y); @Override double getWidthReal(); @Override double getHeightReal(); @Override double getX(); @Override double getY(); @Override int getWidth(); @Override int getHeight(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testTranslate() { final Rectangle rectangle = new Rectangle(1.0, 1.0, 5.0, 5.0); rectangle.translate(1.0, 2.0); assertEquals(2.0, rectangle.getX()); assertEquals(3.0, rectangle.getY()); assertEquals(2.0, rectangle.getMinX()); assertEquals(3.0, rectangle.getMinY()); assertEquals(7.0, rectangle.getMaxX()); assertEquals(8.0, rectangle.getMaxY()); assertEquals(5.0, rectangle.getWidthReal()); assertEquals(5.0, rectangle.getHeightReal()); } |
### Question:
Rectangle implements Area { @Override public String toString() { return new StringBuilder(MIN_LENGHT).append(getClass().getSimpleName()) .append(" [x=") .append(x) .append(", y=") .append(y) .append(", width=") .append(width) .append(", height=") .append(height) .append("]") .toString(); } Rectangle(); Rectangle(double x, double y, double width, double height); void translate(double vx, double vy); void rotate(double angle); void set(double x, double y, double w, double h); double getMinX(); double getMinY(); double getMaxX(); double getMaxY(); @Override boolean intersects(Area area); @Override boolean contains(Area area); @Override boolean contains(double x, double y); @Override double getWidthReal(); @Override double getHeightReal(); @Override double getX(); @Override double getY(); @Override int getWidth(); @Override int getHeight(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testToString() { assertEquals("Rectangle [x=0.0, y=0.0, width=0.0, height=0.0]", new Rectangle().toString()); assertEquals("Rectangle [x=0.0, y=1.0, width=2.0, height=3.0]", new Rectangle(0, 1, 2, 3).toString()); } |
### Question:
Polygon { public void addPoint(double x, double y) { if (npoints >= xpoints.length) { final int newLength = npoints * 2; xpoints = Arrays.copyOf(xpoints, newLength); ypoints = Arrays.copyOf(ypoints, newLength); } xpoints[npoints] = x; ypoints[npoints] = y; npoints++; updateBounds(); } Polygon(); void addPoint(double x, double y); void reset(); Area getArea(); boolean intersects(Area area); boolean contains(Area area); Collection<Line> getPoints(); @Override String toString(); }### Answer:
@Test void testAddPoint() { final Polygon polygon = new Polygon(); assertTrue(polygon.getPoints().isEmpty()); polygon.addPoint(1.0, 2.0); assertTrue(polygon.getPoints().isEmpty()); assertEquals(new Rectangle(0.0, 0.0, 0.0, 0.0), polygon.getArea()); polygon.addPoint(3.0, 4.0); assertEquals(new Line(1.0, 2.0, 3.0, 4.0), polygon.getPoints().iterator().next()); assertEquals(new Rectangle(0.0, 0.0, 0.0, 0.0), polygon.getArea()); polygon.addPoint(-1.0, -2.0); assertEquals(new Line(1.0, 2.0, 3.0, 4.0), polygon.getPoints().iterator().next()); assertEquals(new Rectangle(0.0, 0.0, 0.0, 0.0), polygon.getArea()); polygon.addPoint(-3.0, -4.0); assertEquals(new Rectangle(-3.0, -4.0, 6.0, 8.0), polygon.getArea()); } |
### Question:
Polygon { public void reset() { xpoints = new double[MIN_POINTS]; ypoints = new double[MIN_POINTS]; npoints = 0; bounds.set(0.0, 0.0, 0.0, 0.0); } Polygon(); void addPoint(double x, double y); void reset(); Area getArea(); boolean intersects(Area area); boolean contains(Area area); Collection<Line> getPoints(); @Override String toString(); }### Answer:
@Test void testReset() { final Polygon polygon = new Polygon(); polygon.addPoint(1.0, 2.0); polygon.addPoint(3.0, 4.0); assertFalse(polygon.getPoints().isEmpty()); assertEquals(new Rectangle(0.0, 0.0, 0.0, 0.0), polygon.getArea()); polygon.reset(); assertTrue(polygon.getPoints().isEmpty()); assertEquals(new Rectangle(0.0, 0.0, 0.0, 0.0), polygon.getArea()); } |
### Question:
Polygon { public boolean contains(Area area) { return bounds.contains(area); } Polygon(); void addPoint(double x, double y); void reset(); Area getArea(); boolean intersects(Area area); boolean contains(Area area); Collection<Line> getPoints(); @Override String toString(); }### Answer:
@Test void testContains() { final Polygon polygon = new Polygon(); assertFalse(polygon.contains(null)); assertFalse(polygon.contains(Geom.createArea(1.0, 2.0, 2.0, 2.0))); polygon.addPoint(-1.0, -2.0); polygon.addPoint(-3.0, -4.0); polygon.addPoint(1.0, 2.0); polygon.addPoint(3.0, 4.0); assertFalse(polygon.contains(null)); assertFalse(polygon.contains(Geom.createArea(10.25, 20.25, 0.5, 0.5)), polygon.getArea().toString()); assertTrue(polygon.contains(Geom.createArea(1.25, 2.25, 0.5, 0.5)), polygon.getArea().toString()); } |
### Question:
Polygon { @Override public String toString() { final StringBuilder builder = new StringBuilder(Constant.HUNDRED).append(getClass().getSimpleName()) .append(" ["); for (int i = 0; i < npoints; i++) { builder.append(" p=").append(i + 1).append(" x=").append(xpoints[i]).append(", y=").append(ypoints[i]); } return builder.append("]").toString(); } Polygon(); void addPoint(double x, double y); void reset(); Area getArea(); boolean intersects(Area area); boolean contains(Area area); Collection<Line> getPoints(); @Override String toString(); }### Answer:
@Test void testToString() { final Polygon polygon = new Polygon(); assertEquals("Polygon []", polygon.toString()); polygon.addPoint(1.0, 2.0); assertEquals("Polygon [ p=1 x=1.0, y=2.0]", polygon.toString()); polygon.addPoint(3.0, 4.0); assertEquals("Polygon [ p=1 x=1.0, y=2.0 p=2 x=3.0, y=4.0]", polygon.toString()); } |
### Question:
Geom { public static Localizable createLocalizable(double x, double y) { return new LocalizableImpl(x, y); } private Geom(); static Optional<Coord> intersection(Line l1, Line l2); static Localizable createLocalizable(double x, double y); static Area createArea(double x, double y, double width, double height); static boolean same(Localizable a, Localizable b); }### Answer:
@Test void testCreateLocalizable() { final Localizable localizable = Geom.createLocalizable(1.5, 2.5); assertEquals(1.5, localizable.getX()); assertEquals(2.5, localizable.getY()); }
@Test void testEqualsLocalizable() { final Localizable localizable = Geom.createLocalizable(1.5, 2.5); assertNotEquals(localizable, null); assertNotEquals(localizable, new Object()); assertNotEquals(localizable, Geom.createLocalizable(2.5, 2.5)); assertNotEquals(localizable, Geom.createLocalizable(1.5, 1.5)); assertEquals(localizable, localizable); assertEquals(localizable, Geom.createLocalizable(1.5, 2.5)); assertEquals(Geom.createLocalizable(1.5, 2.5), localizable); assertEquals(Geom.createLocalizable(1.5, 2.5), Geom.createLocalizable(1.5, 2.5)); }
@Test void testHashCodeLocalizable() { final Localizable localizable = Geom.createLocalizable(1.5, 2.5); assertHashNotEquals(localizable, new Object()); assertHashNotEquals(localizable, Geom.createLocalizable(2.5, 2.5)); assertHashNotEquals(localizable, Geom.createLocalizable(1.5, 1.5)); assertHashEquals(localizable, Geom.createLocalizable(1.5, 2.5)); }
@Test void testToStringLocalizable() { assertEquals("LocalizableImpl [x=1.5, y=2.5]", Geom.createLocalizable(1.5, 2.5).toString()); } |
### Question:
Point { public void translate(int vx, int vy) { x += vx; y += vy; } Point(); Point(int x, int y); void translate(int vx, int vy); void set(int x, int y); void setX(int x); void setY(int y); int getX(); int getY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testTranslate() { final Point point = new Point(1, 2); point.translate(10, 20); assertEquals(11, point.getX()); assertEquals(22, point.getY()); } |
### Question:
Point { public void set(int x, int y) { this.x = x; this.y = y; } Point(); Point(int x, int y); void translate(int vx, int vy); void set(int x, int y); void setX(int x); void setY(int y); int getX(); int getY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testSet() { final Point point = new Point(); point.set(10, 20); assertEquals(10, point.getX()); assertEquals(20, point.getY()); } |
### Question:
Point { public void setX(int x) { this.x = x; } Point(); Point(int x, int y); void translate(int vx, int vy); void set(int x, int y); void setX(int x); void setY(int y); int getX(); int getY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testSetX() { final Point point = new Point(1, 2); point.setX(10); assertEquals(10, point.getX()); assertEquals(2, point.getY()); } |
### Question:
Point { public void setY(int y) { this.y = y; } Point(); Point(int x, int y); void translate(int vx, int vy); void set(int x, int y); void setX(int x); void setY(int y); int getX(); int getY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testSetY() { final Point point = new Point(1, 2); point.setY(20); assertEquals(1, point.getX()); assertEquals(20, point.getY()); } |
### Question:
Point { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || getClass() != object.getClass()) { return false; } final Point other = (Point) object; return x == other.x && y == other.y; } Point(); Point(int x, int y); void translate(int vx, int vy); void set(int x, int y); void setX(int x); void setY(int y); int getX(); int getY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testEquals() { final Point point = new Point(); assertEquals(point, point); assertEquals(new Point(), new Point()); assertEquals(new Point(1, 2), new Point(1, 2)); assertNotEquals(new Point(), null); assertNotEquals(new Point(), new Object()); assertNotEquals(new Point(1, 0), new Point(1, 1)); assertNotEquals(new Point(0, 1), new Point(1, 0)); assertNotEquals(new Point(), new Point(1, 1)); } |
### Question:
Point { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + x; result = prime * result + y; return result; } Point(); Point(int x, int y); void translate(int vx, int vy); void set(int x, int y); void setX(int x); void setY(int y); int getX(); int getY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testHashCode() { assertEquals(new Point(1, 2), new Point(1, 2)); assertHashNotEquals(new Point(), new Object()); assertHashNotEquals(new Point(1, 0), new Point(1, 1)); assertHashNotEquals(new Point(0, 1), new Point(1, 0)); assertHashNotEquals(new Point(), new Point(1, 1)); } |
### Question:
Point { @Override public String toString() { return new StringBuilder(MIN_LENGHT).append(getClass().getSimpleName()) .append(" [x=") .append(x) .append(", y=") .append(y) .append("]") .toString(); } Point(); Point(int x, int y); void translate(int vx, int vy); void set(int x, int y); void setX(int x); void setY(int y); int getX(); int getY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testToString() { assertEquals("Point [x=1, y=2]", new Point(1, 2).toString()); } |
### Question:
Line { public void set(double x1, double y1, double x2, double y2) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; } Line(); Line(double x1, double y1, double x2, double y2); void set(double x1, double y1, double x2, double y2); double getX1(); double getX2(); double getY1(); double getY2(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testSet() { final Line line = new Line(); line.set(1.5, 2.5, 3.5, 4.5); assertEquals(1.5, line.getX1()); assertEquals(2.5, line.getY1()); assertEquals(3.5, line.getX2()); assertEquals(4.5, line.getY2()); } |
### Question:
Line { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final Line other = (Line) object; return Double.compare(x1, other.x1) == 0 && Double.compare(y1, other.y1) == 0 && Double.compare(x2, other.x2) == 0 && Double.compare(y2, other.y2) == 0; } Line(); Line(double x1, double y1, double x2, double y2); void set(double x1, double y1, double x2, double y2); double getX1(); double getX2(); double getY1(); double getY2(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testEquals() { final Line coord = new Line(); assertEquals(coord, coord); assertEquals(new Line(), new Line()); assertEquals(new Line(1.5, 2.5, 3.5, 4.5), new Line(1.5, 2.5, 3.5, 4.5)); assertNotEquals(new Line(), null); assertNotEquals(new Line(), new Object()); assertNotEquals(new Line(1.5, 2.5, 3.5, 4.5), new Line(2.5, 2.5, 3.5, 4.5)); assertNotEquals(new Line(1.5, 2.5, 3.5, 4.5), new Line(1.5, 1.5, 3.5, 4.5)); assertNotEquals(new Line(1.5, 2.5, 3.5, 4.5), new Line(1.5, 2.5, 2.5, 4.5)); assertNotEquals(new Line(1.5, 2.5, 3.5, 4.5), new Line(1.5, 2.5, 3.5, 1.5)); } |
### Question:
Check { public static void equality(int a, int b) { if (a != b) { throw new LionEngineException(ERROR_ARGUMENT + String.valueOf(a) + ERROR_EQUALS + String.valueOf(b)); } } private Check(); static void superiorOrEqual(int a, int b); static void superiorOrEqual(double a, double b); static void superiorStrict(int a, int b); static void superiorStrict(double a, double b); static void inferiorOrEqual(int a, int b); static void inferiorOrEqual(double a, double b); static void inferiorStrict(int a, int b); static void inferiorStrict(double a, double b); static void different(int a, int b); static void different(double a, double b); static void equality(int a, int b); static void notNull(Object object); }### Answer:
@Test void testEquality() { Check.equality(Integer.MIN_VALUE, Integer.MIN_VALUE); Check.equality(0, 0); Check.equality(Integer.MAX_VALUE, Integer.MAX_VALUE); }
@Test void testEqualityFail() { assertThrows(() -> Check.equality(Integer.MIN_VALUE, Integer.MAX_VALUE), Check.ERROR_ARGUMENT + Integer.MIN_VALUE + Check.ERROR_EQUALS + Integer.MAX_VALUE); } |
### Question:
Line { @Override public String toString() { return new StringBuilder(MIN_LENGHT).append(getClass().getSimpleName()) .append(" [x1=") .append(x1) .append(", y1=") .append(y1) .append(", x2=") .append(x2) .append(", y2=") .append(y2) .append("]") .toString(); } Line(); Line(double x1, double y1, double x2, double y2); void set(double x1, double y1, double x2, double y2); double getX1(); double getX2(); double getY1(); double getY2(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testToString() { assertEquals("Line [x1=1.5, y1=2.5, x2=3.5, y2=4.5]", new Line(1.5, 2.5, 3.5, 4.5).toString()); } |
### Question:
Coord implements Localizable { public void translate(double vx, double vy) { x += vx; y += vy; } Coord(); Coord(double x, double y); void translate(double vx, double vy); void set(double x, double y); void setX(double x); void setY(double y); @Override double getX(); @Override double getY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testTranslate() { final Coord coord = new Coord(1.5, 2.5); coord.translate(10.25, 20.25); assertEquals(11.75, coord.getX()); assertEquals(22.75, coord.getY()); } |
### Question:
Coord implements Localizable { public void set(double x, double y) { this.x = x; this.y = y; } Coord(); Coord(double x, double y); void translate(double vx, double vy); void set(double x, double y); void setX(double x); void setY(double y); @Override double getX(); @Override double getY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testSet() { final Coord coord = new Coord(); coord.set(10.25, 20.25); assertEquals(10.25, coord.getX()); assertEquals(20.25, coord.getY()); } |
### Question:
Coord implements Localizable { public void setX(double x) { this.x = x; } Coord(); Coord(double x, double y); void translate(double vx, double vy); void set(double x, double y); void setX(double x); void setY(double y); @Override double getX(); @Override double getY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testSetX() { final Coord coord = new Coord(1.5, 2.5); coord.setX(10.25); assertEquals(10.25, coord.getX()); assertEquals(2.5, coord.getY()); } |
### Question:
Coord implements Localizable { public void setY(double y) { this.y = y; } Coord(); Coord(double x, double y); void translate(double vx, double vy); void set(double x, double y); void setX(double x); void setY(double y); @Override double getX(); @Override double getY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testSetY() { final Coord coord = new Coord(1.5, 2.5); coord.setY(20.25); assertEquals(1.5, coord.getX()); assertEquals(20.25, coord.getY()); } |
### Question:
Coord implements Localizable { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final Coord other = (Coord) object; return Double.compare(x, other.x) == 0 && Double.compare(y, other.y) == 0; } Coord(); Coord(double x, double y); void translate(double vx, double vy); void set(double x, double y); void setX(double x); void setY(double y); @Override double getX(); @Override double getY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testEquals() { final Coord coord = new Coord(); assertEquals(coord, coord); assertEquals(new Coord(), new Coord()); assertEquals(new Coord(1.5, 2.5), new Coord(1.5, 2.5)); assertNotEquals(new Coord(), null); assertNotEquals(new Coord(), new Object()); assertNotEquals(new Coord(1.0, 0.0), new Coord(1.0, 1.0)); assertNotEquals(new Coord(0.0, 1.0), new Coord(1.0, 0.0)); assertNotEquals(new Coord(), new Coord(1.0, 1.0)); } |
### Question:
Coord implements Localizable { @Override public int hashCode() { final int prime = 31; int result = 1; long temp; temp = Double.doubleToLongBits(x); result = prime * result + (int) (temp ^ temp >>> 32); temp = Double.doubleToLongBits(y); result = prime * result + (int) (temp ^ temp >>> 32); return result; } Coord(); Coord(double x, double y); void translate(double vx, double vy); void set(double x, double y); void setX(double x); void setY(double y); @Override double getX(); @Override double getY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testHashCode() { assertHashEquals(new Coord(), new Coord()); assertHashEquals(new Coord(1.5, 2.5), new Coord(1.5, 2.5)); assertHashNotEquals(new Coord(), new Object()); assertHashNotEquals(new Coord(1.0, 0.0), new Coord(1.0, 1.0)); assertHashNotEquals(new Coord(0.0, 1.0), new Coord(1.0, 0.0)); assertHashNotEquals(new Coord(), new Coord(1.0, 1.0)); } |
### Question:
Coord implements Localizable { @Override public String toString() { return new StringBuilder(MIN_LENGHT).append(getClass().getSimpleName()) .append(" [x=") .append(x) .append(", y=") .append(y) .append("]") .toString(); } Coord(); Coord(double x, double y); void translate(double vx, double vy); void set(double x, double y); void setX(double x); void setY(double y); @Override double getX(); @Override double getY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testToString() { assertEquals("Coord [x=1.5, y=2.5]", new Coord(1.5, 2.5).toString()); } |
### Question:
UtilConversion { public static int mask(int value) { return value & 0xFF; } private UtilConversion(); static byte[] intToByteArray(int value); static int byteArrayToInt(byte[] bytes); static byte[] shortToByteArray(short value); static short byteArrayToShort(byte[] bytes); static byte fromUnsignedByte(short value); static short toUnsignedByte(byte value); static short fromUnsignedShort(int value); static int toUnsignedShort(short value); static int mask(int value); static int boolToInt(boolean value); static boolean[] toBinary(int number, int length); static int fromBinary(boolean[] binary); static boolean[] invert(boolean[] binary); static String toTitleCase(String string); static String toTitleCaseWord(String string); }### Answer:
@Test void testMask() { assertEquals(255, UtilConversion.mask(255)); assertEquals(0, UtilConversion.mask(256)); assertEquals(1, UtilConversion.mask(257)); } |
### Question:
UtilConversion { public static String toTitleCase(String string) { Check.notNull(string); final int length = string.length(); final StringBuilder result = new StringBuilder(length); for (int i = 0; i < length; i++) { final String next = string.substring(i, i + 1); if (i == 0) { result.append(next.toUpperCase(Locale.ENGLISH)); } else { result.append(next.toLowerCase(Locale.ENGLISH)); } } return result.toString(); } private UtilConversion(); static byte[] intToByteArray(int value); static int byteArrayToInt(byte[] bytes); static byte[] shortToByteArray(short value); static short byteArrayToShort(byte[] bytes); static byte fromUnsignedByte(short value); static short toUnsignedByte(byte value); static short fromUnsignedShort(int value); static int toUnsignedShort(short value); static int mask(int value); static int boolToInt(boolean value); static boolean[] toBinary(int number, int length); static int fromBinary(boolean[] binary); static boolean[] invert(boolean[] binary); static String toTitleCase(String string); static String toTitleCaseWord(String string); }### Answer:
@Test void testToTitleCase() { final String title = UtilConversion.toTitleCase("title"); assertEquals("Title", title); } |
### Question:
Timing { public void pause() { back = systemTime(); } Timing(); void start(); void stop(); void restart(); void pause(); void unpause(); boolean elapsed(long time); long elapsed(); void set(long value); long get(); boolean isStarted(); }### Answer:
@Test void testPause() { timing.start(); UtilTests.pause(PAUSE); timing.pause(); final long old = timing.get(); final long elapsed = timing.elapsed(); UtilTests.pause(PAUSE); assertEquals(old, timing.get(), old + " " + timing.elapsed()); assertEquals(elapsed, timing.elapsed(), elapsed + " " + timing.elapsed()); } |
### Question:
UtilConversion { public static String toTitleCaseWord(String string) { Check.notNull(string); final String[] words = SPACE.split(REPLACER.matcher(string).replaceAll(Constant.SPACE)); final StringBuilder title = new StringBuilder(string.length()); for (int i = 0; i < words.length; i++) { title.append(toTitleCase(words[i])); if (i < words.length - 1) { title.append(Constant.SPACE); } } return title.toString(); } private UtilConversion(); static byte[] intToByteArray(int value); static int byteArrayToInt(byte[] bytes); static byte[] shortToByteArray(short value); static short byteArrayToShort(byte[] bytes); static byte fromUnsignedByte(short value); static short toUnsignedByte(byte value); static short fromUnsignedShort(int value); static int toUnsignedShort(short value); static int mask(int value); static int boolToInt(boolean value); static boolean[] toBinary(int number, int length); static int fromBinary(boolean[] binary); static boolean[] invert(boolean[] binary); static String toTitleCase(String string); static String toTitleCaseWord(String string); }### Answer:
@Test void testToTitleCaseWord() { final String word = UtilConversion.toTitleCaseWord("title toto"); assertEquals("Title Toto", word); } |
### Question:
UtilConversion { public static int boolToInt(boolean value) { if (value) { return 1; } return 0; } private UtilConversion(); static byte[] intToByteArray(int value); static int byteArrayToInt(byte[] bytes); static byte[] shortToByteArray(short value); static short byteArrayToShort(byte[] bytes); static byte fromUnsignedByte(short value); static short toUnsignedByte(byte value); static short fromUnsignedShort(int value); static int toUnsignedShort(short value); static int mask(int value); static int boolToInt(boolean value); static boolean[] toBinary(int number, int length); static int fromBinary(boolean[] binary); static boolean[] invert(boolean[] binary); static String toTitleCase(String string); static String toTitleCaseWord(String string); }### Answer:
@Test void testBoolToInt() { assertEquals(0, UtilConversion.boolToInt(false)); assertEquals(1, UtilConversion.boolToInt(true)); } |
### Question:
UtilConversion { public static int fromBinary(boolean[] binary) { Check.notNull(binary); int number = 0; for (final boolean current : binary) { number = number << 1 | boolToInt(current); } return number; } private UtilConversion(); static byte[] intToByteArray(int value); static int byteArrayToInt(byte[] bytes); static byte[] shortToByteArray(short value); static short byteArrayToShort(byte[] bytes); static byte fromUnsignedByte(short value); static short toUnsignedByte(byte value); static short fromUnsignedShort(int value); static int toUnsignedShort(short value); static int mask(int value); static int boolToInt(boolean value); static boolean[] toBinary(int number, int length); static int fromBinary(boolean[] binary); static boolean[] invert(boolean[] binary); static String toTitleCase(String string); static String toTitleCaseWord(String string); }### Answer:
@Test void testFromBinary() { assertEquals(0, UtilConversion.fromBinary(new boolean[1])); assertEquals(1, UtilConversion.fromBinary(new boolean[] { true })); assertEquals(2, UtilConversion.fromBinary(new boolean[] { true, false })); assertEquals(3, UtilConversion.fromBinary(new boolean[] { true, true })); assertEquals(4, UtilConversion.fromBinary(new boolean[] { true, false, false })); } |
### Question:
UtilConversion { public static boolean[] toBinary(int number, int length) { final boolean[] binary = new boolean[length]; for (int i = 0; i < length; i++) { binary[length - 1 - i] = (1 << i & number) != 0; } return binary; } private UtilConversion(); static byte[] intToByteArray(int value); static int byteArrayToInt(byte[] bytes); static byte[] shortToByteArray(short value); static short byteArrayToShort(byte[] bytes); static byte fromUnsignedByte(short value); static short toUnsignedByte(byte value); static short fromUnsignedShort(int value); static int toUnsignedShort(short value); static int mask(int value); static int boolToInt(boolean value); static boolean[] toBinary(int number, int length); static int fromBinary(boolean[] binary); static boolean[] invert(boolean[] binary); static String toTitleCase(String string); static String toTitleCaseWord(String string); }### Answer:
@Test void testToBinary() { assertArrayEquals(new boolean[1], UtilConversion.toBinary(0, 1)); assertArrayEquals(new boolean[4], UtilConversion.toBinary(0, 4)); assertArrayEquals(new boolean[] { true }, UtilConversion.toBinary(1, 1)); assertArrayEquals(new boolean[] { true, false }, UtilConversion.toBinary(2, 2)); } |
### Question:
UtilConversion { public static boolean[] invert(boolean[] binary) { Check.notNull(binary); final boolean[] inverted = new boolean[binary.length]; for (int i = 0; i < inverted.length; i++) { inverted[i] = !binary[i]; } return inverted; } private UtilConversion(); static byte[] intToByteArray(int value); static int byteArrayToInt(byte[] bytes); static byte[] shortToByteArray(short value); static short byteArrayToShort(byte[] bytes); static byte fromUnsignedByte(short value); static short toUnsignedByte(byte value); static short fromUnsignedShort(int value); static int toUnsignedShort(short value); static int mask(int value); static int boolToInt(boolean value); static boolean[] toBinary(int number, int length); static int fromBinary(boolean[] binary); static boolean[] invert(boolean[] binary); static String toTitleCase(String string); static String toTitleCaseWord(String string); }### Answer:
@Test void testInvert() { assertArrayEquals(new boolean[] { true, false, true }, UtilConversion.invert(new boolean[] { false, true, false })); for (int i = 0; i < 32; i++) { final boolean[] table = new boolean[i]; for (int j = 0; j < table.length; j++) { if (j % 1 == 0) { table[j] = false; } else { table[j] = true; } } final boolean[] inverted = UtilConversion.invert(table); assertEquals(table.length, inverted.length); for (int j = 0; j < inverted.length; j++) { assertTrue(inverted[j] == !table[j]); } } } |
### Question:
EngineAwt extends Engine { public static void start(String name, Version version) { Engine.start(new EngineAwt(name, version, Constant.EMPTY_STRING)); } EngineAwt(String name, Version version, String resourcesDir); EngineAwt(String name, Version version, Class<?> classResource); static void start(String name, Version version); static void start(String name, Version version, String resourcesDir); static void start(String name, Version version, Class<?> classResource); }### Answer:
@Test void testDefaultAlready() { EngineAwt.start(EngineAwtTest.class.getName(), Version.DEFAULT); assertThrows(() -> EngineAwt.start(EngineAwtTest.class.getName(), Version.DEFAULT), "The engine has already been started !"); }
@Test void testNullResources() { assertThrows(() -> EngineAwt.start(EngineAwtTest.class.getName(), Version.DEFAULT, (String) null), "Unexpected null argument !"); }
@Test void testResourcesAlready() { EngineAwt.start(EngineAwtTest.class.getName(), Version.DEFAULT, Constant.EMPTY_STRING); assertTrue(Engine.isStarted()); assertThrows(() -> EngineAwt.start(EngineAwtTest.class.getName(), Version.DEFAULT, Constant.EMPTY_STRING), "The engine has already been started !"); }
@Test void testClass() { EngineAwt.start(EngineAwtTest.class.getName(), Version.DEFAULT, EngineAwtTest.class); assertTrue(Engine.isStarted()); assertThrows(() -> EngineAwt.start(EngineAwtTest.class.getName(), Version.DEFAULT, EngineAwtTest.class), "The engine has already been started !"); } |
### Question:
TextAwt implements Text { @Override public void draw(Graphic g, int x, int y, String text) { draw(g, x, y, Align.LEFT, text); } TextAwt(String fontName, int size, TextStyle style); @Override void draw(Graphic g, int x, int y, String text); @Override void draw(Graphic g, int x, int y, Align alignment, String text); @Override void render(Graphic g); @Override void setLocation(int x, int y); @Override void setText(String text); @Override void setAlign(Align align); @Override void setColor(ColorRgba color); @Override int getSize(); @Override int getLocationX(); @Override int getLocationY(); @Override int getWidth(); @Override int getHeight(); @Override int getStringWidth(Graphic g, String str); @Override int getStringHeight(Graphic g, String str); }### Answer:
@Test void testBold() { final Text text = Graphics.createText(Constant.FONT_DIALOG, 12, TextStyle.BOLD); text.draw(g, 0, 0, VALUE); }
@Test void testItalic() { final Text text = Graphics.createText(Constant.FONT_DIALOG, 12, TextStyle.ITALIC); text.draw(g, 0, 0, VALUE); }
@Test void testAlignUnknown() { final Text text = Graphics.createText(Constant.FONT_DIALOG, 12, TextStyle.NORMAL); final Graphic g = Graphics.createGraphic(); g.setGraphic(ToolsAwt.createImage(1, 1, java.awt.Transparency.OPAQUE).createGraphics()); assertThrows(() -> text.draw(g, 0, 0, UtilEnum.make(Align.class, "FAIL"), Constant.EMPTY_STRING), "Unknown enum: FAIL"); } |
### Question:
FactoryGraphicAwt implements FactoryGraphic { @Override public ImageBuffer rotate(ImageBuffer image, int angle) { final BufferedImage surface = image.getSurface(); return new ImageBufferAwt(ToolsAwt.rotate(surface, angle)); } FactoryGraphicAwt(); @Override Screen createScreen(Config config); @Override Graphic createGraphic(); @Override Transform createTransform(); @Override Text createText(String fontName, int size, TextStyle style); @Override ImageBuffer createImageBuffer(int width, int height); @Override ImageBuffer createImageBuffer(int width, int height, ColorRgba transparency); @Override ImageBuffer getImageBuffer(Media media); @Override ImageBuffer getImageBuffer(ImageBuffer image); @Override ImageBuffer applyMask(ImageBuffer image, ColorRgba maskColor); @Override ImageBuffer[] splitImage(ImageBuffer image, int h, int v); @Override ImageBuffer rotate(ImageBuffer image, int angle); @Override ImageBuffer resize(ImageBuffer image, int width, int height); @Override ImageBuffer flipHorizontal(ImageBuffer image); @Override ImageBuffer flipVertical(ImageBuffer image); @Override void saveImage(ImageBuffer image, Media media); @Override ImageBuffer getRasterBuffer(ImageBuffer image, double fr, double fg, double fb); }### Answer:
@Test @Override protected void testRotate() { final ImageBuffer image = Graphics.getImageBuffer(Medias.create("image.png")); final ImageBuffer rotate = Graphics.rotate(image, 90); assertNotEquals(image, rotate); assertEquals(image.getWidth(), rotate.getHeight()); assertEquals(image.getHeight(), rotate.getWidth()); rotate.dispose(); image.dispose(); } |
### Question:
ToolsAwt { public static BufferedImage getImage(InputStream input) throws IOException { final BufferedImage buffer = ImageIO.read(input); if (buffer == null) { throw new IOException("Invalid image !"); } return copyImage(buffer); } private ToolsAwt(); static int getTransparency(Transparency transparency); static BufferedImage createImage(int width, int height, int transparency); static BufferedImage getImage(InputStream input); static ImageBuffer getImageBuffer(BufferedImage image); static void saveImage(BufferedImage image, OutputStream output); static BufferedImage copyImage(BufferedImage image); static int[] getImageData(BufferedImage image); static BufferedImage applyMask(BufferedImage image, int rgba); static BufferedImage rotate(BufferedImage image, int angle); static BufferedImage resize(BufferedImage image, int width, int height); static BufferedImage flipHorizontal(BufferedImage image); static BufferedImage flipVertical(BufferedImage image); static BufferedImage[] splitImage(BufferedImage image, int h, int v); static BufferedImage getRasterBuffer(BufferedImage image, double fr, double fg, double fb); static Cursor createHiddenCursor(); static void createBufferStrategy(java.awt.Canvas component, GraphicsConfiguration conf); static void createBufferStrategy(java.awt.Window component, GraphicsConfiguration conf); static void optimizeGraphicsQuality(Graphics2D g); static void optimizeGraphicsSpeed(Graphics2D g); }### Answer:
@Test void testGetIoFail() throws IOException { final Media media = Medias.create("raster.xml"); try (InputStream input = media.getInputStream()) { assertThrows(IOException.class, () -> ToolsAwt.getImage(input), "Invalid image !"); } } |
### Question:
FramesConfig { public static FramesConfig imports(Configurer configurer) { Check.notNull(configurer); return imports(configurer.getRoot()); } FramesConfig(int horizontalFrames, int verticalFrames, int offsetX, int offsetY); static FramesConfig imports(Configurer configurer); static FramesConfig imports(Xml root); static Xml exports(FramesConfig config); int getHorizontal(); int getVertical(); int getOffsetX(); int getOffsetY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_FRAMES; static final String ATT_HORIZONTAL; static final String ATT_VERTICAL; static final String ATT_OFFSET_X; static final String ATT_OFFSET_Y; }### Answer:
@Test void testNoNode() { final Xml root = new Xml("test"); assertEquals(new FramesConfig(1, 1, 0, 0), FramesConfig.imports(root)); } |
### Question:
FramesConfig { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final FramesConfig other = (FramesConfig) object; return horizontalFrames == other.horizontalFrames && verticalFrames == other.verticalFrames && offsetX == other.offsetX && offsetY == other.offsetY; } FramesConfig(int horizontalFrames, int verticalFrames, int offsetX, int offsetY); static FramesConfig imports(Configurer configurer); static FramesConfig imports(Xml root); static Xml exports(FramesConfig config); int getHorizontal(); int getVertical(); int getOffsetX(); int getOffsetY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_FRAMES; static final String ATT_HORIZONTAL; static final String ATT_VERTICAL; static final String ATT_OFFSET_X; static final String ATT_OFFSET_Y; }### Answer:
@Test void testEquals() { final FramesConfig config = new FramesConfig(1, 2, 3, 4); assertEquals(config, config); assertEquals(config, new FramesConfig(1, 2, 3, 4)); assertNotEquals(config, null); assertNotEquals(config, new Object()); assertNotEquals(config, new FramesConfig(0, 2, 3, 4)); assertNotEquals(config, new FramesConfig(1, 0, 3, 4)); assertNotEquals(config, new FramesConfig(1, 2, 0, 4)); assertNotEquals(config, new FramesConfig(1, 2, 3, 0)); } |
### Question:
FramesConfig { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + horizontalFrames; result = prime * result + verticalFrames; result = prime * result + offsetX; result = prime * result + offsetY; return result; } FramesConfig(int horizontalFrames, int verticalFrames, int offsetX, int offsetY); static FramesConfig imports(Configurer configurer); static FramesConfig imports(Xml root); static Xml exports(FramesConfig config); int getHorizontal(); int getVertical(); int getOffsetX(); int getOffsetY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_FRAMES; static final String ATT_HORIZONTAL; static final String ATT_VERTICAL; static final String ATT_OFFSET_X; static final String ATT_OFFSET_Y; }### Answer:
@Test void testHashCode() { final FramesConfig hash = new FramesConfig(1, 2, 3, 4); assertHashEquals(hash, new FramesConfig(1, 2, 3, 4)); assertHashNotEquals(hash, new FramesConfig(0, 2, 3, 4)); assertHashNotEquals(hash, new FramesConfig(1, 0, 3, 4)); assertHashNotEquals(hash, new FramesConfig(1, 2, 0, 4)); assertHashNotEquals(hash, new FramesConfig(1, 2, 3, 0)); } |
### Question:
FramesConfig { @Override public String toString() { return new StringBuilder(MIN_LENGTH).append(getClass().getSimpleName()) .append(" [horizontalFrames=") .append(horizontalFrames) .append(", verticalFrames=") .append(verticalFrames) .append(", offsetX=") .append(offsetX) .append(", offsetY=") .append(offsetY) .append("]") .toString(); } FramesConfig(int horizontalFrames, int verticalFrames, int offsetX, int offsetY); static FramesConfig imports(Configurer configurer); static FramesConfig imports(Xml root); static Xml exports(FramesConfig config); int getHorizontal(); int getVertical(); int getOffsetX(); int getOffsetY(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_FRAMES; static final String ATT_HORIZONTAL; static final String ATT_VERTICAL; static final String ATT_OFFSET_X; static final String ATT_OFFSET_Y; }### Answer:
@Test void testToString() { final FramesConfig config = new FramesConfig(1, 2, 3, 4); assertEquals("FramesConfig [horizontalFrames=1, verticalFrames=2, offsetX=3, offsetY=4]", config.toString()); } |
### Question:
SizeConfig { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final SizeConfig other = (SizeConfig) object; return other.width == width && other.height == height; } SizeConfig(int width, int height); static SizeConfig imports(Configurer configurer); static SizeConfig imports(Xml root); static Xml exports(SizeConfig config); int getWidth(); int getHeight(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_SIZE; static final String ATT_WIDTH; static final String ATT_HEIGHT; }### Answer:
@Test void testEquals() { final SizeConfig config = new SizeConfig(16, 32); assertEquals(config, config); assertEquals(config, new SizeConfig(16, 32)); assertNotEquals(config, null); assertNotEquals(config, new Object()); assertNotEquals(config, new SizeConfig(0, 32)); assertNotEquals(config, new SizeConfig(16, 0)); } |
### Question:
SizeConfig { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + width; result = prime * result + height; return result; } SizeConfig(int width, int height); static SizeConfig imports(Configurer configurer); static SizeConfig imports(Xml root); static Xml exports(SizeConfig config); int getWidth(); int getHeight(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_SIZE; static final String ATT_WIDTH; static final String ATT_HEIGHT; }### Answer:
@Test void testHashCode() { final SizeConfig hash = new SizeConfig(16, 32); assertHashEquals(hash, new SizeConfig(16, 32)); assertHashNotEquals(hash, new SizeConfig(0, 32)); assertHashNotEquals(hash, new SizeConfig(16, 0)); } |
### Question:
SizeConfig { @Override public String toString() { return new StringBuilder(MIN_LENGTH).append(getClass().getSimpleName()) .append(" [width=") .append(width) .append(", height=") .append(height) .append("]") .toString(); } SizeConfig(int width, int height); static SizeConfig imports(Configurer configurer); static SizeConfig imports(Xml root); static Xml exports(SizeConfig config); int getWidth(); int getHeight(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_SIZE; static final String ATT_WIDTH; static final String ATT_HEIGHT; }### Answer:
@Test void testToString() { final SizeConfig config = new SizeConfig(16, 32); assertHashEquals("SizeConfig [width=16, height=32]", config.toString()); } |
### Question:
Configurer { public final Xml getRoot() { return root; } Configurer(Media media); static void clearCache(); final void save(); final Xml getRoot(); final String getPath(); final Media getMedia(); final String getText(String... path); final String getTextDefault(String defaultValue, String... path); final String getString(String attribute, String... path); final String getStringDefault(String defaultValue, String attribute, String... path); final boolean getBoolean(String attribute, String... path); final boolean getBooleanDefault(boolean defaultValue, String attribute, String... path); final int getInteger(String attribute, String... path); final int getIntegerDefault(int defaultValue, String attribute, String... path); final double getDouble(String attribute, String... path); final double getDoubleDefault(double defaultValue, String attribute, String... path); final T getImplementation(Class<T> type, String... path); final T getImplementation(ClassLoader loader, Class<T> type, String... path); final T getImplementation(Class<T> type, Class<?> paramType, Object paramValue, String... path); final T getImplementation(Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); static final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String className); final boolean hasNode(String... path); }### Answer:
@Test void testGetRoot() { final Xml root = configurer.getRoot(); assertNotNull(root); assertEquals("root", root.getNodeName()); } |
### Question:
Configurer { public final String getPath() { return path; } Configurer(Media media); static void clearCache(); final void save(); final Xml getRoot(); final String getPath(); final Media getMedia(); final String getText(String... path); final String getTextDefault(String defaultValue, String... path); final String getString(String attribute, String... path); final String getStringDefault(String defaultValue, String attribute, String... path); final boolean getBoolean(String attribute, String... path); final boolean getBooleanDefault(boolean defaultValue, String attribute, String... path); final int getInteger(String attribute, String... path); final int getIntegerDefault(int defaultValue, String attribute, String... path); final double getDouble(String attribute, String... path); final double getDoubleDefault(double defaultValue, String attribute, String... path); final T getImplementation(Class<T> type, String... path); final T getImplementation(ClassLoader loader, Class<T> type, String... path); final T getImplementation(Class<T> type, Class<?> paramType, Object paramValue, String... path); final T getImplementation(Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); static final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String className); final boolean hasNode(String... path); }### Answer:
@Test void testGetPath() { assertEquals(config.getFile().getParent(), configurer.getPath()); } |
### Question:
UtilMath { public static int getRounded(double value, int round) { Check.different(round, 0); return (int) Math.floor(value / round) * round; } private UtilMath(); static double getRound(double speed, double value); static boolean isBetween(int value, int min, int max); static boolean isBetween(double value, double min, double max); static int clamp(int value, int min, int max); static long clamp(long value, long min, long max); static double clamp(double value, double min, double max); static double curveValue(double value, double dest, double speed); static double getDistance(double x1, double y1, double x2, double y2); static double getDistance(Localizable a, Localizable b); static double getDistance(double x1, double y1, double x2, double y2, int w2, int h2); static double getDistance(double x1, double y1, int w1, int h1, double x2, double y2, int w2, int h2); static int wrap(int value, int min, int max); static int wrapAngle(int angle); static double wrapDouble(double value, double min, double max); static int getRounded(double value, int round); static int getRoundedC(double value, int round); static double cos(double degree); static double sin(double degree); static int getSign(double value); }### Answer:
@Test void testRounded() { assertEquals(100, UtilMath.getRounded(105, 100)); } |
### Question:
Configurer { public final Media getMedia() { return media; } Configurer(Media media); static void clearCache(); final void save(); final Xml getRoot(); final String getPath(); final Media getMedia(); final String getText(String... path); final String getTextDefault(String defaultValue, String... path); final String getString(String attribute, String... path); final String getStringDefault(String defaultValue, String attribute, String... path); final boolean getBoolean(String attribute, String... path); final boolean getBooleanDefault(boolean defaultValue, String attribute, String... path); final int getInteger(String attribute, String... path); final int getIntegerDefault(int defaultValue, String attribute, String... path); final double getDouble(String attribute, String... path); final double getDoubleDefault(double defaultValue, String attribute, String... path); final T getImplementation(Class<T> type, String... path); final T getImplementation(ClassLoader loader, Class<T> type, String... path); final T getImplementation(Class<T> type, Class<?> paramType, Object paramValue, String... path); final T getImplementation(Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); static final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String className); final boolean hasNode(String... path); }### Answer:
@Test void testGetMedia() { assertEquals(config, configurer.getMedia()); } |
### Question:
Configurer { public final String getString(String attribute, String... path) { return getNodeString(attribute, path); } Configurer(Media media); static void clearCache(); final void save(); final Xml getRoot(); final String getPath(); final Media getMedia(); final String getText(String... path); final String getTextDefault(String defaultValue, String... path); final String getString(String attribute, String... path); final String getStringDefault(String defaultValue, String attribute, String... path); final boolean getBoolean(String attribute, String... path); final boolean getBooleanDefault(boolean defaultValue, String attribute, String... path); final int getInteger(String attribute, String... path); final int getIntegerDefault(int defaultValue, String attribute, String... path); final double getDouble(String attribute, String... path); final double getDoubleDefault(double defaultValue, String attribute, String... path); final T getImplementation(Class<T> type, String... path); final T getImplementation(ClassLoader loader, Class<T> type, String... path); final T getImplementation(Class<T> type, Class<?> paramType, Object paramValue, String... path); final T getImplementation(Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); static final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String className); final boolean hasNode(String... path); }### Answer:
@Test void testGetString() { assertEquals("string", configurer.getString("attStr")); } |
### Question:
Configurer { public final String getStringDefault(String defaultValue, String attribute, String... path) { return getNodeStringDefault(defaultValue, attribute, path); } Configurer(Media media); static void clearCache(); final void save(); final Xml getRoot(); final String getPath(); final Media getMedia(); final String getText(String... path); final String getTextDefault(String defaultValue, String... path); final String getString(String attribute, String... path); final String getStringDefault(String defaultValue, String attribute, String... path); final boolean getBoolean(String attribute, String... path); final boolean getBooleanDefault(boolean defaultValue, String attribute, String... path); final int getInteger(String attribute, String... path); final int getIntegerDefault(int defaultValue, String attribute, String... path); final double getDouble(String attribute, String... path); final double getDoubleDefault(double defaultValue, String attribute, String... path); final T getImplementation(Class<T> type, String... path); final T getImplementation(ClassLoader loader, Class<T> type, String... path); final T getImplementation(Class<T> type, Class<?> paramType, Object paramValue, String... path); final T getImplementation(Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); static final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String className); final boolean hasNode(String... path); }### Answer:
@Test void testGetStringDefault() { assertEquals("string", configurer.getStringDefault("default", "attStr")); assertEquals("default", configurer.getStringDefault("default", "void")); assertEquals("default", configurer.getStringDefault("default", "void", "none")); } |
### Question:
Configurer { public final boolean getBoolean(String attribute, String... path) { return Boolean.parseBoolean(getNodeString(attribute, path)); } Configurer(Media media); static void clearCache(); final void save(); final Xml getRoot(); final String getPath(); final Media getMedia(); final String getText(String... path); final String getTextDefault(String defaultValue, String... path); final String getString(String attribute, String... path); final String getStringDefault(String defaultValue, String attribute, String... path); final boolean getBoolean(String attribute, String... path); final boolean getBooleanDefault(boolean defaultValue, String attribute, String... path); final int getInteger(String attribute, String... path); final int getIntegerDefault(int defaultValue, String attribute, String... path); final double getDouble(String attribute, String... path); final double getDoubleDefault(double defaultValue, String attribute, String... path); final T getImplementation(Class<T> type, String... path); final T getImplementation(ClassLoader loader, Class<T> type, String... path); final T getImplementation(Class<T> type, Class<?> paramType, Object paramValue, String... path); final T getImplementation(Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); static final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String className); final boolean hasNode(String... path); }### Answer:
@Test void testGetBoolean() { assertFalse(configurer.getBoolean("attStr")); } |
### Question:
Configurer { public final boolean getBooleanDefault(boolean defaultValue, String attribute, String... path) { return Boolean.parseBoolean(getNodeStringDefault(String.valueOf(defaultValue), attribute, path)); } Configurer(Media media); static void clearCache(); final void save(); final Xml getRoot(); final String getPath(); final Media getMedia(); final String getText(String... path); final String getTextDefault(String defaultValue, String... path); final String getString(String attribute, String... path); final String getStringDefault(String defaultValue, String attribute, String... path); final boolean getBoolean(String attribute, String... path); final boolean getBooleanDefault(boolean defaultValue, String attribute, String... path); final int getInteger(String attribute, String... path); final int getIntegerDefault(int defaultValue, String attribute, String... path); final double getDouble(String attribute, String... path); final double getDoubleDefault(double defaultValue, String attribute, String... path); final T getImplementation(Class<T> type, String... path); final T getImplementation(ClassLoader loader, Class<T> type, String... path); final T getImplementation(Class<T> type, Class<?> paramType, Object paramValue, String... path); final T getImplementation(Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); static final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String className); final boolean hasNode(String... path); }### Answer:
@Test void testGetBooleanDefault() { assertFalse(configurer.getBooleanDefault(true, "attStr")); assertTrue(configurer.getBooleanDefault(true, "void")); } |
### Question:
Configurer { public final int getInteger(String attribute, String... path) { try { return Integer.parseInt(getNodeString(attribute, path)); } catch (final NumberFormatException exception) { throw new LionEngineException(exception, media); } } Configurer(Media media); static void clearCache(); final void save(); final Xml getRoot(); final String getPath(); final Media getMedia(); final String getText(String... path); final String getTextDefault(String defaultValue, String... path); final String getString(String attribute, String... path); final String getStringDefault(String defaultValue, String attribute, String... path); final boolean getBoolean(String attribute, String... path); final boolean getBooleanDefault(boolean defaultValue, String attribute, String... path); final int getInteger(String attribute, String... path); final int getIntegerDefault(int defaultValue, String attribute, String... path); final double getDouble(String attribute, String... path); final double getDoubleDefault(double defaultValue, String attribute, String... path); final T getImplementation(Class<T> type, String... path); final T getImplementation(ClassLoader loader, Class<T> type, String... path); final T getImplementation(Class<T> type, Class<?> paramType, Object paramValue, String... path); final T getImplementation(Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); static final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String className); final boolean hasNode(String... path); }### Answer:
@Test void testGetInteger() { assertEquals(1, configurer.getInteger("attInt")); }
@Test void testGetIntegerInvalid() { assertThrows(() -> configurer.getInteger("attStr"), "[configurer.xml] "); } |
### Question:
Configurer { public final double getDouble(String attribute, String... path) { try { return Double.parseDouble(getNodeString(attribute, path)); } catch (final NumberFormatException exception) { throw new LionEngineException(exception, media); } } Configurer(Media media); static void clearCache(); final void save(); final Xml getRoot(); final String getPath(); final Media getMedia(); final String getText(String... path); final String getTextDefault(String defaultValue, String... path); final String getString(String attribute, String... path); final String getStringDefault(String defaultValue, String attribute, String... path); final boolean getBoolean(String attribute, String... path); final boolean getBooleanDefault(boolean defaultValue, String attribute, String... path); final int getInteger(String attribute, String... path); final int getIntegerDefault(int defaultValue, String attribute, String... path); final double getDouble(String attribute, String... path); final double getDoubleDefault(double defaultValue, String attribute, String... path); final T getImplementation(Class<T> type, String... path); final T getImplementation(ClassLoader loader, Class<T> type, String... path); final T getImplementation(Class<T> type, Class<?> paramType, Object paramValue, String... path); final T getImplementation(Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); static final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String className); final boolean hasNode(String... path); }### Answer:
@Test void testGetDouble() { assertEquals(1.0, configurer.getDouble("attInt")); }
@Test void testGetDoubleInvalid() { assertThrows(() -> configurer.getDouble("attStr"), "[configurer.xml] "); } |
### Question:
UtilMath { public static int getRoundedC(double value, int round) { Check.different(round, 0); return (int) Math.ceil(value / round) * round; } private UtilMath(); static double getRound(double speed, double value); static boolean isBetween(int value, int min, int max); static boolean isBetween(double value, double min, double max); static int clamp(int value, int min, int max); static long clamp(long value, long min, long max); static double clamp(double value, double min, double max); static double curveValue(double value, double dest, double speed); static double getDistance(double x1, double y1, double x2, double y2); static double getDistance(Localizable a, Localizable b); static double getDistance(double x1, double y1, double x2, double y2, int w2, int h2); static double getDistance(double x1, double y1, int w1, int h1, double x2, double y2, int w2, int h2); static int wrap(int value, int min, int max); static int wrapAngle(int angle); static double wrapDouble(double value, double min, double max); static int getRounded(double value, int round); static int getRoundedC(double value, int round); static double cos(double degree); static double sin(double degree); static int getSign(double value); }### Answer:
@Test void testRoundedC() { assertEquals(200, UtilMath.getRoundedC(105, 100)); } |
### Question:
Configurer { public final String getText(String... path) { final Xml node = getNode(path); return node.getText(); } Configurer(Media media); static void clearCache(); final void save(); final Xml getRoot(); final String getPath(); final Media getMedia(); final String getText(String... path); final String getTextDefault(String defaultValue, String... path); final String getString(String attribute, String... path); final String getStringDefault(String defaultValue, String attribute, String... path); final boolean getBoolean(String attribute, String... path); final boolean getBooleanDefault(boolean defaultValue, String attribute, String... path); final int getInteger(String attribute, String... path); final int getIntegerDefault(int defaultValue, String attribute, String... path); final double getDouble(String attribute, String... path); final double getDoubleDefault(double defaultValue, String attribute, String... path); final T getImplementation(Class<T> type, String... path); final T getImplementation(ClassLoader loader, Class<T> type, String... path); final T getImplementation(Class<T> type, Class<?> paramType, Object paramValue, String... path); final T getImplementation(Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); static final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String className); final boolean hasNode(String... path); }### Answer:
@Test void testGetText() { assertEquals(Accessible.class.getName(), configurer.getText(Accessible.class.getSimpleName())); }
@Test void testNodeNotFound() { assertThrows(() -> configurer.getText("void", "null"), "[configurer.xml] "); } |
### Question:
Configurer { public final String getTextDefault(String defaultValue, String... path) { final Xml node = getNodeDefault(path); if (node != null) { return node.getText(); } return defaultValue; } Configurer(Media media); static void clearCache(); final void save(); final Xml getRoot(); final String getPath(); final Media getMedia(); final String getText(String... path); final String getTextDefault(String defaultValue, String... path); final String getString(String attribute, String... path); final String getStringDefault(String defaultValue, String attribute, String... path); final boolean getBoolean(String attribute, String... path); final boolean getBooleanDefault(boolean defaultValue, String attribute, String... path); final int getInteger(String attribute, String... path); final int getIntegerDefault(int defaultValue, String attribute, String... path); final double getDouble(String attribute, String... path); final double getDoubleDefault(double defaultValue, String attribute, String... path); final T getImplementation(Class<T> type, String... path); final T getImplementation(ClassLoader loader, Class<T> type, String... path); final T getImplementation(Class<T> type, Class<?> paramType, Object paramValue, String... path); final T getImplementation(Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); static final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String className); final boolean hasNode(String... path); }### Answer:
@Test void testGetTextDefault() { assertEquals(Accessible.class.getName(), configurer.getTextDefault("default", Accessible.class.getSimpleName())); assertEquals("default", configurer.getTextDefault("default", "void")); } |
### Question:
UtilMath { public static double curveValue(double value, double dest, double speed) { Check.different(speed, 0.0); final double reciprocal = 1.0 / speed; final double invReciprocal = 1.0 - reciprocal; return value * invReciprocal + dest * reciprocal; } private UtilMath(); static double getRound(double speed, double value); static boolean isBetween(int value, int min, int max); static boolean isBetween(double value, double min, double max); static int clamp(int value, int min, int max); static long clamp(long value, long min, long max); static double clamp(double value, double min, double max); static double curveValue(double value, double dest, double speed); static double getDistance(double x1, double y1, double x2, double y2); static double getDistance(Localizable a, Localizable b); static double getDistance(double x1, double y1, double x2, double y2, int w2, int h2); static double getDistance(double x1, double y1, int w1, int h1, double x2, double y2, int w2, int h2); static int wrap(int value, int min, int max); static int wrapAngle(int angle); static double wrapDouble(double value, double min, double max); static int getRounded(double value, int round); static int getRoundedC(double value, int round); static double cos(double degree); static double sin(double degree); static int getSign(double value); }### Answer:
@Test void testCurveValue() { assertTrue(UtilMath.curveValue(0.0, 1.0, 0.5) > 0.0); assertTrue(UtilMath.curveValue(0.0, -1.0, 0.5) < 0.0); } |
### Question:
Configurer { public final boolean hasNode(String... path) { Xml node = root; for (final String element : path) { if (!node.hasChild(element)) { return false; } node = node.getChild(element); } return true; } Configurer(Media media); static void clearCache(); final void save(); final Xml getRoot(); final String getPath(); final Media getMedia(); final String getText(String... path); final String getTextDefault(String defaultValue, String... path); final String getString(String attribute, String... path); final String getStringDefault(String defaultValue, String attribute, String... path); final boolean getBoolean(String attribute, String... path); final boolean getBooleanDefault(boolean defaultValue, String attribute, String... path); final int getInteger(String attribute, String... path); final int getIntegerDefault(int defaultValue, String attribute, String... path); final double getDouble(String attribute, String... path); final double getDoubleDefault(double defaultValue, String attribute, String... path); final T getImplementation(Class<T> type, String... path); final T getImplementation(ClassLoader loader, Class<T> type, String... path); final T getImplementation(Class<T> type, Class<?> paramType, Object paramValue, String... path); final T getImplementation(Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); static final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String className); final boolean hasNode(String... path); }### Answer:
@Test void testHasNode() { assertFalse(configurer.hasNode("void")); assertTrue(configurer.hasNode("unknown")); assertFalse(configurer.hasNode("void", "unknown")); } |
### Question:
Configurer { public final void save() { root.save(media); } Configurer(Media media); static void clearCache(); final void save(); final Xml getRoot(); final String getPath(); final Media getMedia(); final String getText(String... path); final String getTextDefault(String defaultValue, String... path); final String getString(String attribute, String... path); final String getStringDefault(String defaultValue, String attribute, String... path); final boolean getBoolean(String attribute, String... path); final boolean getBooleanDefault(boolean defaultValue, String attribute, String... path); final int getInteger(String attribute, String... path); final int getIntegerDefault(int defaultValue, String attribute, String... path); final double getDouble(String attribute, String... path); final double getDoubleDefault(double defaultValue, String attribute, String... path); final T getImplementation(Class<T> type, String... path); final T getImplementation(ClassLoader loader, Class<T> type, String... path); final T getImplementation(Class<T> type, Class<?> paramType, Object paramValue, String... path); final T getImplementation(Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String... path); static final T getImplementation(ClassLoader loader,
Class<T> type,
Class<?>[] paramsType,
Collection<?> paramsValue,
String className); final boolean hasNode(String... path); }### Answer:
@Test void testSave() { final Media media = createConfig("save.xml"); final Configurer configurer = new Configurer(media); final Xml root = configurer.getRoot(); root.setText("save"); configurer.save(); assertEquals("save", new Configurer(media).getText()); assertTrue(media.getFile().delete()); } |
### Question:
TextGame implements Text { public void draw(Graphic g, Localizable localizable, int offsetX, int offsetY, Align align, String text) { draw(g, (int) localizable.getX() + offsetX, (int) localizable.getY() + offsetY, align, text); } TextGame(String fontName, int size, TextStyle style); void update(Viewer viewer); void draw(Graphic g, Localizable localizable, int offsetX, int offsetY, Align align, String text); void drawRect(Graphic g, ColorRgba color, int x, int y, int width, int height); @Override void draw(Graphic g, int x, int y, Align alignment, String text); @Override void draw(Graphic g, int x, int y, String text); @Override void render(Graphic g); @Override void setLocation(int x, int y); @Override void setText(String text); @Override void setAlign(Align align); @Override void setColor(ColorRgba color); @Override int getSize(); @Override int getLocationX(); @Override int getLocationY(); @Override int getWidth(); @Override int getHeight(); @Override int getStringWidth(Graphic g, String str); @Override int getStringHeight(Graphic g, String str); }### Answer:
@Test void testDraw() { final Graphic g = new GraphicMock(); final TextGame text = new TextGame(Constant.FONT_DIALOG, 8, TextStyle.NORMAL); text.setText("text"); text.setAlign(Align.CENTER); text.setColor(ColorRgba.WHITE); text.render(g); text.draw(g, 0, 0, "toto"); text.draw(g, 1, 2, Align.LEFT, "tata"); text.draw(g, Geom.createLocalizable(3, 4), 1, 2, Align.RIGHT, "titi"); text.drawRect(g, ColorRgba.BLACK, 0, 0, 10, 20); g.dispose(); } |
### Question:
ForceConfig { public static Force imports(Configurer configurer) { Check.notNull(configurer); return imports(configurer.getRoot()); } private ForceConfig(); static Force imports(Configurer configurer); static Force imports(Xml root); static Xml exports(Force force); static final String NODE_FORCE; static final String ATT_VX; static final String ATT_VY; static final String ATT_VELOCITY; static final String ATT_SENSIBILITY; }### Answer:
@Test void testOptional() { final Xml root = new Xml("test"); final Xml node = root.createChild(ForceConfig.NODE_FORCE); final Force force = new Force(1.0, 2.0, 0.0, 0.0); node.writeDouble(ForceConfig.ATT_VX, force.getDirectionHorizontal()); node.writeDouble(ForceConfig.ATT_VY, force.getDirectionVertical()); final Media media = Medias.create("force.xml"); root.save(media); assertEquals(force, ForceConfig.imports(new Xml(media))); assertEquals(force, ForceConfig.imports(new Configurer(media))); assertTrue(media.getFile().delete()); } |
### Question:
Force implements Direction, Updatable { public void addDirection(double extrp, Direction direction) { addDirection(extrp, direction.getDirectionHorizontal(), direction.getDirectionVertical()); } Force(); Force(double fh, double fv); Force(double fh, double fv, double velocity, double sensibility); Force(Force force); static Force fromVector(double ox, double oy, double x, double y); void zero(); void setVelocity(double velocity); void setSensibility(double sensibility); void addDirection(double extrp, Direction direction); void addDirection(double extrp, double fh, double fv); void setDirection(Direction direction); void setDirection(double fh, double fv); void setDestination(double fh, double fv); void setDirectionMaximum(Direction max); void setDirectionMinimum(Direction min); double getVelocity(); double getSensibility(); boolean isDecreasingHorizontal(); boolean isIncreasingHorizontal(); @Override void update(double extrp); @Override double getDirectionHorizontal(); @Override double getDirectionVertical(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testAddDirection() { final Force force = new Force(1.0, 2.0); force.addDirection(1.0, -1, -2.0); force.addDirection(1.0, new Force(2.0, 1.0)); assertForce(2.0, 1.0, 0.0, 0.0, force); }
@Test void testAddDirectionExtrapolation() { final Force force = new Force(0.0, 0.0); force.addDirection(0.5, 1, 2.0); assertForce(0.5, 1.0, 0.0, 0.0, force); } |
### Question:
Force implements Direction, Updatable { public void setDirection(Direction direction) { setDirection(direction.getDirectionHorizontal(), direction.getDirectionVertical()); } Force(); Force(double fh, double fv); Force(double fh, double fv, double velocity, double sensibility); Force(Force force); static Force fromVector(double ox, double oy, double x, double y); void zero(); void setVelocity(double velocity); void setSensibility(double sensibility); void addDirection(double extrp, Direction direction); void addDirection(double extrp, double fh, double fv); void setDirection(Direction direction); void setDirection(double fh, double fv); void setDestination(double fh, double fv); void setDirectionMaximum(Direction max); void setDirectionMinimum(Direction min); double getVelocity(); double getSensibility(); boolean isDecreasingHorizontal(); boolean isIncreasingHorizontal(); @Override void update(double extrp); @Override double getDirectionHorizontal(); @Override double getDirectionVertical(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testSetDirection() { final Force force = new Force(0.0, 0.0); force.setDirection(1.0, 2.0); assertForce(1.0, 2.0, 0.0, 0.0, force); force.setDirection(new Force(-1.0, -2.0)); assertForce(-1.0, -2.0, 0.0, 0.0, force); } |
### Question:
Force implements Direction, Updatable { public void setDirectionMinimum(Direction min) { directionMin = min; } Force(); Force(double fh, double fv); Force(double fh, double fv, double velocity, double sensibility); Force(Force force); static Force fromVector(double ox, double oy, double x, double y); void zero(); void setVelocity(double velocity); void setSensibility(double sensibility); void addDirection(double extrp, Direction direction); void addDirection(double extrp, double fh, double fv); void setDirection(Direction direction); void setDirection(double fh, double fv); void setDestination(double fh, double fv); void setDirectionMaximum(Direction max); void setDirectionMinimum(Direction min); double getVelocity(); double getSensibility(); boolean isDecreasingHorizontal(); boolean isIncreasingHorizontal(); @Override void update(double extrp); @Override double getDirectionHorizontal(); @Override double getDirectionVertical(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testSetDirectionMinimum() { final Force force = new Force(1.0, 2.0); force.setDirectionMinimum(new Force(3.0, 4.0)); force.update(1.0); assertForce(3.0, 4.0, 0.0, 0.0, force); } |
### Question:
Force implements Direction, Updatable { public void setDirectionMaximum(Direction max) { directionMax = max; } Force(); Force(double fh, double fv); Force(double fh, double fv, double velocity, double sensibility); Force(Force force); static Force fromVector(double ox, double oy, double x, double y); void zero(); void setVelocity(double velocity); void setSensibility(double sensibility); void addDirection(double extrp, Direction direction); void addDirection(double extrp, double fh, double fv); void setDirection(Direction direction); void setDirection(double fh, double fv); void setDestination(double fh, double fv); void setDirectionMaximum(Direction max); void setDirectionMinimum(Direction min); double getVelocity(); double getSensibility(); boolean isDecreasingHorizontal(); boolean isIncreasingHorizontal(); @Override void update(double extrp); @Override double getDirectionHorizontal(); @Override double getDirectionVertical(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testSetDirectionMaximum() { final Force force = new Force(3.0, 4.0); force.setDirectionMaximum(new Force(1.0, 2.0)); force.update(1.0); assertForce(1.0, 2.0, 0.0, 0.0, force); } |
### Question:
Force implements Direction, Updatable { public void zero() { fhOld = 0.0; fvOld = 0.0; fhDest = 0.0; fvDest = 0.0; fhLast = 0.0; fvLast = 0.0; fh = 0.0; fv = 0.0; } Force(); Force(double fh, double fv); Force(double fh, double fv, double velocity, double sensibility); Force(Force force); static Force fromVector(double ox, double oy, double x, double y); void zero(); void setVelocity(double velocity); void setSensibility(double sensibility); void addDirection(double extrp, Direction direction); void addDirection(double extrp, double fh, double fv); void setDirection(Direction direction); void setDirection(double fh, double fv); void setDestination(double fh, double fv); void setDirectionMaximum(Direction max); void setDirectionMinimum(Direction min); double getVelocity(); double getSensibility(); boolean isDecreasingHorizontal(); boolean isIncreasingHorizontal(); @Override void update(double extrp); @Override double getDirectionHorizontal(); @Override double getDirectionVertical(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testZero() { final Force force = new Force(); force.setVelocity(1.0); force.setDestination(1.0, 2.0); force.update(1.0); assertForce(1.0, 1.0, 1.0, 0.0, force); force.zero(); assertForce(0.0, 0.0, 1.0, 0.0, force); } |
### Question:
Force implements Direction, Updatable { @Override public String toString() { return new StringBuilder(MIN_LENGTH).append(getClass().getSimpleName()) .append(" [fh=") .append(fh) .append(", fv=") .append(fv) .append(", velocity=") .append(velocity) .append(", sensibility=") .append(sensibility) .append("]") .toString(); } Force(); Force(double fh, double fv); Force(double fh, double fv, double velocity, double sensibility); Force(Force force); static Force fromVector(double ox, double oy, double x, double y); void zero(); void setVelocity(double velocity); void setSensibility(double sensibility); void addDirection(double extrp, Direction direction); void addDirection(double extrp, double fh, double fv); void setDirection(Direction direction); void setDirection(double fh, double fv); void setDestination(double fh, double fv); void setDirectionMaximum(Direction max); void setDirectionMinimum(Direction min); double getVelocity(); double getSensibility(); boolean isDecreasingHorizontal(); boolean isIncreasingHorizontal(); @Override void update(double extrp); @Override double getDirectionHorizontal(); @Override double getDirectionVertical(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testToString() { final Force force = new Force(1.0, 2.0, 3.0, 4.0); assertEquals("Force [fh=1.0, fv=2.0, velocity=3.0, sensibility=4.0]", force.toString()); } |
### Question:
Damages { public void setMin(int min) { this.min = UtilMath.clamp(min, 0, Integer.MAX_VALUE); max = UtilMath.clamp(max, this.min, Integer.MAX_VALUE); } Damages(); Damages(int min, int max); void setMin(int min); void setMax(int max); void setDamages(int min, int max); void setDamages(Range range); int getRandom(); int getLast(); int getMin(); int getMax(); Range getDamages(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testSetMin() { final Damages damages = new Damages(1, 5); assertEquals(1, damages.getMin()); assertEquals(5, damages.getMax()); damages.setMin(2); assertEquals(2, damages.getMin()); assertEquals(5, damages.getMax()); damages.setMin(6); assertEquals(6, damages.getMin()); assertEquals(6, damages.getMax()); } |
### Question:
Damages { public void setMax(int max) { this.max = UtilMath.clamp(max, min, Integer.MAX_VALUE); } Damages(); Damages(int min, int max); void setMin(int min); void setMax(int max); void setDamages(int min, int max); void setDamages(Range range); int getRandom(); int getLast(); int getMin(); int getMax(); Range getDamages(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testSetMax() { final Damages damages = new Damages(1, 5); assertEquals(1, damages.getMin()); assertEquals(5, damages.getMax()); damages.setMax(6); assertEquals(1, damages.getMin()); assertEquals(6, damages.getMax()); damages.setMax(0); assertEquals(1, damages.getMin()); assertEquals(1, damages.getMax()); } |
### Question:
Damages { public void setDamages(int min, int max) { this.min = UtilMath.clamp(min, 0, Integer.MAX_VALUE); this.max = UtilMath.clamp(max, this.min, Integer.MAX_VALUE); } Damages(); Damages(int min, int max); void setMin(int min); void setMax(int max); void setDamages(int min, int max); void setDamages(Range range); int getRandom(); int getLast(); int getMin(); int getMax(); Range getDamages(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testSetDamages() { final Damages damages = new Damages(); damages.setDamages(1, 5); assertEquals(1, damages.getMin()); assertEquals(5, damages.getMax()); } |
### Question:
Damages { public int getLast() { return last; } Damages(); Damages(int min, int max); void setMin(int min); void setMax(int max); void setDamages(int min, int max); void setDamages(Range range); int getRandom(); int getLast(); int getMin(); int getMax(); Range getDamages(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testGetLast() { final Damages damages = new Damages(1, 1); assertEquals(1, damages.getRandom()); assertEquals(1, damages.getLast()); } |
### Question:
Damages { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final Damages other = (Damages) object; return min == other.min && max == other.max; } Damages(); Damages(int min, int max); void setMin(int min); void setMax(int max); void setDamages(int min, int max); void setDamages(Range range); int getRandom(); int getLast(); int getMin(); int getMax(); Range getDamages(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testEquals() { final Damages damages = new Damages(1, 2); assertEquals(damages, damages); assertEquals(damages, new Damages(1, 2)); assertNotEquals(damages, null); assertNotEquals(damages, new Object()); assertNotEquals(damages, new Damages(2, 2)); assertNotEquals(damages, new Damages(1, 1)); } |
### Question:
Damages { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + min; result = prime * result + max; return result; } Damages(); Damages(int min, int max); void setMin(int min); void setMax(int max); void setDamages(int min, int max); void setDamages(Range range); int getRandom(); int getLast(); int getMin(); int getMax(); Range getDamages(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testHashCode() { final Damages damages = new Damages(1, 2); assertHashEquals(damages, new Damages(1, 2)); assertHashNotEquals(damages, new Object()); assertHashNotEquals(damages, new Damages(2, 2)); assertHashNotEquals(damages, new Damages(1, 1)); } |
### Question:
Damages { @Override public String toString() { return new StringBuilder(MIN_LENGHT).append(getClass().getSimpleName()) .append(" [min=") .append(min) .append(", max=") .append(max) .append("]") .toString(); } Damages(); Damages(int min, int max); void setMin(int min); void setMax(int max); void setDamages(int min, int max); void setDamages(Range range); int getRandom(); int getLast(); int getMin(); int getMax(); Range getDamages(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer:
@Test void testToString() { assertEquals("Damages [min=1, max=2]", new Damages(1, 2).toString()); } |
### Question:
BodyConfig { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final BodyConfig other = (BodyConfig) object; return Double.compare(getGravity(), other.getGravity()) == 0 && Double.compare(getGravityMax(), other.getGravityMax()) == 0; } BodyConfig(double gravity, double gravityMax); static BodyConfig imports(Configurer configurer); static void exports(Xml root, Body body); double getGravity(); double getGravityMax(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_BODY; static final String ATT_GRAVITY; static final String ATT_GRAVITY_MAX; }### Answer:
@Test void testEquals() { final BodyConfig config = new BodyConfig(1.0, 2.0); assertEquals(config, config); assertEquals(config, new BodyConfig(1.0, 2.0)); assertNotEquals(config, null); assertNotEquals(config, new Object()); assertNotEquals(config, new BodyConfig(2.0, 2.0)); assertNotEquals(config, new BodyConfig(1.0, 1.0)); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.