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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations