CategoricalScale { public ScaleCategory scaleRawValue(int rawValue) throws EepOutOfRangeException { for(ScaleCategory category : categories) { if(category.fallsIntoCategory(rawValue)) { return category; } } throw new EepOutOfRangeException( "Raw value ''{0}'' is not within the valid scale ranges : {1}", categories ); } CategoricalScale(Set<ScaleCategory> categories);  CategoricalScale(ScaleCategory...categories); ScaleCategory scaleRawValue(int rawValue);  }
@Test public void testBasicConstruction() throws Exception { ScaleCategory category1 = new ScaleCategory("Category 1", 0, 49, "CAT1", 1); ScaleCategory category2 = new ScaleCategory("Category 2", 50, 99, "CAT2", 2); Set<ScaleCategory> categories = new HashSet<ScaleCategory>(); categories.add(category1); categories.add(category2); CategoricalScale scale = new CategoricalScale(categories); ScaleCategory scaledCategory = scale.scaleRawValue(25); Assert.assertEquals(category1, scaledCategory); scale = new CategoricalScale(category1, category2); scaledCategory = scale.scaleRawValue(25); Assert.assertEquals(category1, scaledCategory); }
@Test public void testScaling() throws Exception { ScaleCategory category1 = new ScaleCategory("Category 1", 0, 49, "CAT1", 1); ScaleCategory category2 = new ScaleCategory("Category 2", 50, 99, "CAT2", 2); Set<ScaleCategory> categories = new HashSet<ScaleCategory>(); categories.add(category1); categories.add(category2); CategoricalScale scale = new CategoricalScale(categories); ScaleCategory scaledCategory = scale.scaleRawValue(49); Assert.assertEquals(category1, scaledCategory); scaledCategory = scale.scaleRawValue(50); Assert.assertEquals(category2, scaledCategory); scaledCategory = scale.scaleRawValue(99); Assert.assertEquals(category2, scaledCategory); }
@Test public void testScaleOutOfRangeValue() throws Exception { ScaleCategory category1 = new ScaleCategory("Category 1", 0, 49, "CAT1", 1); ScaleCategory category2 = new ScaleCategory("Category 2", 50, 99, "CAT2", 2); CategoricalScale scale = new CategoricalScale(category1, category2); try { ScaleCategory scaleCategory = scale.scaleRawValue(100); Assert.fail(); } catch (EepOutOfRangeException e) { } }