method2testcases
stringlengths
118
3.08k
### Question: BodyConfig { @Override public int hashCode() { final int prime = 31; int result = 1; long temp; temp = Double.doubleToLongBits(gravity); result = prime * result + (int) (temp ^ temp >>> 32); temp = Double.doubleToLongBits(gravityMax); result = prime * result + (int) (temp ^ temp >>> 32); return result; } 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 testHashCode() { final BodyConfig config = new BodyConfig(1.0, 2.0); assertHashEquals(config, config); assertHashEquals(config, new BodyConfig(1.0, 2.0)); assertHashNotEquals(config, new Object()); assertHashNotEquals(config, new BodyConfig(2.0, 2.0)); assertHashNotEquals(config, new BodyConfig(2.0, 1.0)); }
### Question: BodyConfig { @Override public String toString() { return new StringBuilder(MIN_LENGTH).append(getClass().getSimpleName()) .append(" [gravity=") .append(gravity) .append(", gravityMax=") .append(gravityMax) .append("]") .toString(); } 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 testToString() { final BodyConfig config = new BodyConfig(1.0, 2.0); assertEquals("BodyConfig [gravity=1.0, gravityMax=2.0]", config.toString()); }
### Question: Handler implements Handlables, Updatable, Renderable, IdentifiableListener, Listenable<HandlerListener> { @Override public final Featurable get(Integer id) { Featurable featurable = featurables.get(id); if (featurable == null) { featurable = toAdd.get(id); } if (featurable != null) { return featurable; } throw new LionEngineException(ERROR_FEATURABLE_NOT_FOUND + String.valueOf(id)); } Handler(Services services); final void addComponent(ComponentUpdater component); final void addComponent(ComponentRenderer component); final void add(Featurable featurable); final void remove(FeatureProvider featurable); final void removeAll(); final int size(); void updateAdd(); void updateRemove(); @Override final void addListener(HandlerListener listener); @Override final void removeListener(HandlerListener listener); @Override final Featurable get(Integer id); @Override Iterable<I> get(Class<I> type); @Override Iterable<Featurable> values(); @Override void update(double extrp); @Override void render(Graphic g); @Override final void notifyDestroyed(Integer id); }### Answer: @Test void testObjectIdNotFound() { assertThrows(() -> handler.get(Integer.valueOf(0)), Handler.ERROR_FEATURABLE_NOT_FOUND + 0); } @Test void testObjectTypeNotFound() { assertFalse(handler.get(Featurable.class).iterator().hasNext()); }
### Question: AnimatableModel extends FeatureModel implements Animatable, Recyclable { @Override public void play(Animation animation) { animator.play(animation); } AnimatableModel(Services services, Setup setup); AnimatableModel(Services services, Setup setup, Animator animator); @Override void addListener(AnimatorListener listener); @Override void removeListener(AnimatorListener listener); @Override void update(double extrp); @Override void play(Animation animation); @Override void stop(); @Override void reset(); @Override void setAnimSpeed(double speed); @Override void setFrame(int frame); @Override int getFrames(); @Override int getFrame(); @Override int getFrameAnim(); @Override AnimState getAnimState(); @Override boolean is(AnimState state); @Override void recycle(); }### Answer: @Test void testPlay() { final int first = 2; final int last = 4; final Animation animation = new Animation(Animation.DEFAULT_NAME, first, last, 1.0, false, false); final Animatable animatable = new AnimatableModel(services, setup); testAnimatorState(animatable, Animation.MINIMUM_FRAME, Animation.MINIMUM_FRAME, AnimState.STOPPED); assertEquals(1, animatable.getFrames()); animatable.play(animation); testAnimatorState(animatable, first, first, AnimState.PLAYING); assertFalse(animatable.is(AnimState.FINISHED)); assertEquals(last - first + 1, animatable.getFrames()); animatable.update(1.0); testAnimatorState(animatable, first, first + 1, AnimState.PLAYING); animatable.update(1.0); testAnimatorState(animatable, first, last, AnimState.PLAYING); animatable.update(1.0); testAnimatorState(animatable, first, last, AnimState.FINISHED); animatable.stop(); testAnimatorState(animatable, first, last, AnimState.STOPPED); }
### Question: AnimatableModel extends FeatureModel implements Animatable, Recyclable { @Override public void reset() { animator.reset(); } AnimatableModel(Services services, Setup setup); AnimatableModel(Services services, Setup setup, Animator animator); @Override void addListener(AnimatorListener listener); @Override void removeListener(AnimatorListener listener); @Override void update(double extrp); @Override void play(Animation animation); @Override void stop(); @Override void reset(); @Override void setAnimSpeed(double speed); @Override void setFrame(int frame); @Override int getFrames(); @Override int getFrame(); @Override int getFrameAnim(); @Override AnimState getAnimState(); @Override boolean is(AnimState state); @Override void recycle(); }### Answer: @Test void testReset() { final int first = 2; final int last = 4; final Animation animation = new Animation(Animation.DEFAULT_NAME, first, last, 1.0, false, false); final Animatable animatable = new AnimatableModel(services, setup); testAnimatorState(animatable, Animation.MINIMUM_FRAME, Animation.MINIMUM_FRAME, AnimState.STOPPED); animatable.play(animation); testAnimatorState(animatable, first, first, AnimState.PLAYING); animatable.reset(); testAnimatorState(animatable, 1, 1, AnimState.STOPPED); }
### Question: FeaturableModel extends FeaturableAbstract { @Override public Media getMedia() { return media; } FeaturableModel(Services services, Setup setup); @Override final void addFeature(Feature feature); @Override Media getMedia(); }### Answer: @Test void testAddFeatures() { final Media media = Medias.create("Features.xml"); final Xml root = new Xml(FeaturableConfig.NODE_FEATURABLE); final Xml unknown = root.createChild(FeaturableConfig.NODE_FEATURE); unknown.setText(MyFeature.class.getName()); root.save(media); Featurable featurable = new FeaturableModel(new Services(), new Setup(media)); featurable.checkListener(featurable); assertEquals(media, featurable.getMedia()); for (final Feature next : featurable.getFeatures()) { assertTrue(MyFeature.class.equals(next.getClass()) || Identifiable.class.isAssignableFrom(next.getClass()) || Recycler.class.isAssignableFrom(next.getClass()), next.getClass().getName()); } featurable = new FeaturableModel(new Services(), new Setup(media)); UtilFile.deleteFile(media.getFile()); }
### Question: ProducerModel extends FeatureModel implements Producer, Recyclable { @Override public void update(double extrp) { switch (state) { case NONE: progress = -1; break; case WILL_PRODUCE: actionWillProduce(); break; case PRODUCING: actionProducing(); break; case PRODUCED: actionProduced(); break; case CHECK: actionCheck(); break; default: throw new LionEngineException(state); } } ProducerModel(Services services, Setup setup); @Override void prepare(FeatureProvider provider); @Override void checkListener(Object listener); @Override void addListener(ProducerListener listener); @Override void removeListener(ProducerListener listener); @Override void setChecker(ProducerChecker checker); @Override void addToProductionQueue(Featurable featurable); @Override void update(double extrp); @Override void skipProduction(); @Override void stopProduction(); @Override void setStepsSpeed(double stepsPerTick); @Override double getProgress(); @Override int getProgressPercent(); @Override Featurable getProducingElement(); @Override Iterator<Featurable> iterator(); @Override int getQueueLength(); @Override boolean isProducing(); @Override void recycle(); }### Answer: @Test void testEnumFail() throws ReflectiveOperationException { final ProducerModel producer = new ProducerModel(services, setup); final Field field = producer.getClass().getDeclaredField("state"); UtilReflection.setAccessible(field, true); field.set(producer, ProducerState.values()[5]); assertThrows(() -> producer.update(1.0), "Unknown enum: FAIL"); }
### Question: ProducibleConfig { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final ProducibleConfig other = (ProducibleConfig) object; return steps == other.steps && width == other.width && height == other.height; } ProducibleConfig(int steps, int width, int height); static ProducibleConfig imports(Configurer configurer); static ProducibleConfig imports(Xml root); static Xml exports(ProducibleConfig config); int getWidth(); int getHeight(); int getSteps(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_PRODUCIBLE; static final String ATT_STEPS; }### Answer: @Test void testEquals() { final ProducibleConfig producible = new ProducibleConfig(1, 2, 3); assertEquals(producible, producible); assertNotEquals(producible, null); assertNotEquals(producible, new Object()); assertNotEquals(producible, new ProducibleConfig(0, 2, 3)); assertNotEquals(producible, new ProducibleConfig(1, 0, 3)); assertNotEquals(producible, new ProducibleConfig(1, 2, 0)); }
### Question: ProducibleConfig { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + steps; result = prime * result + width; result = prime * result + height; return result; } ProducibleConfig(int steps, int width, int height); static ProducibleConfig imports(Configurer configurer); static ProducibleConfig imports(Xml root); static Xml exports(ProducibleConfig config); int getWidth(); int getHeight(); int getSteps(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_PRODUCIBLE; static final String ATT_STEPS; }### Answer: @Test void testHashCode() { final ProducibleConfig hash = new ProducibleConfig(1, 2, 3); assertHashEquals(hash, new ProducibleConfig(1, 2, 3)); assertHashNotEquals(hash, new ProducibleConfig(0, 2, 3)); assertHashNotEquals(hash, new ProducibleConfig(1, 0, 3)); assertHashNotEquals(hash, new ProducibleConfig(1, 2, 0)); }
### Question: ProducibleConfig { @Override public String toString() { return new StringBuilder(MIN_LENGTH).append(getClass().getSimpleName()) .append(" [steps=") .append(steps) .append(", width=") .append(width) .append(", height=") .append(height) .append("]") .toString(); } ProducibleConfig(int steps, int width, int height); static ProducibleConfig imports(Configurer configurer); static ProducibleConfig imports(Xml root); static Xml exports(ProducibleConfig config); int getWidth(); int getHeight(); int getSteps(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_PRODUCIBLE; static final String ATT_STEPS; }### Answer: @Test void testToString() { final ProducibleConfig producible = new ProducibleConfig(1, 2, 3); assertEquals("ProducibleConfig [steps=1, width=2, height=3]", producible.toString()); }
### Question: ActionRef { @Override public String toString() { return new StringBuilder().append(getClass().getSimpleName()) .append(" [path=") .append(path) .append(", cancel=") .append(cancel) .append(", refs=") .append(refs) .append("]") .toString(); } ActionRef(String path, boolean cancel, Collection<ActionRef> refs); ActionRef(String path, boolean cancel, Collection<ActionRef> refs, Function<Class<? extends Feature>, Feature> id); String getPath(); boolean hasCancel(); boolean isUnique(); Collection<ActionRef> getRefs(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); }### Answer: @Test void testToString() { assertEquals("ActionRef [path=path2, cancel=true, refs=[ActionRef [path=path, cancel=false, refs=[]]]]", actionRef2.toString()); }
### Question: UtilMath { public static int wrap(int value, int min, int max) { int newValue = value; final int step = max - min; if (newValue >= max) { while (newValue >= max) { newValue -= step; } } else if (newValue < min) { while (newValue < min) { newValue += step; } } return newValue; } 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 testWrap() { assertEquals(0, UtilMath.wrap(360, 0, 360)); assertEquals(359, UtilMath.wrap(-1, 0, 360)); assertEquals(180, UtilMath.wrap(180, 0, 360)); }
### Question: Timing { public void unpause() { cur += systemTime() - back; back = 0L; } 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 testUnpause() { timing.start(); timing.pause(); UtilTests.pause(PAUSE); final long old = timing.get(); final long elapsed = timing.elapsed(); timing.unpause(); UtilTests.pause(PAUSE); assertTrue(timing.elapsed(PAUSE), String.valueOf(timing.elapsed())); assertTrue(timing.get() > old, timing + " " + timing.elapsed()); assertTrue(timing.elapsed() > elapsed, timing + " " + timing.elapsed()); }
### Question: ActionConfig { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final ActionConfig other = (ActionConfig) object; return other.x == x && other.y == y && other.width == width && other.height == height && other.name.equals(name) && other.description.equals(description); } ActionConfig(String name, String description, int x, int y, int width, int height); static ActionConfig imports(Configurer configurer); static ActionConfig imports(Xml root); static Xml exports(ActionConfig config); String getName(); String getDescription(); int getX(); int getY(); int getWidth(); int getHeight(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_ACTION; static final String ATT_NAME; static final String ATT_DESCRIPTION; static final String ATT_X; static final String ATT_Y; static final String ATT_WIDTH; static final String ATT_HEIGHT; }### Answer: @Test void testEquals() { final ActionConfig action = new ActionConfig("a", "b", 0, 1, 2, 3); assertEquals(action, action); assertNotEquals(action, null); assertNotEquals(action, new Object()); assertNotEquals(action, new ActionConfig("", "b", 0, 1, 2, 3)); assertNotEquals(action, new ActionConfig("a", "", 0, 1, 2, 3)); assertNotEquals(action, new ActionConfig("a", "b", -1, 1, 2, 3)); assertNotEquals(action, new ActionConfig("a", "b", 0, -1, 2, 3)); assertNotEquals(action, new ActionConfig("a", "b", 0, 1, -1, 3)); assertNotEquals(action, new ActionConfig("a", "b", 0, 1, 2, -1)); }
### Question: ActionConfig { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + x; result = prime * result + y; result = prime * result + width; result = prime * result + height; result = prime * result + name.hashCode(); result = prime * result + description.hashCode(); return result; } ActionConfig(String name, String description, int x, int y, int width, int height); static ActionConfig imports(Configurer configurer); static ActionConfig imports(Xml root); static Xml exports(ActionConfig config); String getName(); String getDescription(); int getX(); int getY(); int getWidth(); int getHeight(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_ACTION; static final String ATT_NAME; static final String ATT_DESCRIPTION; static final String ATT_X; static final String ATT_Y; static final String ATT_WIDTH; static final String ATT_HEIGHT; }### Answer: @Test void testHashCode() { final ActionConfig action = new ActionConfig("a", "b", 0, 1, 2, 3); assertHashEquals(action, new ActionConfig("a", "b", 0, 1, 2, 3)); assertHashNotEquals(action, new ActionConfig("", "b", 0, 1, 2, 3)); assertHashNotEquals(action, new ActionConfig("a", "", 0, 1, 2, 3)); assertHashNotEquals(action, new ActionConfig("a", "b", -1, 1, 2, 3)); assertHashNotEquals(action, new ActionConfig("a", "b", 0, -1, 2, 3)); assertHashNotEquals(action, new ActionConfig("a", "b", 0, 1, -1, 3)); assertHashNotEquals(action, new ActionConfig("a", "b", 0, 1, 2, -1)); }
### Question: ActionConfig { @Override public String toString() { return new StringBuilder(MIN_LENGTH).append(getClass().getSimpleName()) .append(" [name=") .append(name) .append(", description=") .append(description) .append(", x=") .append(x) .append(", y=") .append(y) .append(", width=") .append(width) .append(", height=") .append(height) .append("]") .toString(); } ActionConfig(String name, String description, int x, int y, int width, int height); static ActionConfig imports(Configurer configurer); static ActionConfig imports(Xml root); static Xml exports(ActionConfig config); String getName(); String getDescription(); int getX(); int getY(); int getWidth(); int getHeight(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_ACTION; static final String ATT_NAME; static final String ATT_DESCRIPTION; static final String ATT_X; static final String ATT_Y; static final String ATT_WIDTH; static final String ATT_HEIGHT; }### Answer: @Test void testToString() { final ActionConfig action = new ActionConfig("a", "b", 0, 1, 2, 3); assertEquals("ActionConfig [name=a, description=b, x=0, y=1, width=2, height=3]", action.toString()); }
### Question: StateConfig { public static Optional<String> imports(Configurer configurer) { Check.notNull(configurer); return imports(configurer.getRoot()); } private StateConfig(); static Optional<String> imports(Configurer configurer); static Optional<String> imports(Xml root); static Xml exports(Class<?> state); static final String NODE_STATE; }### Answer: @Test void testNoNode() { final Xml root = new Xml("test"); assertFalse(StateConfig.imports(root).isPresent()); }
### Question: StateHandler extends FeatureModel implements Updatable, Recyclable, Listenable<StateTransitionListener> { public void changeState(Class<? extends State> next) { Check.notNull(next); this.next = next; } StateHandler(Services services, Setup setup); @SuppressWarnings("unchecked") StateHandler(Services services, Setup setup, Function<Class<? extends State>, String> converter); void changeState(Class<? extends State> next); boolean isState(Class<? extends State> state); void postUpdate(); @Override void addListener(StateTransitionListener listener); @Override void removeListener(StateTransitionListener listener); @Override void update(double extrp); @Override void recycle(); }### Answer: @Test void testNullArgument() { final StateHandler handler = new StateHandler(services, setup); assertThrows(() -> handler.changeState(null), "Unexpected null argument !"); }
### Question: LayerableConfig { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final LayerableConfig other = (LayerableConfig) object; return layerRefresh == other.layerRefresh && layerDisplay == other.layerDisplay; } LayerableConfig(int layerRefresh, int layerDisplay); static LayerableConfig imports(Configurer configurer); static LayerableConfig imports(Xml root); static Xml exports(LayerableConfig config); int getLayerRefresh(); int getLayerDisplay(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_LAYERABLE; static final String ATT_REFRESH; static final String ATT_DISPLAY; }### Answer: @Test void testEquals() { final LayerableConfig config = new LayerableConfig(0, 1); assertEquals(config, config); assertEquals(config, new LayerableConfig(0, 1)); assertNotEquals(config, null); assertNotEquals(config, new Object()); assertNotEquals(config, new LayerableConfig(1, 1)); assertNotEquals(config, new LayerableConfig(0, 0)); assertNotEquals(config, new LayerableConfig(1, 0)); }
### Question: LayerableConfig { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + layerRefresh; result = prime * result + layerDisplay; return result; } LayerableConfig(int layerRefresh, int layerDisplay); static LayerableConfig imports(Configurer configurer); static LayerableConfig imports(Xml root); static Xml exports(LayerableConfig config); int getLayerRefresh(); int getLayerDisplay(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_LAYERABLE; static final String ATT_REFRESH; static final String ATT_DISPLAY; }### Answer: @Test void testHashCode() { final LayerableConfig hash = new LayerableConfig(0, 1); assertHashEquals(hash, new LayerableConfig(0, 1)); assertHashNotEquals(hash, new LayerableConfig(1, 1)); assertHashNotEquals(hash, new LayerableConfig(0, 0)); assertHashNotEquals(hash, new LayerableConfig(1, 0)); }
### Question: LayerableConfig { @Override public String toString() { return new StringBuilder(MIN_LENGTH).append(getClass().getSimpleName()) .append(" [layerRefresh=") .append(layerRefresh) .append(", layerDisplay=") .append(layerDisplay) .append("]") .toString(); } LayerableConfig(int layerRefresh, int layerDisplay); static LayerableConfig imports(Configurer configurer); static LayerableConfig imports(Xml root); static Xml exports(LayerableConfig config); int getLayerRefresh(); int getLayerDisplay(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_LAYERABLE; static final String ATT_REFRESH; static final String ATT_DISPLAY; }### Answer: @Test void testToString() { final LayerableConfig config = new LayerableConfig(0, 1); assertEquals("LayerableConfig [layerRefresh=0, layerDisplay=1]", config.toString()); }
### Question: Services { public <S> S create(Class<S> service) { Check.notNull(service); try { final S instance = UtilReflection.create(service, new Class<?>[] { Services.class }, this); return add(instance); } catch (@SuppressWarnings("unused") final NoSuchMethodException exception) { try { final S instance = service.newInstance(); return add(instance); } catch (final IllegalAccessException exception2) { throw new LionEngineException(exception2, ERROR_SERVICE_NO_CONSTRUCTOR + service); } catch (final InstantiationException exception2) { throw new LionEngineException(exception2, ERROR_SERVICE_CREATE + service); } } } Services(); S create(Class<S> service); S add(S service); S get(Class<S> service); Optional<S> getOptional(Class<S> service); }### Answer: @Test void testServiceNoConstructor() { final Services services = new Services(); assertCause(() -> services.create(NoConstructorService.class), IllegalAccessException.class); } @Test void testServiceInvalidConstructor() { final Services services = new Services(); assertCause(() -> services.create(InvalidConstructorService.class), InstantiationException.class); }
### Question: UtilMath { public static int wrapAngle(int angle) { return wrap(angle, 0, Constant.ANGLE_MAX); } 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 testWrapAngle() { assertEquals(0, UtilMath.wrapAngle(360)); assertEquals(359, UtilMath.wrapAngle(-1)); assertEquals(180, UtilMath.wrapAngle(180)); }
### Question: Services { public <S> S get(Class<S> service) { final S instance = getService(service); if (instance == null) { throw new LionEngineException(ERROR_SERVICE_GET + service.getName()); } return instance; } Services(); S create(Class<S> service); S add(S service); S get(Class<S> service); Optional<S> getOptional(Class<S> service); }### Answer: @Test void testNotFound() { final Services services = new Services(); assertThrows(() -> services.get(Camera.class), Services.ERROR_SERVICE_GET + Camera.class.getName()); } @Test void testNull() { final Services services = new Services(); assertThrows(() -> services.get(null), "Unexpected null argument !"); }
### Question: CollisionCouple { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final CollisionCouple other = (CollisionCouple) object; return with.equals(other.with) && by.equals(other.by); } CollisionCouple(Collision with, Collision by); Collision getWith(); Collision getBy(); @Override int hashCode(); @Override boolean equals(Object object); }### Answer: @Test void testEquals() { final Collision with = new Collision("with", 1, 2, 3, 4, true); final Collision by = new Collision("by", 1, 2, 3, 4, true); final CollisionCouple couple = new CollisionCouple(with, by); assertEquals(couple, couple); assertEquals(couple, new CollisionCouple(with, by)); assertNotEquals(couple, null); assertNotEquals(couple, new Object()); assertNotEquals(couple, new CollisionCouple(with, with)); assertNotEquals(couple, new CollisionCouple(by, with)); }
### Question: CollisionCouple { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + by.hashCode(); result = prime * result + with.hashCode(); return result; } CollisionCouple(Collision with, Collision by); Collision getWith(); Collision getBy(); @Override int hashCode(); @Override boolean equals(Object object); }### Answer: @Test void testHashCode() { final Collision with = new Collision("with", 1, 2, 3, 4, true); final Collision by = new Collision("by", 1, 2, 3, 4, true); final CollisionCouple couple = new CollisionCouple(with, by); assertHashEquals(couple, new CollisionCouple(with, by)); assertHashNotEquals(couple, new Object()); assertHashNotEquals(couple, new CollisionCouple(with, with)); assertHashNotEquals(couple, new CollisionCouple(by, with)); }
### Question: CollisionConfig { public Collision getCollision(String name) { if (collisions.containsKey(name)) { return collisions.get(name); } throw new LionEngineException(ERROR_COLLISION_NOT_FOUND + name); } CollisionConfig(Map<String, Collision> collisions); static CollisionConfig imports(Configurer configurer); static CollisionConfig imports(Xml root); static Collision createCollision(XmlReader node); static void exports(Xml root, Collision collision); Collision getCollision(String name); Collection<Collision> getCollisions(); static final String NODE_COLLISIONS; static final String NODE_COLLISION; static final String ATT_NAME; static final String ATT_OFFSETX; static final String ATT_OFFSETY; static final String ATT_WIDTH; static final String ATT_HEIGHT; static final String ATT_MIRROR; }### Answer: @Test void testGetUnknownCollision() { final CollisionConfig config = new CollisionConfig(new HashMap<>()); assertThrows(() -> config.getCollision("void"), CollisionConfig.ERROR_COLLISION_NOT_FOUND + "void"); }
### Question: CollidableFramedConfig { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final CollidableFramedConfig other = (CollidableFramedConfig) object; return collisions.equals(other.collisions); } CollidableFramedConfig(Map<Integer, Collection<Collision>> collisions); static CollidableFramedConfig imports(Configurer configurer); static CollidableFramedConfig imports(Xml root); static void exports(Xml root, Map<Integer, Collection<Collision>> collisions); Collection<Collision> getCollision(Integer frame); Collection<Collision> getCollisions(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_COLLISION_FRAMED; static final String ATT_PREFIX; static final String ATT_NUMBER; static final String ATT_OFFSETX; static final String ATT_OFFSETY; static final String ATT_WIDTH; static final String ATT_HEIGHT; static final String ATT_MIRROR; }### Answer: @Test void testEquals() { final Map<Integer, Collection<Collision>> collisions = new HashMap<>(); collisions.put(Integer.valueOf(1), Arrays.asList(new Collision("anim%1", 0, 1, 2, 3, true))); collisions.put(Integer.valueOf(2), Arrays.asList(new Collision("anim%2", 3, 2, 1, 0, false))); final CollidableFramedConfig config = new CollidableFramedConfig(collisions); assertEquals(config, config); assertEquals(config, new CollidableFramedConfig(collisions)); assertNotEquals(config, null); assertNotEquals(config, new Object()); assertNotEquals(config, new CollidableFramedConfig(new HashMap<>())); }
### Question: CollidableFramedConfig { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + collisions.hashCode(); return result; } CollidableFramedConfig(Map<Integer, Collection<Collision>> collisions); static CollidableFramedConfig imports(Configurer configurer); static CollidableFramedConfig imports(Xml root); static void exports(Xml root, Map<Integer, Collection<Collision>> collisions); Collection<Collision> getCollision(Integer frame); Collection<Collision> getCollisions(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_COLLISION_FRAMED; static final String ATT_PREFIX; static final String ATT_NUMBER; static final String ATT_OFFSETX; static final String ATT_OFFSETY; static final String ATT_WIDTH; static final String ATT_HEIGHT; static final String ATT_MIRROR; }### Answer: @Test void testHashCode() { final Map<Integer, Collection<Collision>> collisions = new HashMap<>(); collisions.put(Integer.valueOf(1), Arrays.asList(new Collision("anim%1", 0, 1, 2, 3, true))); collisions.put(Integer.valueOf(2), Arrays.asList(new Collision("anim%2", 3, 2, 1, 0, false))); final CollidableFramedConfig config = new CollidableFramedConfig(collisions); assertHashEquals(config, config); assertHashEquals(config, new CollidableFramedConfig(collisions)); assertHashNotEquals(config, new Object()); assertHashNotEquals(config, new CollidableFramedConfig(new HashMap<>())); }
### Question: CollidableFramedConfig { @Override public String toString() { return new StringBuilder(MIN_LENGTH).append(getClass().getSimpleName()).append(collisions).toString(); } CollidableFramedConfig(Map<Integer, Collection<Collision>> collisions); static CollidableFramedConfig imports(Configurer configurer); static CollidableFramedConfig imports(Xml root); static void exports(Xml root, Map<Integer, Collection<Collision>> collisions); Collection<Collision> getCollision(Integer frame); Collection<Collision> getCollisions(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_COLLISION_FRAMED; static final String ATT_PREFIX; static final String ATT_NUMBER; static final String ATT_OFFSETX; static final String ATT_OFFSETY; static final String ATT_WIDTH; static final String ATT_HEIGHT; static final String ATT_MIRROR; }### Answer: @Test void testToString() { final Map<Integer, Collection<Collision>> collisions = new HashMap<>(); collisions.put(Integer.valueOf(1), Arrays.asList(new Collision("anim%1", 0, 1, 2, 3, true))); final CollidableFramedConfig config = new CollidableFramedConfig(collisions); assertEquals("CollidableFramedConfig" + "{1=[Collision [name=anim%1, offsetX=0, offsetY=1, width=2, height=3, mirror=true]]}", config.toString()); }
### Question: UtilMath { public static double wrapDouble(double value, double min, double max) { double newValue = value; final double step = max - min; if (Double.compare(newValue, max) >= 0) { while (Double.compare(newValue, max) >= 0) { newValue -= step; } } else if (newValue < min) { while (newValue < min) { newValue += step; } } return newValue; } 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 testWrapDouble() { assertEquals(0.0, UtilMath.wrapDouble(360.0, 0.0, 360.0)); assertEquals(359.0, UtilMath.wrapDouble(-1.0, 0.0, 360.0)); assertEquals(180.0, UtilMath.wrapDouble(180.0, 0.0, 360.0)); }
### Question: ComponentCollision implements ComponentUpdater, HandlerListener, TransformableListener { public Collection<Collidable> getInside(Area area) { final Collection<Collidable> inside = new HashSet<>(); final Collection<Point> points = getPoints(area); for (final Map<Point, Set<Collidable>> groups : collidables.values()) { for (final Point point : points) { final Collection<Collidable> elements = groups.get(point); if (elements != null) { checkInside(elements, area, inside); } } } return inside; } ComponentCollision(); Collection<Collidable> getInside(Area area); @Override void update(double extrp, Handlables objects); @Override void notifyHandlableAdded(Featurable featurable); @Override void notifyHandlableRemoved(Featurable featurable); @Override void notifyTransformed(Transformable transformable); }### Answer: @Test void testGetInside() { transformable1.teleport(20.0, 20.0); transformable2.teleport(30.0, 30.0); handler.update(1.0); assertTrue(component.getInside(Geom.createArea(0, 0, 16, 16)).isEmpty()); assertEquals(2, component.getInside(Geom.createArea(15, 15, 32, 32)).size()); }
### Question: Collision extends NameableAbstract { public Collision(String name, int offsetX, int offsetY, int width, int height, boolean mirror) { super(name); this.offsetX = offsetX; this.offsetY = offsetY; this.width = width; this.height = height; this.mirror = mirror; } Collision(String name, int offsetX, int offsetY, int width, int height, boolean mirror); int getOffsetX(); int getOffsetY(); int getWidth(); int getHeight(); boolean hasMirror(); @Override String toString(); static final Collision AUTOMATIC; }### Answer: @Test void testCollision() { final Collision collision = new Collision("void", 1, 2, 3, 4, true); assertEquals("void", collision.getName()); assertTrue(collision.getOffsetX() == 1); assertTrue(collision.getOffsetY() == 2); assertTrue(collision.getWidth() == 3); assertTrue(collision.getHeight() == 4); assertTrue(collision.hasMirror()); }
### Question: Collision extends NameableAbstract { @Override public String toString() { return new StringBuilder(MIN_LENGTH).append(getClass().getSimpleName()) .append(" [name=") .append(getName()) .append(", offsetX=") .append(offsetX) .append(", offsetY=") .append(offsetY) .append(", width=") .append(width) .append(", height=") .append(height) .append(", mirror=") .append(mirror) .append("]") .toString(); } Collision(String name, int offsetX, int offsetY, int width, int height, boolean mirror); int getOffsetX(); int getOffsetY(); int getWidth(); int getHeight(); boolean hasMirror(); @Override String toString(); static final Collision AUTOMATIC; }### Answer: @Test void testToString() { final Collision collision = new Collision("void", 0, 2, 3, 4, true); assertEquals("Collision [name=void, offsetX=0, offsetY=2, width=3, height=4, mirror=true]", collision.toString()); }
### Question: CollidableModel extends FeatureModel implements Collidable, Recyclable, TransformableListener, IdentifiableListener { @Override public void notifyCollided(Collidable collidable, Collision with, Collision by) { for (int i = 0; i < listenable.size(); i++) { listenable.get(i).notifyCollided(collidable, with, by); } } CollidableModel(Services services, Setup setup); @Override void prepare(FeatureProvider provider); @Override void checkListener(Object listener); @Override void addListener(CollidableListener listener); @Override void removeListener(CollidableListener listener); @Override void addCollision(Collision collision); @Override void addAccept(Integer group); @Override void removeAccept(Integer group); @Override void forceUpdate(); @Override List<CollisionCouple> collide(Collidable other); @Override void render(Graphic g); @Override void setGroup(Integer group); @Override void setOrigin(Origin origin); @Override void setEnabled(boolean enabled, Collision collision); @Override void setEnabled(boolean enabled); @Override void setCollisionVisibility(boolean visible); @Override boolean isEnabled(); @Override List<Collision> getCollisions(); @Override List<Rectangle> getCollisionBounds(); @Override void notifyCollided(Collidable collidable, Collision with, Collision by); @Override Integer getGroup(); @Override Collection<Integer> getAccepted(); @Override int getMaxWidth(); @Override int getMaxHeight(); @Override Origin getOrigin(); @Override void recycle(); @Override void notifyTransformed(Transformable transformable); @Override void notifyDestroyed(Integer id); @Override boolean isEnabled(Collision collision); }### Answer: @Test void testListenerVoid() { assertNotNull(CollidableListenerVoid.getInstance()); CollidableListenerVoid.getInstance().notifyCollided(null, null, null); }
### Question: CollidableConfig { public static CollidableConfig imports(Configurer configurer) { Check.notNull(configurer); if (configurer.hasNode(NODE_COLLIDABLE)) { final Integer group = Integer.valueOf(configurer.getIntegerDefault(DEFAULT_GROUP.intValue(), ATT_GROUP, NODE_COLLIDABLE)); final String accepted = configurer.getStringDefault(Constant.EMPTY_STRING, ATT_ACCEPTED, NODE_COLLIDABLE); final Collection<Integer> acceptedGroups; if (accepted.isEmpty()) { acceptedGroups = new ArrayList<>(); } else { acceptedGroups = Arrays.asList(ACCEPTED_SEPARATOR_PATTERN.split(accepted)) .stream() .map(Integer::valueOf) .collect(Collectors.toSet()); } return new CollidableConfig(group, acceptedGroups); } return new CollidableConfig(DEFAULT_GROUP, Collections.emptySet()); } CollidableConfig(Integer group, Collection<Integer> accepted); static CollidableConfig imports(Configurer configurer); static void exports(Xml root, Collidable collidable); Integer getGroup(); Collection<Integer> getAccepted(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_COLLIDABLE; static final String ATT_GROUP; static final String ATT_ACCEPTED; static final Integer DEFAULT_GROUP; }### Answer: @Test void testInvalidGroup() { final Media media = Medias.create("Object.xml"); final Xml root = new Xml("test"); final Xml node = root.createChild(CollidableConfig.NODE_COLLIDABLE); node.writeString(CollidableConfig.ATT_GROUP, "a"); root.save(media); assertCause(() -> CollidableConfig.imports(new Configurer(media)), NumberFormatException.class); assertTrue(media.getFile().delete()); }
### Question: CollidableConfig { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final CollidableConfig other = (CollidableConfig) object; return group.equals(other.getGroup()) && accepted.containsAll(other.getAccepted()) && other.getAccepted().containsAll(accepted); } CollidableConfig(Integer group, Collection<Integer> accepted); static CollidableConfig imports(Configurer configurer); static void exports(Xml root, Collidable collidable); Integer getGroup(); Collection<Integer> getAccepted(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_COLLIDABLE; static final String ATT_GROUP; static final String ATT_ACCEPTED; static final Integer DEFAULT_GROUP; }### Answer: @Test void testEquals() { final CollidableConfig config = new CollidableConfig(Integer.valueOf(1), Arrays.asList(Integer.valueOf(2))); assertEquals(config, config); assertEquals(config, new CollidableConfig(Integer.valueOf(1), Arrays.asList(Integer.valueOf(2)))); assertNotEquals(config, null); assertNotEquals(config, new Object()); assertNotEquals(config, new CollidableConfig(Integer.valueOf(0), Arrays.asList(Integer.valueOf(2)))); assertNotEquals(config, new CollidableConfig(Integer.valueOf(1), Collections.emptyList())); assertNotEquals(config, new CollidableConfig(Integer.valueOf(1), Arrays.asList(Integer.valueOf(0)))); }
### Question: CollidableConfig { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + group.hashCode(); result = prime * result + accepted.hashCode(); return result; } CollidableConfig(Integer group, Collection<Integer> accepted); static CollidableConfig imports(Configurer configurer); static void exports(Xml root, Collidable collidable); Integer getGroup(); Collection<Integer> getAccepted(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_COLLIDABLE; static final String ATT_GROUP; static final String ATT_ACCEPTED; static final Integer DEFAULT_GROUP; }### Answer: @Test void testHashCode() { final CollidableConfig config = new CollidableConfig(Integer.valueOf(1), Arrays.asList(Integer.valueOf(2))); assertHashEquals(config, config); assertHashEquals(config, new CollidableConfig(Integer.valueOf(1), Arrays.asList(Integer.valueOf(2)))); assertHashNotEquals(config, new Object()); assertHashNotEquals(config, new CollidableConfig(Integer.valueOf(0), Arrays.asList(Integer.valueOf(2)))); assertHashNotEquals(config, new CollidableConfig(Integer.valueOf(1), Collections.emptyList())); assertHashNotEquals(config, new CollidableConfig(Integer.valueOf(1), Arrays.asList(Integer.valueOf(0)))); }
### Question: UtilMath { public static int getSign(double value) { final int sign; if (value > 0) { sign = 1; } else if (value < 0) { sign = -1; } else { sign = 0; } return sign; } 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 testSign() { assertEquals(-1, UtilMath.getSign(-1.0)); assertEquals(1, UtilMath.getSign(1.0)); assertEquals(0, UtilMath.getSign(0)); }
### Question: CollidableConfig { @Override public String toString() { return new StringBuilder(MIN_LENGTH).append(getClass().getSimpleName()) .append(" [group=") .append(group) .append(", accepted=") .append(accepted) .append("]") .toString(); } CollidableConfig(Integer group, Collection<Integer> accepted); static CollidableConfig imports(Configurer configurer); static void exports(Xml root, Collidable collidable); Integer getGroup(); Collection<Integer> getAccepted(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_COLLIDABLE; static final String ATT_GROUP; static final String ATT_ACCEPTED; static final Integer DEFAULT_GROUP; }### Answer: @Test void testToString() { final CollidableConfig config = new CollidableConfig(Integer.valueOf(1), Arrays.asList(Integer.valueOf(2))); assertEquals(CollidableConfig.class.getSimpleName() + " [group=1, accepted=[2]]", config.toString()); }
### Question: FeaturableConfig { public static FeaturableConfig imports(Configurer configurer) { Check.notNull(configurer); return imports(configurer.getRoot()); } FeaturableConfig(String clazz, String setup); static void clearCache(); static FeaturableConfig imports(Configurer configurer); static FeaturableConfig imports(Xml root); static Xml exportClass(String clazz); static Xml exportSetup(String setup); static List<Feature> getFeatures(ClassLoader loader, Services services, Setup setup); String getClassName(); String getSetupName(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String DEFAULT_FILENAME; static final String NODE_FEATURABLE; static final String ATT_CLASS; static final String ATT_SETUP; static final String NODE_FEATURES; static final String NODE_FEATURE; }### Answer: @Test void testDefaultClass() { final Xml root = new Xml("test"); final Media media = Medias.create("Object.xml"); root.save(media); assertEquals(new FeaturableConfig(FeaturableModel.class.getName(), ""), FeaturableConfig.imports(new Xml(media))); assertTrue(media.getFile().delete()); }
### Question: FeaturableConfig { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final FeaturableConfig other = (FeaturableConfig) object; return clazz.equals(other.clazz) && setup.equals(other.setup); } FeaturableConfig(String clazz, String setup); static void clearCache(); static FeaturableConfig imports(Configurer configurer); static FeaturableConfig imports(Xml root); static Xml exportClass(String clazz); static Xml exportSetup(String setup); static List<Feature> getFeatures(ClassLoader loader, Services services, Setup setup); String getClassName(); String getSetupName(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String DEFAULT_FILENAME; static final String NODE_FEATURABLE; static final String ATT_CLASS; static final String ATT_SETUP; static final String NODE_FEATURES; static final String NODE_FEATURE; }### Answer: @Test void testEquals() { final FeaturableConfig config = new FeaturableConfig("class", "setup"); assertEquals(config, config); assertEquals(config, new FeaturableConfig("class", "setup")); assertNotEquals(config, null); assertNotEquals(config, new Object()); assertNotEquals(config, new FeaturableConfig("", "setup")); assertNotEquals(config, new FeaturableConfig("class", "")); }
### Question: FeaturableConfig { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + clazz.hashCode(); result = prime * result + setup.hashCode(); return result; } FeaturableConfig(String clazz, String setup); static void clearCache(); static FeaturableConfig imports(Configurer configurer); static FeaturableConfig imports(Xml root); static Xml exportClass(String clazz); static Xml exportSetup(String setup); static List<Feature> getFeatures(ClassLoader loader, Services services, Setup setup); String getClassName(); String getSetupName(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String DEFAULT_FILENAME; static final String NODE_FEATURABLE; static final String ATT_CLASS; static final String ATT_SETUP; static final String NODE_FEATURES; static final String NODE_FEATURE; }### Answer: @Test void testHashCode() { final FeaturableConfig hash = new FeaturableConfig("class", "setup"); assertHashEquals(hash, new FeaturableConfig("class", "setup")); assertHashNotEquals(hash, new FeaturableConfig("", "setup")); assertHashNotEquals(hash, new FeaturableConfig("class", "")); }
### Question: FeaturableConfig { @Override public String toString() { return new StringBuilder(MIN_LENGTH).append(getClass().getSimpleName()) .append(" [clazz=") .append(clazz) .append(", setup=") .append(setup) .append("]") .toString(); } FeaturableConfig(String clazz, String setup); static void clearCache(); static FeaturableConfig imports(Configurer configurer); static FeaturableConfig imports(Xml root); static Xml exportClass(String clazz); static Xml exportSetup(String setup); static List<Feature> getFeatures(ClassLoader loader, Services services, Setup setup); String getClassName(); String getSetupName(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String DEFAULT_FILENAME; static final String NODE_FEATURABLE; static final String ATT_CLASS; static final String ATT_SETUP; static final String NODE_FEATURES; static final String NODE_FEATURE; }### Answer: @Test void testToString() { final FeaturableConfig config = new FeaturableConfig("clazz", "setup"); assertEquals("FeaturableConfig [clazz=clazz, setup=setup]", config.toString()); }
### Question: TransformableModel extends FeatureModel implements Transformable, Recyclable { @Override public void teleport(double x, double y) { mover.teleport(x, y); notifyTransformed(true); } TransformableModel(Services services, Setup setup); @Override void addListener(TransformableListener listener); @Override void removeListener(TransformableListener listener); @Override void moveLocation(double extrp, Direction direction, Direction... directions); @Override void moveLocationX(double extrp, double vx); @Override void moveLocationY(double extrp, double vy); @Override void moveLocation(double extrp, double vx, double vy); @Override void teleport(double x, double y); @Override void teleportX(double x); @Override void teleportY(double y); @Override void setLocation(double x, double y); @Override void setLocationX(double x); @Override void setLocationY(double y); @Override void transform(double x, double y, int width, int height); @Override void setSize(int width, int height); @Override double getX(); @Override double getY(); @Override int getWidth(); @Override int getHeight(); @Override double getOldX(); @Override double getOldY(); @Override int getOldWidth(); @Override int getOldHeight(); @Override void recycle(); }### Answer: @Test void testTeleport() { assertLocalization(0.0, 0.0, 0.0, 0.0); transformable.teleport(1.0, -1.0); assertLocalization(1.0, -1.0, 1.0, -1.0); transformable.teleportX(2.0); assertLocalization(2.0, -1.0, 2.0, -1.0); transformable.teleportY(3.0); assertLocalization(2.0, 3.0, 2.0, 3.0); }
### Question: TransformableModel extends FeatureModel implements Transformable, Recyclable { @Override public void setLocation(double x, double y) { mover.setLocation(x, y); notifyTransformed(false); } TransformableModel(Services services, Setup setup); @Override void addListener(TransformableListener listener); @Override void removeListener(TransformableListener listener); @Override void moveLocation(double extrp, Direction direction, Direction... directions); @Override void moveLocationX(double extrp, double vx); @Override void moveLocationY(double extrp, double vy); @Override void moveLocation(double extrp, double vx, double vy); @Override void teleport(double x, double y); @Override void teleportX(double x); @Override void teleportY(double y); @Override void setLocation(double x, double y); @Override void setLocationX(double x); @Override void setLocationY(double y); @Override void transform(double x, double y, int width, int height); @Override void setSize(int width, int height); @Override double getX(); @Override double getY(); @Override int getWidth(); @Override int getHeight(); @Override double getOldX(); @Override double getOldY(); @Override int getOldWidth(); @Override int getOldHeight(); @Override void recycle(); }### Answer: @Test void testSetLocation() { assertLocalization(0.0, 0.0, 0.0, 0.0); transformable.setLocation(1.0, 1.0); assertLocalization(0.0, 0.0, 1.0, 1.0); transformable.setLocationX(2.0); assertLocalization(1.0, 0.0, 2.0, 1.0); transformable.setLocationY(3.0); assertLocalization(1.0, 1.0, 2.0, 3.0); }
### Question: TransformableModel extends FeatureModel implements Transformable, Recyclable { @Override public void setSize(int width, int height) { oldWidth = this.width; oldHeight = this.height; this.width = width; this.height = height; notifyTransformed(false); } TransformableModel(Services services, Setup setup); @Override void addListener(TransformableListener listener); @Override void removeListener(TransformableListener listener); @Override void moveLocation(double extrp, Direction direction, Direction... directions); @Override void moveLocationX(double extrp, double vx); @Override void moveLocationY(double extrp, double vy); @Override void moveLocation(double extrp, double vx, double vy); @Override void teleport(double x, double y); @Override void teleportX(double x); @Override void teleportY(double y); @Override void setLocation(double x, double y); @Override void setLocationX(double x); @Override void setLocationY(double y); @Override void transform(double x, double y, int width, int height); @Override void setSize(int width, int height); @Override double getX(); @Override double getY(); @Override int getWidth(); @Override int getHeight(); @Override double getOldX(); @Override double getOldY(); @Override int getOldWidth(); @Override int getOldHeight(); @Override void recycle(); }### Answer: @Test void testSetSize() { assertEquals(16, transformable.getOldWidth()); assertEquals(32, transformable.getOldHeight()); assertEquals(16, transformable.getWidth()); assertEquals(32, transformable.getHeight()); transformable.setSize(64, 48); assertEquals(16, transformable.getOldWidth()); assertEquals(32, transformable.getOldHeight()); assertEquals(64, transformable.getWidth()); assertEquals(48, transformable.getHeight()); }
### Question: UtilMath { public static double getRound(double speed, double value) { if (speed < 0) { return Math.floor(value); } return Math.ceil(value); } 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 testGetRound() { assertEquals(1.0, UtilMath.getRound(-1.0, 1.5)); assertEquals(2.0, UtilMath.getRound(1.0, 1.5)); }
### Question: TransformableModel extends FeatureModel implements Transformable, Recyclable { @Override public void moveLocation(double extrp, Direction direction, Direction... directions) { mover.moveLocation(extrp, direction, directions); notifyTransformed(false); } TransformableModel(Services services, Setup setup); @Override void addListener(TransformableListener listener); @Override void removeListener(TransformableListener listener); @Override void moveLocation(double extrp, Direction direction, Direction... directions); @Override void moveLocationX(double extrp, double vx); @Override void moveLocationY(double extrp, double vy); @Override void moveLocation(double extrp, double vx, double vy); @Override void teleport(double x, double y); @Override void teleportX(double x); @Override void teleportY(double y); @Override void setLocation(double x, double y); @Override void setLocationX(double x); @Override void setLocationY(double y); @Override void transform(double x, double y, int width, int height); @Override void setSize(int width, int height); @Override double getX(); @Override double getY(); @Override int getWidth(); @Override int getHeight(); @Override double getOldX(); @Override double getOldY(); @Override int getOldWidth(); @Override int getOldHeight(); @Override void recycle(); }### Answer: @Test void testMoveLocation() { assertLocalization(0.0, 0.0, 0.0, 0.0); transformable.moveLocation(1.0, 1.0, 2.0); assertLocalization(0.0, 0.0, 1.0, 2.0); transformable.moveLocation(1.0, new Force(-2.0, -3.0), new Force(-1.0, -2.0)); assertLocalization(1.0, 2.0, -2.0, -3.0); }
### Question: TransformableModel extends FeatureModel implements Transformable, Recyclable { @Override public void transform(double x, double y, int width, int height) { mover.teleport(x, y); oldWidth = this.width; oldHeight = this.height; this.width = width; this.height = height; notifyTransformed(true); } TransformableModel(Services services, Setup setup); @Override void addListener(TransformableListener listener); @Override void removeListener(TransformableListener listener); @Override void moveLocation(double extrp, Direction direction, Direction... directions); @Override void moveLocationX(double extrp, double vx); @Override void moveLocationY(double extrp, double vy); @Override void moveLocation(double extrp, double vx, double vy); @Override void teleport(double x, double y); @Override void teleportX(double x); @Override void teleportY(double y); @Override void setLocation(double x, double y); @Override void setLocationX(double x); @Override void setLocationY(double y); @Override void transform(double x, double y, int width, int height); @Override void setSize(int width, int height); @Override double getX(); @Override double getY(); @Override int getWidth(); @Override int getHeight(); @Override double getOldX(); @Override double getOldY(); @Override int getOldWidth(); @Override int getOldHeight(); @Override void recycle(); }### Answer: @Test void testTransform() { transformable.transform(1.0, 2.0, 3, 4); assertLocalization(1.0, 2.0, 1.0, 2.0); assertEquals(16, transformable.getOldWidth()); assertEquals(32, transformable.getOldHeight()); assertEquals(3, transformable.getWidth()); assertEquals(4, transformable.getHeight()); }
### Question: TransformableModel extends FeatureModel implements Transformable, Recyclable { @Override public void recycle() { mover.teleport(0.0, 0.0); } TransformableModel(Services services, Setup setup); @Override void addListener(TransformableListener listener); @Override void removeListener(TransformableListener listener); @Override void moveLocation(double extrp, Direction direction, Direction... directions); @Override void moveLocationX(double extrp, double vx); @Override void moveLocationY(double extrp, double vy); @Override void moveLocation(double extrp, double vx, double vy); @Override void teleport(double x, double y); @Override void teleportX(double x); @Override void teleportY(double y); @Override void setLocation(double x, double y); @Override void setLocationX(double x); @Override void setLocationY(double y); @Override void transform(double x, double y, int width, int height); @Override void setSize(int width, int height); @Override double getX(); @Override double getY(); @Override int getWidth(); @Override int getHeight(); @Override double getOldX(); @Override double getOldY(); @Override int getOldWidth(); @Override int getOldHeight(); @Override void recycle(); }### Answer: @Test void testRecycle() { transformable.teleport(1.0, 1.0); transformable.recycle(); assertLocalization(0.0, 0.0, 0.0, 0.0); }
### Question: IdentifiableModel extends FeatureAbstract implements Identifiable, Recyclable { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } final IdentifiableModel other = (IdentifiableModel) obj; return other.id.equals(id); } IdentifiableModel(); @Override void addListener(IdentifiableListener listener); @Override void removeListener(IdentifiableListener listener); @Override Integer getId(); @Override void destroy(); @Override void notifyDestroyed(); @Override void recycle(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer: @Test void testEquals() { final IdentifiableModel model = new IdentifiableModel(); assertEquals(model, model); assertNotEquals(model, null); assertNotEquals(model, new Object()); assertNotEquals(model, new IdentifiableModel()); }
### Question: IdentifiableModel extends FeatureAbstract implements Identifiable, Recyclable { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + id.hashCode(); return result; } IdentifiableModel(); @Override void addListener(IdentifiableListener listener); @Override void removeListener(IdentifiableListener listener); @Override Integer getId(); @Override void destroy(); @Override void notifyDestroyed(); @Override void recycle(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer: @Test void testHashCode() { final IdentifiableModel model = new IdentifiableModel(); assertHashEquals(model, model); assertHashNotEquals(model, new Object()); assertHashNotEquals(model, new IdentifiableModel()); }
### Question: SequenceGame extends Sequence { protected SequenceGame(Context context, Function<Services, WorldGame> creator) { this(context, context.getConfig().getOutput(), creator); } protected SequenceGame(Context context, Function<Services, WorldGame> creator); protected SequenceGame(Context context, Resolution resolution, Function<Services, WorldGame> creator); protected SequenceGame(Context context, Resolution resolution, Loop loop, Function<Services, WorldGame> creator); @Override void load(); @Override void update(double extrp); @Override void render(Graphic g); @Override void onTerminated(boolean hasNextSequence); }### Answer: @Test void testSequenceGame() { assertTimeout(1000L, () -> Loader.start(CONFIG, SequenceGameMock.class).await()); }
### Question: LaunchableConfig { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final LaunchableConfig other = (LaunchableConfig) object; return ox == other.ox && oy == other.oy && delay == other.delay && media.equals(other.media) && vector.equals(other.vector); } LaunchableConfig(String media, int delay, int ox, int oy, Force vector); static LaunchableConfig imports(Xml node); static Xml exports(LaunchableConfig config); String getMedia(); int getDelay(); int getOffsetX(); int getOffsetY(); Force getVector(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_LAUNCHABLE; static final String ATT_MEDIA; static final String ATT_DELAY; static final String ATT_OFFSET_X; static final String ATT_OFFSET_Y; }### Answer: @Test void testEquals() { final LaunchableConfig launchable = new LaunchableConfig("media", 10, 1, 2, new Force(1.0, 2.0)); assertEquals(launchable, launchable); assertNotEquals(launchable, null); assertNotEquals(launchable, new Object()); assertNotEquals(launchable, new LaunchableConfig("", 10, 1, 2, new Force(1.0, 2.0))); assertNotEquals(launchable, new LaunchableConfig("media", 0, 1, 2, new Force(1.0, 2.0))); assertNotEquals(launchable, new LaunchableConfig("media", 10, 1, 2, new Force(2.0, 1.0))); assertNotEquals(launchable, new LaunchableConfig("media", 10, 0, 2, new Force(1.0, 2.0))); assertNotEquals(launchable, new LaunchableConfig("media", 10, 1, 0, new Force(1.0, 2.0))); }
### Question: LaunchableConfig { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + media.hashCode(); result = prime * result + delay; result = prime * result + ox; result = prime * result + oy; result = prime * result + vector.hashCode(); return result; } LaunchableConfig(String media, int delay, int ox, int oy, Force vector); static LaunchableConfig imports(Xml node); static Xml exports(LaunchableConfig config); String getMedia(); int getDelay(); int getOffsetX(); int getOffsetY(); Force getVector(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_LAUNCHABLE; static final String ATT_MEDIA; static final String ATT_DELAY; static final String ATT_OFFSET_X; static final String ATT_OFFSET_Y; }### Answer: @Test void testHashCode() { final LaunchableConfig launchable = new LaunchableConfig("media", 10, 1, 2, new Force(1.0, 2.0)); assertHashEquals(launchable, launchable); assertHashEquals(launchable, new LaunchableConfig("media", 10, 1, 2, new Force(1.0, 2.0))); assertHashNotEquals(launchable, new LaunchableConfig("", 10, 1, 2, new Force(1.0, 2.0))); assertHashNotEquals(launchable, new LaunchableConfig("media", 0, 1, 2, new Force(1.0, 2.0))); assertHashNotEquals(launchable, new LaunchableConfig("media", 10, 1, 2, new Force(2.0, 1.0))); assertHashNotEquals(launchable, new LaunchableConfig("media", 10, 0, 2, new Force(1.0, 2.0))); assertHashNotEquals(launchable, new LaunchableConfig("media", 10, 1, 0, new Force(1.0, 2.0))); }
### Question: LaunchableConfig { @Override public String toString() { return new StringBuilder(MIN_LENGTH).append(getClass().getSimpleName()) .append(" [media=") .append(media) .append(", delay=") .append(delay) .append(", ox=") .append(ox) .append(", oy=") .append(oy) .append(", vector=") .append(vector) .append("]") .toString(); } LaunchableConfig(String media, int delay, int ox, int oy, Force vector); static LaunchableConfig imports(Xml node); static Xml exports(LaunchableConfig config); String getMedia(); int getDelay(); int getOffsetX(); int getOffsetY(); Force getVector(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_LAUNCHABLE; static final String ATT_MEDIA; static final String ATT_DELAY; static final String ATT_OFFSET_X; static final String ATT_OFFSET_Y; }### Answer: @Test void testToString() { final LaunchableConfig launchable = new LaunchableConfig("media", 10, 1, 2, new Force(1.0, 2.0)); assertEquals("LaunchableConfig [media=media, delay=10, ox=1, oy=2, vector=" + "Force [fh=1.0, fv=2.0, velocity=0.0, sensibility=0.0]]", launchable.toString()); }
### Question: LauncherConfig { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final LauncherConfig other = (LauncherConfig) object; return level == other.level && rate == other.rate && Arrays.equals(launchables.toArray(), other.launchables.toArray()); } LauncherConfig(int level, int rate, Collection<LaunchableConfig> launchables); static List<LauncherConfig> imports(Configurer configurer); static LauncherConfig imports(Xml node); static Xml exports(LauncherConfig config); int getLevel(); int getRate(); Iterable<LaunchableConfig> getLaunchables(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_LAUNCHER; static final String ATT_LEVEL; static final String ATT_RATE; }### Answer: @Test void testEquals() { final LaunchableConfig launchable = new LaunchableConfig("media", 10, 1, 2, new Force(1.0, 2.0)); final LauncherConfig launcher = new LauncherConfig(0, 1, Arrays.asList(launchable)); assertEquals(launcher, launcher); assertNotEquals(launcher, null); assertNotEquals(launcher, new Object()); assertNotEquals(launcher, new LauncherConfig(0, 0, Arrays.asList(launchable))); assertNotEquals(launcher, new LauncherConfig(0, 1, new ArrayList<LaunchableConfig>())); assertNotEquals(launcher, new LauncherConfig(1, 0, Arrays.asList(launchable))); }
### Question: Resolution { public Resolution get2x() { return getScaled(FACTOR_2X, FACTOR_2X); } Resolution(int width, int height, int rate); Resolution get2x(); Resolution get3x(); Resolution get4x(); Resolution getScaled(double factorX, double factorY); int getWidth(); int getHeight(); int getRate(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer: @Test void testScale2x() { final Resolution resolution = new Resolution(320, 240, 60); assertEquals(new Resolution(640, 480, 60), resolution.get2x()); }
### Question: LauncherConfig { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + level; result = prime * result + rate; result = prime * result + launchables.hashCode(); return result; } LauncherConfig(int level, int rate, Collection<LaunchableConfig> launchables); static List<LauncherConfig> imports(Configurer configurer); static LauncherConfig imports(Xml node); static Xml exports(LauncherConfig config); int getLevel(); int getRate(); Iterable<LaunchableConfig> getLaunchables(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_LAUNCHER; static final String ATT_LEVEL; static final String ATT_RATE; }### Answer: @Test void testHashCode() { final LaunchableConfig launchable = new LaunchableConfig("media", 10, 1, 2, new Force(1.0, 2.0)); final LauncherConfig launcher = new LauncherConfig(0, 1, Arrays.asList(launchable)); assertHashEquals(launcher, launcher); assertHashEquals(launcher, new LauncherConfig(0, 1, Arrays.asList(launchable))); assertHashNotEquals(launcher, new LauncherConfig(0, 0, Arrays.asList(launchable))); assertHashNotEquals(launcher, new LauncherConfig(0, 1, new ArrayList<LaunchableConfig>())); assertHashNotEquals(launcher, new LauncherConfig(1, 0, Arrays.asList(launchable))); }
### Question: Setup extends Configurer { public final Media getIconFile() { return iconFile.orElseThrow(() -> new LionEngineException(ERROR_ICON_FILE)); } Setup(Media config); @SuppressWarnings("unchecked") final Class<T> getConfigClass(ClassLoader classLoader); final Media getSurfaceFile(); final Media getIconFile(); final ImageBuffer getSurface(); final ImageBuffer getIcon(); }### Answer: @Test void testConfigNoIcon() { final Media config = Medias.create("ObjectNoIcon.xml"); final Setup setup = new Setup(config); assertEquals(config, setup.getMedia()); assertThrows(() -> setup.getIconFile(), Setup.ERROR_ICON_FILE); assertNotNull(setup); } @Test void testNoIcon() { final Setup setup = new Setup(Medias.create("ObjectNoConstructor.xml")); assertThrows(() -> setup.getIconFile(), Setup.ERROR_ICON_FILE); }
### Question: Setup extends Configurer { @SuppressWarnings("unchecked") public final <T> Class<T> getConfigClass(ClassLoader classLoader) { if (clazz == null) { final FeaturableConfig config = FeaturableConfig.imports(this); try { clazz = classLoader.loadClass(config.getClassName()); } catch (final ClassNotFoundException exception) { throw new LionEngineException(exception, Setup.ERROR_CLASS + getMedia().getPath()); } } return (Class<T>) clazz; } Setup(Media config); @SuppressWarnings("unchecked") final Class<T> getConfigClass(ClassLoader classLoader); final Media getSurfaceFile(); final Media getIconFile(); final ImageBuffer getSurface(); final ImageBuffer getIcon(); }### Answer: @Test void testClass() { final Media config = Medias.create("Object.xml"); final Setup setup = new Setup(config); assertEquals(FeaturableModel.class, setup.getConfigClass(ClassLoader.getSystemClassLoader())); assertEquals(FeaturableModel.class, setup.getConfigClass(ClassLoader.getSystemClassLoader())); } @Test void testNoClass() { final Setup setup = new Setup(Medias.create("ObjectNoClass.xml")); assertCause(() -> setup.getConfigClass(ClassLoader.getSystemClassLoader()), ClassNotFoundException.class); }
### Question: ActionsConfig { public static List<ActionRef> imports(Configurer configurer, Function<Class<? extends Feature>, Feature> id) { Check.notNull(configurer); return imports(configurer.getRoot(), id); } private ActionsConfig(); static List<ActionRef> imports(Configurer configurer, Function<Class<? extends Feature>, Feature> id); static List<ActionRef> imports(Xml root, Function<Class<? extends Feature>, Feature> id); static Xml exports(Collection<ActionRef> actions); static final String NODE_ACTIONS; static final String NODE_ACTION_REF; static final String ATT_PATH; static final String ATT_CANCEL; static final String ATT_UNIQUE; }### Answer: @Test void testImportNoNode() { final Media media = Medias.create("producer.xml"); final Xml root = new Xml("test"); root.save(media); assertTrue(ActionsConfig.imports(new Xml(media), null).isEmpty()); assertTrue(media.getFile().delete()); }
### Question: Resolution { public Resolution get3x() { return getScaled(FACTOR_3X, FACTOR_3X); } Resolution(int width, int height, int rate); Resolution get2x(); Resolution get3x(); Resolution get4x(); Resolution getScaled(double factorX, double factorY); int getWidth(); int getHeight(); int getRate(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer: @Test void testScale3x() { final Resolution resolution = new Resolution(320, 240, 60); assertEquals(new Resolution(960, 720, 60), resolution.get3x()); }
### Question: Routines extends FeatureModel implements Updatable, Renderable { public Routines(Services services, Setup setup) { super(services, setup); } Routines(Services services, Setup setup); @Override void prepare(FeatureProvider provider); @Override void update(double extrp); @Override void render(Graphic g); }### Answer: @Test void testRoutines() { final MyRoutine routine = new MyRoutine(services, setup); featurable.addFeature(routine); final Routines routines = featurable.addFeatureAndGet(new Routines(services, setup)); assertFalse(routine.update.get()); assertFalse(routine.render.get()); routines.update(1.0); assertTrue(routine.update.get()); assertFalse(routine.render.get()); routines.render(null); assertTrue(routine.update.get()); assertTrue(routine.render.get()); }
### Question: ComponentUpdatable implements ComponentUpdater { @Override public void update(double extrp, Handlables featurables) { for (final Updatable updatable : featurables.get(Updatable.class)) { updatable.update(extrp); } } ComponentUpdatable(); @Override void update(double extrp, Handlables featurables); }### Answer: @Test void testUpdater() { final ComponentUpdatable updatable = new ComponentUpdatable(); final Handler handler = new Handler(new Services()); handler.addComponent(updatable); final Updater object = new Updater(services, setup); handler.add(object); assertFalse(object.isUpdated()); handler.update(1.0); assertTrue(object.isUpdated()); handler.removeAll(); handler.update(1.0); }
### Question: MirrorableModel extends FeatureModel implements Mirrorable, Recyclable { @Override public void mirror(Mirror state) { Check.notNull(state); nextState = state; updater = this::updateMirror; } MirrorableModel(Services services, Setup setup); @Override void mirror(Mirror state); @Override void update(double extrp); @Override Mirror getMirror(); @Override boolean is(Mirror mirror); @Override void recycle(); }### Answer: @Test void testMirror() { final MirrorableModel mirrorable = new MirrorableModel(services, setup); assertEquals(Mirror.NONE, mirrorable.getMirror()); mirrorable.recycle(); assertEquals(Mirror.NONE, mirrorable.getMirror()); assertTrue(mirrorable.is(Mirror.NONE)); mirrorable.update(1.0); assertEquals(Mirror.NONE, mirrorable.getMirror()); mirrorable.mirror(Mirror.HORIZONTAL); assertEquals(Mirror.NONE, mirrorable.getMirror()); mirrorable.update(1.0); assertEquals(Mirror.HORIZONTAL, mirrorable.getMirror()); assertTrue(mirrorable.is(Mirror.HORIZONTAL)); mirrorable.mirror(Mirror.VERTICAL); assertEquals(Mirror.HORIZONTAL, mirrorable.getMirror()); mirrorable.update(1.0); assertEquals(Mirror.VERTICAL, mirrorable.getMirror()); assertTrue(mirrorable.is(Mirror.VERTICAL)); assertFalse(mirrorable.is(Mirror.HORIZONTAL)); }
### Question: AttackerModel extends FeatureModel implements Attacker, Recyclable { @Override public int getAttackDamages() { return damages.getRandom(); } AttackerModel(Services services, Setup setup); @Override void prepare(FeatureProvider provider); @Override void checkListener(Object listener); @Override void addListener(AttackerListener listener); @Override void removeListener(AttackerListener listener); @Override void attack(Transformable target); @Override void stopAttack(); @Override void update(double extrp); @Override void setAttackChecker(Predicate<Transformable> checker); @Override void setAttackDistanceComputer(ToDoubleBiFunction<Transformable, Transformable> distance); @Override void setAttackDelay(int tick); @Override void setAttackFrame(int frame); @Override void setAttackDistance(Range range); @Override void setAttackDamages(Range range); @Override int getAttackDamages(); @Override boolean isAttacking(); @Override Transformable getTarget(); @Override void recycle(); }### Answer: @Test void testNoConfig() { final Media media = UtilTransformable.createMedia(AttackerModelTest.class); final Xml xml = new Xml(media); xml.save(media); final AttackerModel attacker = new AttackerModel(services, new Setup(media)); assertTrue(attacker.getAttackDamages() == 0); assertTrue(media.getFile().delete()); }
### Question: AttackerModel extends FeatureModel implements Attacker, Recyclable { @Override public void stopAttack() { stop = true; } AttackerModel(Services services, Setup setup); @Override void prepare(FeatureProvider provider); @Override void checkListener(Object listener); @Override void addListener(AttackerListener listener); @Override void removeListener(AttackerListener listener); @Override void attack(Transformable target); @Override void stopAttack(); @Override void update(double extrp); @Override void setAttackChecker(Predicate<Transformable> checker); @Override void setAttackDistanceComputer(ToDoubleBiFunction<Transformable, Transformable> distance); @Override void setAttackDelay(int tick); @Override void setAttackFrame(int frame); @Override void setAttackDistance(Range range); @Override void setAttackDamages(Range range); @Override int getAttackDamages(); @Override boolean isAttacking(); @Override Transformable getTarget(); @Override void recycle(); }### Answer: @Test void testStopAttack() { canAttack.set(true); attacker.setAttackChecker(t -> canAttack.get()); attacker.setAttackDistance(new Range(0, 2)); final Transformable target = new TransformableModel(services, setup); target.teleport(1, 1); attacker.attack(target); attacker.update(1.0); attacker.update(1.0); assertTrue(attacker.isAttacking()); attacker.stopAttack(); assertTrue(attacker.isAttacking()); attacker.update(1.0); assertFalse(attacker.isAttacking()); }
### Question: AttackerModel extends FeatureModel implements Attacker, Recyclable { @Override public void update(double extrp) { tick.update(extrp); switch (state) { case NONE: break; case CHECK: updateAttackCheck(); break; case ATTACKING: updateAttacking(); break; default: throw new LionEngineException(state); } if (stop) { attacking = false; state = AttackState.NONE; target = null; stop = false; for (int i = 0; i < listenable.size(); i++) { listenable.get(i).notifyAttackStopped(); } } } AttackerModel(Services services, Setup setup); @Override void prepare(FeatureProvider provider); @Override void checkListener(Object listener); @Override void addListener(AttackerListener listener); @Override void removeListener(AttackerListener listener); @Override void attack(Transformable target); @Override void stopAttack(); @Override void update(double extrp); @Override void setAttackChecker(Predicate<Transformable> checker); @Override void setAttackDistanceComputer(ToDoubleBiFunction<Transformable, Transformable> distance); @Override void setAttackDelay(int tick); @Override void setAttackFrame(int frame); @Override void setAttackDistance(Range range); @Override void setAttackDamages(Range range); @Override int getAttackDamages(); @Override boolean isAttacking(); @Override Transformable getTarget(); @Override void recycle(); }### Answer: @Test void testEnumFail() throws ReflectiveOperationException { final AttackerModel attacker = new AttackerModel(services, setup); final Field field = attacker.getClass().getDeclaredField("state"); UtilReflection.setAccessible(field, true); field.set(attacker, AttackState.values()[3]); assertThrows(() -> attacker.update(1.0), "Unknown enum: FAIL"); }
### Question: AttackerConfig { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final AttackerConfig other = (AttackerConfig) object; return delay == other.delay && distanceMin == other.distanceMin && distanceMax == other.distanceMax && damagesMin == other.damagesMin && damagesMax == other.damagesMax; } AttackerConfig(int delay, int distanceMin, int distanceMax, int damagesMin, int damagesMax); static AttackerConfig imports(Configurer configurer); static AttackerConfig imports(Xml root); static Xml exports(AttackerConfig config); int getDelay(); Range getDistance(); Range getDamages(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_ATTACKER; static final String ATT_DELAY; static final String ATT_DISTANCE_MIN; static final String ATT_DISTANCE_MAX; static final String ATT_DAMAGES_MIN; static final String ATT_DAMAGES_MAX; }### Answer: @Test void testEquals() { final AttackerConfig config = new AttackerConfig(1, 2, 3, 4, 5); assertEquals(config, config); assertEquals(config, new AttackerConfig(1, 2, 3, 4, 5)); assertNotEquals(config, null); assertNotEquals(config, new Object()); assertNotEquals(config, new AttackerConfig(0, 2, 3, 4, 5)); assertNotEquals(config, new AttackerConfig(1, 0, 3, 4, 5)); assertNotEquals(config, new AttackerConfig(1, 2, 0, 4, 5)); assertNotEquals(config, new AttackerConfig(1, 2, 3, 0, 5)); assertNotEquals(config, new AttackerConfig(1, 2, 3, 4, 0)); }
### Question: AttackerConfig { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + delay; result = prime * result + distanceMin; result = prime * result + distanceMax; result = prime * result + damagesMin; result = prime * result + damagesMax; return result; } AttackerConfig(int delay, int distanceMin, int distanceMax, int damagesMin, int damagesMax); static AttackerConfig imports(Configurer configurer); static AttackerConfig imports(Xml root); static Xml exports(AttackerConfig config); int getDelay(); Range getDistance(); Range getDamages(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_ATTACKER; static final String ATT_DELAY; static final String ATT_DISTANCE_MIN; static final String ATT_DISTANCE_MAX; static final String ATT_DAMAGES_MIN; static final String ATT_DAMAGES_MAX; }### Answer: @Test void testHashCode() { final AttackerConfig hash = new AttackerConfig(1, 2, 3, 4, 5); assertHashEquals(hash, new AttackerConfig(1, 2, 3, 4, 5)); assertHashNotEquals(hash, new AttackerConfig(0, 2, 3, 4, 5)); assertHashNotEquals(hash, new AttackerConfig(1, 0, 3, 4, 5)); assertHashNotEquals(hash, new AttackerConfig(1, 2, 0, 4, 5)); assertHashNotEquals(hash, new AttackerConfig(1, 2, 3, 0, 5)); assertHashNotEquals(hash, new AttackerConfig(1, 2, 3, 4, 0)); }
### Question: AttackerConfig { @Override public String toString() { return new StringBuilder(MIN_LENGTH).append(getClass().getSimpleName()) .append(" [delay=") .append(delay) .append(", distanceMin=") .append(getDistance().getMin()) .append(", distanceMax=") .append(getDistance().getMax()) .append(", damagesMin=") .append(getDamages().getMin()) .append(", damagesMax=") .append(getDamages().getMax()) .append("]") .toString(); } AttackerConfig(int delay, int distanceMin, int distanceMax, int damagesMin, int damagesMax); static AttackerConfig imports(Configurer configurer); static AttackerConfig imports(Xml root); static Xml exports(AttackerConfig config); int getDelay(); Range getDistance(); Range getDamages(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String NODE_ATTACKER; static final String ATT_DELAY; static final String ATT_DISTANCE_MIN; static final String ATT_DISTANCE_MAX; static final String ATT_DAMAGES_MIN; static final String ATT_DAMAGES_MAX; }### Answer: @Test void testToString() { final AttackerConfig config = new AttackerConfig(1, 2, 3, 4, 5); assertEquals("AttackerConfig [delay=1, distanceMin=2, distanceMax=3, damagesMin=4, damagesMax=5]", config.toString()); }
### Question: Resolution { public Resolution get4x() { return getScaled(FACTOR_4X, FACTOR_4X); } Resolution(int width, int height, int rate); Resolution get2x(); Resolution get3x(); Resolution get4x(); Resolution getScaled(double factorX, double factorY); int getWidth(); int getHeight(); int getRate(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer: @Test void testScale4x() { final Resolution resolution = new Resolution(320, 180, 60); assertEquals(new Resolution(1280, 720, 60), resolution.get4x()); }
### Question: Factory implements HandlerListener { public Setup getSetup(Media media) { Check.notNull(media); if (!setups.containsKey(media)) { setups.put(media, createSetup(media)); } return setups.get(media); } Factory(Services services); @SuppressWarnings("unchecked") O create(Media media); @SuppressWarnings("unchecked") O create(Media media, Class<O> type); void createCache(Media folder, int count); void setClassLoader(ClassLoader classLoader); Setup getSetup(Media media); @Override void notifyHandlableAdded(Featurable featurable); @Override void notifyHandlableRemoved(Featurable featurable); static final String FILE_DATA_EXTENSION; static final String FILE_DATA_DOT_EXTENSION; }### Answer: @Test void testGetSetup() { final Setup setup = factory.getSetup(Medias.create("Object.xml")); assertEquals(Medias.create("Object.xml"), setup.getMedia()); assertEquals(setup, factory.getSetup(Medias.create("Object.xml"))); assertEquals(setup, factory.getSetup(Medias.create("Object.xml"))); }
### Question: TileConfig { public static int imports(Xml nodeTile) { Check.notNull(nodeTile); return nodeTile.readInteger(ATT_TILE_NUMBER); } private TileConfig(); static int imports(Xml nodeTile); static Xml exports(int number); static final String NODE_TILE; static final String ATT_TILE_NUMBER; }### Answer: @Test void testImports() { final Xml nodeTile = new Xml(TileConfig.NODE_TILE); nodeTile.writeInteger(TileConfig.ATT_TILE_NUMBER, 1); assertEquals(1, TileConfig.imports(nodeTile)); }
### Question: TileConfig { public static Xml exports(int number) { final Xml node = new Xml(NODE_TILE); node.writeInteger(ATT_TILE_NUMBER, number); return node; } private TileConfig(); static int imports(Xml nodeTile); static Xml exports(int number); static final String NODE_TILE; static final String ATT_TILE_NUMBER; }### Answer: @Test void testExports() { final int number = 1; final Xml nodeTile = TileConfig.exports(number); assertEquals(number, nodeTile.readInteger(TileConfig.ATT_TILE_NUMBER)); }
### Question: Resolution { public Resolution getScaled(double factorX, double factorY) { Check.superiorStrict(factorX, 0); Check.superiorStrict(factorY, 0); return new Resolution((int) (width * factorX), (int) (height * factorY), rate); } Resolution(int width, int height, int rate); Resolution get2x(); Resolution get3x(); Resolution get4x(); Resolution getScaled(double factorX, double factorY); int getWidth(); int getHeight(); int getRate(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer: @Test void testScaleWrongFactorX() { assertThrows(() -> new Resolution(320, 240, 60).getScaled(0, 1), Check.ERROR_ARGUMENT + 0.0 + Check.ERROR_SUPERIOR_STRICT + 0.0); } @Test void testScaleWrongFactorY() { assertThrows(() -> new Resolution(320, 240, 60).getScaled(1, 0), Check.ERROR_ARGUMENT + 0.0 + Check.ERROR_SUPERIOR_STRICT + 0.0); }
### Question: TileGroup extends NameableAbstract { public boolean contains(Tile tile) { return contains(tile.getKey()); } TileGroup(String name, TileGroupType type, Set<Integer> tiles); boolean contains(Tile tile); boolean contains(Integer number); TileGroupType getType(); Set<Integer> getTiles(); }### Answer: @Test void testContains() { final TileGroup tileGroup = new TileGroup("test", TileGroupType.NONE, getTile(1)); assertTrue(tileGroup.contains(Integer.valueOf(1))); assertTrue(tileGroup.contains(new TileGame(1, 1, 1, 1, 1))); assertFalse(tileGroup.contains(Integer.valueOf(2))); }
### Question: Circuit { @Override public String toString() { return new StringBuilder().append(type).append(Constant.SPACE).append(groups).toString(); } Circuit(CircuitType type, String groupIn, String groupOut); CircuitType getType(); String getIn(); String getOut(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer: @Test void testToString() { assertEquals(CircuitType.MIDDLE.name() + " a -> b", new Circuit(CircuitType.MIDDLE, "a", "b").toString()); }
### Question: TransitiveGroup { static void reduceTransitive(Collection<GroupTransition> transitive) { final Collection<GroupTransition> localChecked = new ArrayList<>(transitive.size()); final Collection<GroupTransition> toRemove = new ArrayList<>(); final Iterator<GroupTransition> iterator = transitive.iterator(); GroupTransition first = iterator.next(); while (iterator.hasNext()) { final GroupTransition current = iterator.next(); localChecked.add(current); if (current.getOut().equals(first.getOut())) { toRemove.addAll(localChecked); localChecked.clear(); if (iterator.hasNext()) { first = iterator.next(); } } } transitive.removeAll(toRemove); toRemove.clear(); } TransitiveGroup(MapTile map); void load(); void checkTransitives(Tile tile); Collection<GroupTransition> getTransitives(String groupIn, String groupOut); Collection<Integer> getDirectTransitiveTiles(Transition transition); }### Answer: @Test void testReduce() { final Collection<GroupTransition> transitive = new ArrayList<>(); transitive.add(new GroupTransition("a", "b")); transitive.add(new GroupTransition("b", "c")); transitive.add(new GroupTransition("c", "b")); transitive.add(new GroupTransition("b", "d")); final Collection<GroupTransition> expected = new ArrayList<>(); expected.add(new GroupTransition("a", "b")); expected.add(new GroupTransition("b", "d")); TransitiveGroup.reduceTransitive(transitive); assertEquals(expected, transitive); }
### Question: GroupTransition { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final GroupTransition other = (GroupTransition) object; return groupIn.equals(other.groupIn) && groupOut.equals(other.groupOut); } GroupTransition(String groupIn, String groupOut); String getIn(); String getOut(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer: @Test void testEquals() { final GroupTransition transition = new GroupTransition("a", "a"); assertEquals(transition, transition); assertEquals(new GroupTransition("a", "a"), new GroupTransition("a", "a")); assertEquals(new GroupTransition("a", "b"), new GroupTransition("a", "b")); assertNotEquals(new GroupTransition("a", "a"), null); assertNotEquals(new GroupTransition("a", "a"), new Object()); assertNotEquals(new GroupTransition("a", "b"), new GroupTransition("b", "a")); assertNotEquals(new GroupTransition("a", "b"), new GroupTransition("a", "a")); assertNotEquals(new GroupTransition("a", "b"), new GroupTransition("b", "b")); assertNotEquals(new GroupTransition("a", "a"), new GroupTransition("b", "a")); assertNotEquals(new GroupTransition("a", "a"), new GroupTransition("b", "b")); }
### Question: GroupTransition { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + groupIn.hashCode(); result = prime * result + groupOut.hashCode(); return result; } GroupTransition(String groupIn, String groupOut); String getIn(); String getOut(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer: @Test void testHashCode() { assertHashEquals(new GroupTransition("a", "a"), new GroupTransition("a", "a")); assertHashEquals(new GroupTransition("a", "b"), new GroupTransition("a", "b")); assertHashNotEquals(new GroupTransition("a", "a"), new Object()); assertHashNotEquals(new GroupTransition("a", "b"), new GroupTransition("b", "a")); assertHashNotEquals(new GroupTransition("a", "b"), new GroupTransition("a", "a")); assertHashNotEquals(new GroupTransition("a", "b"), new GroupTransition("b", "b")); assertHashNotEquals(new GroupTransition("a", "a"), new GroupTransition("b", "a")); assertHashNotEquals(new GroupTransition("a", "a"), new GroupTransition("b", "b")); }
### Question: GroupTransition { @Override public String toString() { return new StringBuilder(groupIn).append(TRANSITION).append(groupOut).toString(); } GroupTransition(String groupIn, String groupOut); String getIn(); String getOut(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer: @Test void testToString() { assertEquals("a -> b", new GroupTransition("a", "b").toString()); }
### Question: Transition { @Override public String toString() { return new StringBuilder().append(type).append(Constant.SPACE).append(groups).toString(); } Transition(TransitionType type, String groupIn, String groupOut); TransitionType getType(); String getIn(); String getOut(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer: @Test void testToString() { assertEquals(TransitionType.CENTER.name() + " a -> b", new Transition(TransitionType.CENTER, "a", "b").toString()); }
### Question: FovableConfig { public static int imports(Configurer configurer) { Check.notNull(configurer); return imports(configurer.getRoot()); } private FovableConfig(); static int imports(Configurer configurer); static int imports(Xml root); static Xml exports(int fov); static final String NODE_FOVABLE; static final String ATT_FOV; }### Answer: @Test void testExportsImportsNoNode() { final Xml root = new Xml("test"); final Media media = Medias.create("Object.xml"); root.save(media); assertEquals(0, FovableConfig.imports(new Xml(media))); assertEquals(0, FovableConfig.imports(new Configurer(media))); assertTrue(media.getFile().delete()); }
### Question: CollisionFormula extends NameableAbstract { @Override public String toString() { return new StringBuilder(MINIMUM_LENGTH).append(getClass().getSimpleName()) .append(" (name=") .append(getName()) .append(")") .append(System.lineSeparator()) .append(Constant.TAB) .append(range) .append(System.lineSeparator()) .append(Constant.TAB) .append(function) .append(System.lineSeparator()) .append(Constant.TAB) .append(constraint) .append(System.lineSeparator()) .toString(); } CollisionFormula(String name, CollisionRange range, CollisionFunction function, CollisionConstraint constraint); CollisionRange getRange(); CollisionFunction getFunction(); CollisionConstraint getConstraint(); @Override String toString(); }### Answer: @Test void testToString() { assertEquals("CollisionFormula (name=formula)" + System.lineSeparator() + Constant.TAB + "CollisionRange (output=X, minX=0, maxX=1, minY=2, maxY=3)" + System.lineSeparator() + Constant.TAB + "CollisionFunctionLinear (a=1.0, b=2.0)" + System.lineSeparator() + Constant.TAB + "CollisionConstraint{NORTH=[], NORTH_EAST=[], EAST=[], SOUTH_EAST=[], " + "SOUTH=[], SOUTH_WEST=[], WEST=[], NORTH_WEST=[]}" + System.lineSeparator(), formula.toString()); }
### Question: CollisionGroup extends NameableAbstract { public static boolean same(String groupA, String groupB) { final boolean result; if (groupA != null && groupB != null) { result = groupA.equals(groupB); } else if (groupA == null && groupB == null) { result = true; } else { result = false; } return result; } CollisionGroup(String name, Collection<CollisionFormula> formulas); static boolean same(String groupA, String groupB); Collection<CollisionFormula> getFormulas(); @Override String toString(); }### Answer: @Test void testSame() { assertTrue(CollisionGroup.same(null, null)); assertTrue(CollisionGroup.same("a", "a")); assertFalse(CollisionGroup.same(null, "a")); assertFalse(CollisionGroup.same("a", null)); assertFalse(CollisionGroup.same("a", "b")); }
### Question: CollisionGroup extends NameableAbstract { public Collection<CollisionFormula> getFormulas() { return Collections.unmodifiableCollection(formulas); } CollisionGroup(String name, Collection<CollisionFormula> formulas); static boolean same(String groupA, String groupB); Collection<CollisionFormula> getFormulas(); @Override String toString(); }### Answer: @Test void testGroup() { assertEquals("group", group.getName()); assertEquals(formula, group.getFormulas().iterator().next()); }
### Question: CollisionGroup extends NameableAbstract { @Override public String toString() { return new StringBuilder(MINIMUM_LENGTH).append(getClass().getSimpleName()) .append(" (name=") .append(getName()) .append(")") .append(System.lineSeparator()) .append(Constant.TAB) .append(formulas) .toString(); } CollisionGroup(String name, Collection<CollisionFormula> formulas); static boolean same(String groupA, String groupB); Collection<CollisionFormula> getFormulas(); @Override String toString(); }### Answer: @Test void testToString() { assertEquals("CollisionGroup (name=group)" + System.lineSeparator() + Constant.TAB + "[CollisionFormula (name=formula)" + System.lineSeparator() + Constant.TAB + "CollisionRange (output=X, minX=0, maxX=1, minY=2, maxY=3)" + System.lineSeparator() + Constant.TAB + "CollisionFunctionLinear (a=1.0, b=2.0)" + System.lineSeparator() + Constant.TAB + "CollisionConstraint{NORTH=[], NORTH_EAST=[], EAST=[], SOUTH_EAST=[], SOUTH=[], " + "SOUTH_WEST=[], WEST=[], NORTH_WEST=[]}" + System.lineSeparator() + "]", group.toString()); }
### Question: CollisionCategoryConfig { public static Collection<CollisionCategory> imports(Xml root) { Check.notNull(root); final Collection<CollisionCategory> categories = new ArrayList<>(); if (root.hasChild(NODE_CATEGORIES)) { final Collection<Xml> childrenCategory = root.getChild(NODE_CATEGORIES).getChildren(NODE_CATEGORY); for (final Xml node : childrenCategory) { final Collection<Xml> childrenGroup = node.getChildren(TileGroupsConfig.NODE_GROUP); final Collection<CollisionGroup> groups = new ArrayList<>(childrenGroup.size()); for (final Xml group : childrenGroup) { final String name = group.getText(); groups.add(new CollisionGroup(name, new ArrayList<>(0))); } childrenGroup.clear(); final String name = node.readString(ATT_NAME); final Axis axis = Axis.valueOf(node.readString(ATT_AXIS)); final int x = node.readInteger(ATT_X); final int y = node.readInteger(ATT_Y); final boolean glue = node.readBoolean(true, ATT_GLUE); final CollisionCategory category = new CollisionCategory(name, axis, x, y, glue, groups); categories.add(category); } childrenCategory.clear(); } return categories; } private CollisionCategoryConfig(); static Collection<CollisionCategory> imports(Xml root); static Collection<CollisionCategory> imports(Configurer configurer, MapTileCollision map); static CollisionCategory imports(Xml root, MapTileCollision map); static void exports(Xml root, CollisionCategory category); static final String NODE_CATEGORIES; static final String NODE_CATEGORY; static final String ATT_NAME; static final String ATT_AXIS; static final String ATT_X; static final String ATT_Y; static final String ATT_GLUE; }### Answer: @Test void testNoNode() { final Xml root = new Xml("categories"); assertTrue(CollisionCategoryConfig.imports(root).isEmpty()); }
### Question: Resolution { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || getClass() != object.getClass()) { return false; } final Resolution other = (Resolution) object; return width == other.width && height == other.height && rate == other.rate; } Resolution(int width, int height, int rate); Resolution get2x(); Resolution get3x(); Resolution get4x(); Resolution getScaled(double factorX, double factorY); int getWidth(); int getHeight(); int getRate(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer: @Test void testEquals() { final Resolution resolution = new Resolution(320, 240, 60); assertEquals(resolution, resolution); assertEquals(new Resolution(320, 240, 60), resolution); assertNotEquals(resolution, null); assertNotEquals(resolution, new Object()); assertNotEquals(resolution, new Resolution(100, 240, 60)); assertNotEquals(resolution, new Resolution(320, 100, 60)); assertNotEquals(resolution, new Resolution(320, 240, 30)); }
### Question: Timing { public void restart() { stop(); start(); } 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 testRestart() { timing.start(); UtilTests.pause(PAUSE); assertTrue(timing.elapsed() >= PAUSE, String.valueOf(timing.elapsed())); timing.restart(); UtilTests.pause(PAUSE); assertTrue(timing.elapsed() >= PAUSE, String.valueOf(timing.elapsed())); }
### Question: CollisionResult { @Override public String toString() { return new StringBuilder(MIN_LENGHT).append(getClass().getSimpleName()) .append(" [x=") .append(x) .append(", y=") .append(y) .append(", fx=") .append(formulaX.getName()) .append(", fy=") .append(formulaY.getName()) .append("]") .toString(); } CollisionResult(Double x, Double y, Tile tile, CollisionFormula formulaX, CollisionFormula formulaY); Double getX(); Double getY(); Tile getTile(); boolean startWithX(String name); boolean startWithY(String name); boolean contains(String name); @Override String toString(); }### Answer: @Test void testToString() { assertEquals("CollisionResult [x=1.0, y=2.0, fx=formulaX, fy=formulaY]", new CollisionResult(Double.valueOf(1.0), Double.valueOf(2.0), new TileGame(1, 3, 4, 1, 1), formulaX, formulaY).toString()); }
### Question: CollisionConstraint { @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || object.getClass() != getClass()) { return false; } final CollisionConstraint other = (CollisionConstraint) object; return constraints.equals(other.constraints); } CollisionConstraint(); void add(Orientation orientation, String group); Map<Orientation, Collection<String>> getConstraints(); Collection<String> getConstraints(Orientation orientation); boolean has(Orientation orientation, String group); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer: @Test void testEquals() { assertEquals(constraint, constraint); final CollisionConstraint same = new CollisionConstraint(); same.add(Orientation.EAST, "group"); assertEquals(constraint, same); assertNotEquals(constraint, null); assertNotEquals(constraint, new Object()); final CollisionConstraint other = new CollisionConstraint(); other.add(Orientation.NORTH, "group"); assertNotEquals(constraint, other); final CollisionConstraint other2 = new CollisionConstraint(); other2.add(Orientation.EAST, "void"); assertNotEquals(constraint, other2); }
### Question: CollisionConstraint { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + constraints.hashCode(); return result; } CollisionConstraint(); void add(Orientation orientation, String group); Map<Orientation, Collection<String>> getConstraints(); Collection<String> getConstraints(Orientation orientation); boolean has(Orientation orientation, String group); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer: @Test void testHashCode() { final CollisionConstraint same = new CollisionConstraint(); same.add(Orientation.EAST, "group"); assertHashEquals(constraint, same); assertHashNotEquals(constraint, new Object()); final CollisionConstraint other = new CollisionConstraint(); other.add(Orientation.NORTH, "group"); assertHashNotEquals(constraint, other); final CollisionConstraint other2 = new CollisionConstraint(); other2.add(Orientation.EAST, "void"); assertHashNotEquals(constraint, other2); }
### Question: CollisionConstraint { @Override public String toString() { return new StringBuilder().append(getClass().getSimpleName()).append(constraints).toString(); } CollisionConstraint(); void add(Orientation orientation, String group); Map<Orientation, Collection<String>> getConstraints(); Collection<String> getConstraints(Orientation orientation); boolean has(Orientation orientation, String group); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer: @Test void testToString() { assertEquals("CollisionConstraint{NORTH=[], NORTH_EAST=[], EAST=[group], SOUTH_EAST=[], " + "SOUTH=[], SOUTH_WEST=[], WEST=[], NORTH_WEST=[]}", constraint.toString()); }
### Question: CollisionFunctionConfig { public static CollisionFunction imports(Xml parent) { Check.notNull(parent); final Xml node = parent.getChild(FUNCTION); final String name = node.readString(TYPE); try { final CollisionFunctionType type = CollisionFunctionType.valueOf(name); switch (type) { case LINEAR: return new CollisionFunctionLinear(node.readDouble(A), node.readDouble(B)); default: throw new LionEngineException(ERROR_TYPE + name); } } catch (final IllegalArgumentException | NullPointerException exception) { throw new LionEngineException(exception, ERROR_TYPE + name); } } private CollisionFunctionConfig(); static CollisionFunction imports(Xml parent); static void exports(Xml root, CollisionFunction function); static final String FUNCTION; static final String TYPE; static final String A; static final String B; }### Answer: @Test void testFunctionUnknown() { final Xml root = new Xml("function"); root.createChild(CollisionFunctionConfig.FUNCTION) .writeString(CollisionFunctionConfig.TYPE, CollisionFunctionType.values()[1].name()); assertThrows(() -> CollisionFunctionConfig.imports(root), "Unknown type: FAIL"); }
### Question: Resolution { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + width; result = prime * result + height; result = prime * result + rate; return result; } Resolution(int width, int height, int rate); Resolution get2x(); Resolution get3x(); Resolution get4x(); Resolution getScaled(double factorX, double factorY); int getWidth(); int getHeight(); int getRate(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); }### Answer: @Test void testHashCode() { final Resolution resolution = new Resolution(320, 240, 60); assertHashEquals(new Resolution(320, 240, 60), resolution); assertHashNotEquals(resolution, new Object()); assertHashNotEquals(resolution, new Resolution(100, 240, 60)); assertHashNotEquals(resolution, new Resolution(320, 100, 60)); assertHashNotEquals(resolution, new Resolution(320, 240, 30)); }
### Question: MapTileCollisionModel extends FeatureAbstract implements MapTileCollision { @Override public CollisionFormula getCollisionFormula(String name) { return loader.getCollisionFormula(name); } MapTileCollisionModel(); @Override void prepare(FeatureProvider provider); @Override void loadCollisions(Media collisionFormulas, Media collisionGroups); @Override void loadCollisions(CollisionFormulaConfig formulasConfig, CollisionGroupConfig groupsConfig); @Override void saveCollisions(); @Override CollisionResult computeCollision(Transformable transformable, CollisionCategory category); @Override CollisionFormula getCollisionFormula(String name); @Override CollisionGroup getCollisionGroup(String name); @Override Collection<CollisionFormula> getCollisionFormulas(Tile tile); @Override Collection<CollisionFormula> getCollisionFormulas(); @Override Collection<CollisionGroup> getCollisionGroups(); @Override Media getFormulasConfig(); @Override Media getCollisionsConfig(); }### Answer: @Test void testUnknownFormula() { assertThrows(() -> mapCollision.getCollisionFormula("void"), MapTileCollisionLoader.ERROR_FORMULA + "void"); }