MoodSystem extends BaseSystem { public int scoreIntensityLevelOutOf(final int subdivisions) { int res = (short) Math.round((float) intensity / (float) MAX_INTENSITY * (float) subdivisions); if (res > subdivisions) { res = subdivisions; } logger.trace("intensity level " + intensity + " scored as " + res + "/" + subdivisions); return res; } MoodSystem(EventManager eventManager); @Override void processSystem(); int scoreIntensityLevelOutOf(final int subdivisions); static final int MAX_INTENSITY; static final HashMap<String, Integer> CA_INTENSITY_MAP; public int intensity; }
@Test public void testIntensityLevelScorerMax() { MoodSystem moodSystem = new MoodSystem(new EventManager()); moodSystem.intensity = MoodSystem.MAX_INTENSITY; int res = moodSystem.scoreIntensityLevelOutOf(10); assert res == 10; }
@Test public void testIntensityLevelScorerGreaterThanMax() { MoodSystem moodSystem = new MoodSystem(new EventManager()); moodSystem.intensity = MoodSystem.MAX_INTENSITY * 2; int res = moodSystem.scoreIntensityLevelOutOf(10); assert res == 10; }
@Test public void testIntensityLevelScorerMiddle() { MoodSystem moodSystem = new MoodSystem(new EventManager()); moodSystem.intensity = MoodSystem.MAX_INTENSITY / 2; int res = moodSystem.scoreIntensityLevelOutOf(10); assert res <= 6 && res >= 4; }