Agent extends WorldEntity implements Drawable { public Orientation calculateOrientationToTask() { double direction = getDirection(); switch ((int) ((Math.toDegrees(direction) + 22.5) % 360) / 45) { case 0: orientation = Orientation.EAST; break; case 1: orientation = Orientation.NORTHEAST; break; case 2: orientation = Orientation.NORTH; break; case 3: orientation = Orientation.NORTHWEST; break; case 4: orientation = Orientation.WEST; break; case 5: orientation = Orientation.SOUTHWEST; break; case 6: orientation = Orientation.SOUTH; break; case 7: orientation = Orientation.SOUTHEAST; break; } return orientation; } Agent(String name, int x, int y, double speed);  Agent(int x, int y, double speed,
                 Map<String, String> marketplaceProperties); static List<String> getRoleTypeNames(); static RoleType getRoleTypeFromString(String name); static int getTotalInfections(); static void setTreatmentRound(int amount); static void setremainingTreatments(int amount); int getAge(); boolean isFemale(); String getGender(); void setExistingWorkerRoleExperience(); @Override void tick(); void moveTowardTaskLocation(); double getDirection(); double getSpeed(); void setSpeed(double speed); String getName(); boolean hasTask(); boolean hasIdleTask(); AbstractTask getTask(); void setTask(AbstractTask task); Inventory getRucksack(); ToolType getToolType(); MachineType getMachineType(); void removeTool(); void removeMachine(); Tool getTool(); Machine getMachine(); boolean equip(ToolType type); boolean equipMachine(MachineType type); void removeResource(String name); boolean canEquip(ToolType toolType); boolean canEquipMachine(MachineType machineType); Orientation calculateOrientationToTask(); @Override void draw(Viewport v, GraphicsContext g); int getHappiness(); void setHappiness(int happiness); Animation getAnimation(); void setAnimation(Animation animation); int getLevelForRole(RoleType roleType); void addExperienceForRole(RoleType roleType, int experience); void IHaveSeenLeggy(); boolean eligibleForTask(AbstractTask task); boolean hasRequiredTool(AbstractTask task); boolean isRequiredRole(AbstractTask task); boolean taskInWorkingArea(AbstractTask task); RoleType getCurrentRoleType(); void setCurrentRoleType(RoleType roleType); void setAreaLock(Rectangle workingArea); int getHighestLevel(); int getWage(); boolean setWage(int newWage); boolean isRoleTypeLocked(); void lockRole(); void unlockRole(); Map<String, String> getAttributes(); int getQuantity(); int getMaxQuantity(); void setState(AgentState state); @Override String toString(); Integer getId(); void setId(Integer id); String getImageFileName(); Rectangle getAreaLock(); boolean isAreaLocked(); void areaUnlock();  }
@Test public void testCalculateOrientationToTask() { Agent agent = mock(Agent.class); double tolerance = 0.1; doCallRealMethod().when(agent).calculateOrientationToTask(); when(agent.getDirection()).thenReturn(-Math.PI / 8 + tolerance); assertEquals(Agent.Orientation.EAST, agent.calculateOrientationToTask()); when(agent.getDirection()).thenReturn(Math.PI / 8 - tolerance); assertEquals(Agent.Orientation.EAST, agent .calculateOrientationToTask()); when(agent.getDirection()).thenReturn(Math.PI / 8 + tolerance); assertEquals(Agent.Orientation.NORTHEAST, agent .calculateOrientationToTask()); when(agent.getDirection()).thenReturn(3 * Math.PI / 8 - tolerance); assertEquals(Agent.Orientation.NORTHEAST, agent .calculateOrientationToTask()); when(agent.getDirection()).thenReturn(3 * Math.PI / 8 + tolerance); assertEquals(Agent.Orientation.NORTH, agent .calculateOrientationToTask()); when(agent.getDirection()).thenReturn(5 * Math.PI / 8 - tolerance); assertEquals(Agent.Orientation.NORTH, agent .calculateOrientationToTask()); when(agent.getDirection()).thenReturn(5 * Math.PI / 8 + tolerance); assertEquals(Agent.Orientation.NORTHWEST, agent .calculateOrientationToTask()); when(agent.getDirection()).thenReturn(7 * Math.PI / 8 - tolerance); assertEquals(Agent.Orientation.NORTHWEST, agent .calculateOrientationToTask()); when(agent.getDirection()).thenReturn(7 * Math.PI / 8 + tolerance); assertEquals(Agent.Orientation.WEST, agent .calculateOrientationToTask()); when(agent.getDirection()).thenReturn(9 * Math.PI / 8 - tolerance); assertEquals(Agent.Orientation.WEST, agent .calculateOrientationToTask()); when(agent.getDirection()).thenReturn(9 * Math.PI / 8 + tolerance); assertEquals(Agent.Orientation.SOUTHWEST, agent .calculateOrientationToTask()); when(agent.getDirection()).thenReturn(11 * Math.PI / 8 - tolerance); assertEquals(Agent.Orientation.SOUTHWEST, agent .calculateOrientationToTask()); when(agent.getDirection()).thenReturn(11 * Math.PI / 8 + tolerance); assertEquals(Agent.Orientation.SOUTH, agent .calculateOrientationToTask()); when(agent.getDirection()).thenReturn(13 * Math.PI / 8 - tolerance); assertEquals(Agent.Orientation.SOUTH, agent .calculateOrientationToTask()); when(agent.getDirection()).thenReturn(13 * Math.PI / 8 + tolerance); assertEquals(Agent.Orientation.SOUTHEAST, agent .calculateOrientationToTask()); when(agent.getDirection()).thenReturn(15 * Math.PI / 8 - tolerance); assertEquals(Agent.Orientation.SOUTHEAST, agent .calculateOrientationToTask()); }