/** * Tests broadcasting from and to unreliable agents. */ @Test public void testBroadcastUnreliable() { final Agent unreliable = new Agent(new Point(5, 5), 0); model.register(unreliable); unreliable.device().broadcast(Contents.YO); model.afterTick(TimeLapseFactory.create(0, 100)); assertTrue(agent1.device().getUnreadMessages().isEmpty()); assertTrue(agent2.device().getUnreadMessages().isEmpty()); agent1.device().broadcast(Contents.YO); model.afterTick(TimeLapseFactory.create(0, 100)); assertTrue(unreliable.device().getUnreadMessages().isEmpty()); assertEquals(1, agent2.device().getUnreadMessages().size()); }
/** * Test for unreliable direct message. */ @Test public void testSendDirectMsgUnreliable() { final Agent unreliable = new Agent(new Point(5, 5), 0); model.register(unreliable); unreliable.device().send(Contents.YO, agent1); model.afterTick(TimeLapseFactory.create(0, 100)); assertTrue(agent1.device().getUnreadMessages().isEmpty()); agent1.device().send(Contents.YO, unreliable); model.afterTick(TimeLapseFactory.create(0, 100)); assertTrue(unreliable.device().getUnreadMessages().isEmpty()); }
final Agent rangedNoPos = new RangedAgent(null, 5); final Agent ranged = new RangedAgent(new Point(1, 1), 5); final Agent noPos = new Agent(null); assertFalse(rangedNoPos.getPosition().isPresent()); model.register(rangedNoPos);
/** * Tests what happens if an agent no longer has a position. */ @Test public void testSenderIsRemovedDuringSend() { final Agent a = new Agent(new Point(0, 0)); final Agent b = new RangedAgent(new Point(0, 0), 5); model.register(a); model.register(b); // a is removed during the same tick as that it sends a message, this // doesn't matter since it has no range, therefore it sends anyway. a.device().broadcast(Contents.YO); a.setPosition(null); model.afterTick(TimeLapseFactory.create(0, 100)); assertEquals(1, agent1.device().getReceivedCount()); // b is removed during the same tick as that is sends a message, since it is // a ranged device the message is not sent and will stay in the outbox. b.device().broadcast(Contents.YO); b.setPosition(null); model.afterTick(TimeLapseFactory.create(0, 100)); assertEquals(1, agent1.device().getReceivedCount()); assertEquals(1, b.device().getOutbox().size()); }
/** * Set up a simple and reliable world. */ @Before public void setUp() { model = CommModel .builder() .withDefaultDeviceReliability(1.0) .build(fakeDependencies()); agent1 = new Agent(new Point(0, 0)); agent2 = new Agent(new Point(0, 10)); agent3 = new Agent(new Point(5, 10)); agent4 = new Agent(new Point(5, 5)); agent5 = new Agent(new Point(5, 0)); model.register(agent1); model.register(agent2); model.register(agent3); model.register(agent4); model.register(agent5); TestUtil.testEnum(CommModel.EventTypes.class); }
/** * Test input validation. */ @Test public void testSendDirectMsgInputValidation() { boolean fail = false; try { agent1.device().send(Contents.YO, agent1); } catch (final IllegalArgumentException e) { fail = true; } assertTrue(fail); fail = false; final Agent unknown = new Agent(new Point(0, 0)); try { agent1.device().send(Contents.YO, unknown); } catch (final IllegalArgumentException e) { fail = true; } assertTrue(fail); }