public String getDescription() { if (value == null) return unit; return value.toString()+unit; }
@Override public String getDescription() { return super.getDescription()+" = "+value.toString(); }
private void runConversionCase(XmlPullParser xpp) throws XmlPullParserException, IOException, UcumException { String id = xpp.getAttributeValue(null, "id"); String value = xpp.getAttributeValue(null, "value"); String srcUnit = xpp.getAttributeValue(null, "srcUnit"); String dstUnit = xpp.getAttributeValue(null, "dstUnit"); String outcome = xpp.getAttributeValue(null, "outcome"); System.out.println("case "+id+": "+value+" "+srcUnit+" -> "+outcome+" "+dstUnit); Decimal res = ucumSvc.convert(new Decimal(value), srcUnit, dstUnit); debug("Convert Test "+id+": the value '"+value+" "+srcUnit+"' ==> "+res.toString()+" "+dstUnit); // if (!res.toPlainString().equals(outcome)) { - that assumes that we can get the precision right, which we can't if (res.comparesTo(new Decimal(outcome)) != 0) { errCount++; System.err.println("Test "+id+": The value '"+outcome+"' was expected the result was "+res.toString()); } while (xpp.getEventType() != XmlPullParser.END_TAG) xpp.next(); xpp.next(); }
public int asInteger() throws UcumException { if (!isWholeNumber()) throw new UcumException("Unable to represent "+toString()+" as an integer"); if (comparesTo(new Decimal(Integer.MIN_VALUE)) < 0) throw new UcumException("Unable to represent "+toString()+" as a signed 8 byte integer"); if (comparesTo(new Decimal(Integer.MAX_VALUE)) > 0) throw new UcumException("Unable to represent "+toString()+" as a signed 8 byte integer"); return Integer.parseInt(asDecimal()); }
private void testString(String s, String st, String std) throws UcumException { Decimal dec = new Decimal(s); String s1 = dec.toString(); String s2 = dec.asScientific(); check(s1.equals(st), "decimal: expected "+st+" but got "+s1); check(s2.equals(std), "scientific: expected "+std+" but got "+s2); dec = new Decimal(std); s1 = dec.asDecimal(); check(s1.equals(st), "decimal(2): expected "+st+" but got "+s1); }
private void runMultiplicationCase(XmlPullParser xpp) throws XmlPullParserException, IOException, UcumException { String id = xpp.getAttributeValue(null, "id"); String v1 = xpp.getAttributeValue(null, "v1"); String u1 = xpp.getAttributeValue(null, "u1"); String v2 = xpp.getAttributeValue(null, "v2"); String u2 = xpp.getAttributeValue(null, "u2"); String vRes = xpp.getAttributeValue(null, "vRes"); String uRes = xpp.getAttributeValue(null, "uRes"); Pair o1 = new Pair(new Decimal(v1), u1); Pair o2 = new Pair(new Decimal(v2), u2); Pair o3 = ucumSvc.multiply(o1, o2); debug("Multiplication Test "+id+": the value '"+v1+" "+u1+"' * '"+v2+" "+u2+"' ==> "+o3.getValue().toString()+" "+o3.getCode()); // if (!res.toPlainString().equals(outcome)) { - that assumes that we can get the precision right, which we can't if (o3.getValue().comparesTo(new Decimal(vRes)) != 0 || !o3.getCode().equals(uRes)) { errCount++; System.err.println("Test "+id+": The value '"+vRes+" "+uRes+"' was expected, but the result was "+o3.getValue().toString()+" "+o3.getCode()); } while (xpp.getEventType() != XmlPullParser.END_TAG) xpp.next(); xpp.next(); }
throw new UcumException("Attempt to divide "+toString()+" by zero");
public String getDescription() { if (value == null) return unit; return value.toString()+unit; }
@Override public String getDescription() { return super.getDescription()+" = "+value.toString(); }
private void runConversionCase(XmlPullParser xpp) throws XmlPullParserException, IOException, UcumException { String id = xpp.getAttributeValue(null, "id"); String value = xpp.getAttributeValue(null, "value"); String srcUnit = xpp.getAttributeValue(null, "srcUnit"); String dstUnit = xpp.getAttributeValue(null, "dstUnit"); String outcome = xpp.getAttributeValue(null, "outcome"); System.out.println("case "+id+": "+value+" "+srcUnit+" -> "+outcome+" "+dstUnit); Decimal res = ucumSvc.convert(new Decimal(value), srcUnit, dstUnit); debug("Convert Test "+id+": the value '"+value+" "+srcUnit+"' ==> "+res.toString()+" "+dstUnit); // if (!res.toPlainString().equals(outcome)) { - that assumes that we can get the precision right, which we can't if (res.comparesTo(new Decimal(outcome)) != 0) { errCount++; System.err.println("Test "+id+": The value '"+outcome+"' was expected the result was "+res.toString()); } while (xpp.getEventType() != XmlPullParser.END_TAG) xpp.next(); xpp.next(); }
public int asInteger() throws UcumException { if (!isWholeNumber()) throw new UcumException("Unable to represent "+toString()+" as an integer"); if (comparesTo(new Decimal(Integer.MIN_VALUE)) < 0) throw new UcumException("Unable to represent "+toString()+" as a signed 8 byte integer"); if (comparesTo(new Decimal(Integer.MAX_VALUE)) > 0) throw new UcumException("Unable to represent "+toString()+" as a signed 8 byte integer"); return Integer.parseInt(asDecimal()); }
private void testString(String s, String st, String std) throws UcumException { Decimal dec = new Decimal(s); String s1 = dec.toString(); String s2 = dec.asScientific(); check(s1.equals(st), "decimal: expected "+st+" but got "+s1); check(s2.equals(std), "scientific: expected "+std+" but got "+s2); dec = new Decimal(std); s1 = dec.asDecimal(); check(s1.equals(st), "decimal(2): expected "+st+" but got "+s1); }
private void runMultiplicationCase(XmlPullParser xpp) throws XmlPullParserException, IOException, UcumException { String id = xpp.getAttributeValue(null, "id"); String v1 = xpp.getAttributeValue(null, "v1"); String u1 = xpp.getAttributeValue(null, "u1"); String v2 = xpp.getAttributeValue(null, "v2"); String u2 = xpp.getAttributeValue(null, "u2"); String vRes = xpp.getAttributeValue(null, "vRes"); String uRes = xpp.getAttributeValue(null, "uRes"); Pair o1 = new Pair(new Decimal(v1), u1); Pair o2 = new Pair(new Decimal(v2), u2); Pair o3 = ucumSvc.multiply(o1, o2); debug("Multiplication Test "+id+": the value '"+v1+" "+u1+"' * '"+v2+" "+u2+"' ==> "+o3.getValue().toString()+" "+o3.getCode()); // if (!res.toPlainString().equals(outcome)) { - that assumes that we can get the precision right, which we can't if (o3.getValue().comparesTo(new Decimal(vRes)) != 0 || !o3.getCode().equals(uRes)) { errCount++; System.err.println("Test "+id+": The value '"+vRes+" "+uRes+"' was expected, but the result was "+o3.getValue().toString()+" "+o3.getCode()); } while (xpp.getEventType() != XmlPullParser.END_TAG) xpp.next(); xpp.next(); }
throw new UcumException("Attempt to divide "+toString()+" by zero");