ConstantLookup { public static double getValue(String name) { Double value = constants.get(name); if (value == null) { throw new IllegalArgumentException("Unknown constant: " + name); } return value; }  static boolean isDefined(String name); static double getValue(String name);  }
@Test public void getPI() { assertEquals(Math.PI, ConstantLookup.getValue("M_PI"), TOL); }
@Test public void getPIOn2() { assertEquals(Math.PI / 2.0, ConstantLookup.getValue("M_PI_2"), TOL); }
@Test public void getPIOn4() { assertEquals(Math.PI / 4.0, ConstantLookup.getValue("M_PI_4"), TOL); }
@Test public void getSqrt2() { assertEquals(Math.sqrt(2.0), ConstantLookup.getValue("M_SQRT2"), TOL); }
@Test public void getE() { assertEquals(Math.E, ConstantLookup.getValue("M_E"), TOL); }
@Test public void getNanPrefix() { assertTrue(Double.isNaN( ConstantLookup.getValue("M_NaN"))); assertTrue(Double.isNaN( ConstantLookup.getValue("M_NAN"))); }
@Test public void getNanNoPrefix() { assertTrue(Double.isNaN( ConstantLookup.getValue("NaN"))); assertTrue(Double.isNaN( ConstantLookup.getValue("NAN"))); }
@Test(expected=IllegalArgumentException.class) public void unknownConstant() { ConstantLookup.getValue("NotAConstant"); }