Search in sources :

Example 11 with Featurable

use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.

the class ProducerModelTest method testCannot.

/**
 * Test the cannot produce.
 */
@Test
void testCannot() {
    object.check.set(false);
    producer.recycle();
    producer.setStepsSpeed(50.0);
    final AtomicReference<Featurable> skip = new AtomicReference<>();
    final AtomicReference<Featurable> cant = new AtomicReference<>();
    producer.addListener(UtilProducible.createProducerListener(skip, skip, skip, cant));
    final Featurable featurable = UtilProducible.createProducible(services);
    producer.addToProductionQueue(featurable);
    producer.update(1.0);
    assertFalse(producer.isProducing());
    assertEquals(featurable, cant.get());
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 12 with Featurable

use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.

the class ProducerModelTest method testListenerAutoAdd.

/**
 * Test the production listener auto add.
 */
@Test
void testListenerAutoAdd() {
    final ProducerObjectSelf object = new ProducerObjectSelf(services, setup);
    final ProducerModel producer = new ProducerModel(services, setup);
    producer.prepare(object);
    producer.setStepsSpeed(50.0);
    producer.checkListener(object);
    producer.recycle();
    final Featurable featurable = UtilProducible.createProducible(services);
    producer.addToProductionQueue(featurable);
    assertEquals(0, object.flag.get());
    producer.update(1.0);
    assertEquals(1, object.flag.get());
}
Also used : Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 13 with Featurable

use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.

the class ProducerModelTest method testPendingCannot.

/**
 * Test the production pending and cannot.
 */
@Test
void testPendingCannot() {
    producer.recycle();
    producer.setStepsSpeed(50.0);
    final AtomicReference<Featurable> start = new AtomicReference<>();
    final AtomicReference<Featurable> skip = new AtomicReference<>();
    producer.addListener(UtilProducible.createProducerListener(start, skip, skip, skip));
    final Featurable featurable = UtilProducible.createProducible(services);
    producer.addToProductionQueue(featurable);
    producer.addToProductionQueue(featurable);
    producer.update(1.0);
    producer.update(1.0);
    object.check.set(false);
    producer.update(1.0);
    producer.update(1.0);
    assertEquals(1, producer.getQueueLength());
    assertNotNull(start.get());
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 14 with Featurable

use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.

the class ProducerModelTest method testSkip.

/**
 * Test the skip production.
 */
@Test
void testSkip() {
    producer.setStepsSpeed(50.0);
    final AtomicReference<Featurable> done = new AtomicReference<>();
    final AtomicReference<Featurable> skip = new AtomicReference<>();
    producer.addListener(UtilProducible.createProducerListener(skip, skip, done, skip));
    producer.recycle();
    producer.skipProduction();
    final Featurable featurable = UtilProducible.createProducible(services);
    producer.addToProductionQueue(featurable);
    producer.addToProductionQueue(featurable);
    producer.update(1.0);
    producer.skipProduction();
    producer.update(1.0);
    producer.update(1.0);
    producer.update(1.0);
    assertNull(done.get());
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 15 with Featurable

use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.

the class ProducerModelTest method testDefaultProduction.

/**
 * Test the default production with default checker.
 */
@Test
void testDefaultProduction() {
    final ProducerModel producer = new ProducerModel(services, setup);
    producer.prepare(new FeaturableModel(services, setup));
    producer.recycle();
    producer.setStepsSpeed(0.5);
    final AtomicReference<Featurable> start = new AtomicReference<>();
    final AtomicReference<Featurable> current = new AtomicReference<>();
    final AtomicReference<Featurable> done = new AtomicReference<>();
    final AtomicReference<Featurable> cant = new AtomicReference<>();
    producer.addListener(UtilProducible.createProducerListener(start, current, done, cant));
    producer.update(1.0);
    assertNull(producer.getProducingElement());
    assertEquals(-1.0, producer.getProgress());
    assertEquals(-1, producer.getProgressPercent());
    assertEquals(0, producer.getQueueLength());
    assertFalse(producer.isProducing());
    final Featurable featurable = UtilProducible.createProducible(services);
    producer.addToProductionQueue(featurable);
    assertEquals(0, producer.getQueueLength());
    assertNull(start.get());
    assertFalse(producer.isProducing());
    producer.update(1.0);
    assertEquals(0.0, producer.getProgress());
    assertEquals(0, producer.getProgressPercent());
    assertEquals(0, producer.getQueueLength());
    assertEquals(featurable, start.get());
    assertNull(current.get());
    assertTrue(producer.isProducing());
    assertEquals(featurable, producer.getProducingElement());
    producer.update(1.0);
    assertEquals(0.5, producer.getProgress());
    assertEquals(50, producer.getProgressPercent());
    assertEquals(featurable, current.get());
    assertNull(done.get());
    assertTrue(producer.isProducing());
    producer.update(1.0);
    assertEquals(1.0, producer.getProgress());
    assertEquals(100, producer.getProgressPercent());
    assertEquals(featurable, current.get());
    assertNull(done.get());
    assertFalse(producer.isProducing());
    producer.update(1.0);
    assertEquals(featurable, done.get());
    assertNull(cant.get());
    assertFalse(producer.isProducing());
}
Also used : FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Aggregations

Featurable (com.b3dgs.lionengine.game.feature.Featurable)35 Test (org.junit.jupiter.api.Test)19 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)18 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Setup (com.b3dgs.lionengine.game.feature.Setup)8 Media (com.b3dgs.lionengine.Media)7 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)6 Transformable (com.b3dgs.lionengine.game.feature.Transformable)5 Services (com.b3dgs.lionengine.game.feature.Services)4 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)4 Animation (com.b3dgs.lionengine.Animation)3 Medias (com.b3dgs.lionengine.Medias)2 ViewerMock (com.b3dgs.lionengine.ViewerMock)2 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)2 Camera (com.b3dgs.lionengine.game.feature.Camera)2 IdentifiableModel (com.b3dgs.lionengine.game.feature.IdentifiableModel)2 LayerableModel (com.b3dgs.lionengine.game.feature.LayerableModel)2 MirrorableModel (com.b3dgs.lionengine.game.feature.MirrorableModel)2 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)2