private static Rational rational(final String s) { return Rational.valueOf(s); }
/** * Test that the denominator cannot be zero */ @Test(expected = NumberFormatException.class) public void invalidParseZeroDenominator() { Rational.valueOf(" 3 / 0"); }
/** * Test that the denominator cannot be negative */ @Test(expected = NumberFormatException.class) public void invalidParseNegativeDenominator() { Rational.valueOf(" 3 / -3"); }
/** * Test that the denominator cannot be a decimal value */ @Test(expected = NumberFormatException.class) public void invalidParseDecimalDenominator() { Rational.valueOf(" 1 / 3.3"); }
/** * Test that the numerator cannot be a decimal value */ @Test(expected = NumberFormatException.class) public void invalidParseDecimalNumerator() { Rational.valueOf(" 1.1 / 3"); }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { final String lexicalForm = getLexicalForm(literal); try { return OWLRealUtils.getCanonicalObject(Rational.valueOf(lexicalForm)); } catch (final NumberFormatException e) { throw new InvalidLiteralException(getName(), lexicalForm, e); } }
@Override public Number getValue(final ATermAppl literal) throws InvalidLiteralException { final String lexicalForm = getLexicalForm(literal); try { return OWLRealUtils.getCanonicalObject(Rational.valueOf(lexicalForm)); } catch (final NumberFormatException e) { throw new InvalidLiteralException(getName(), lexicalForm, e); } }
/** * Test parsing of valid values */ @Test public void validParse() { Rational r; r = Rational.valueOf("1 / 3"); assertNotNull(r); assertEquals(new Rational(OWLRealUtils.getCanonicalObject(1), OWLRealUtils.getCanonicalObject(3)), r); r = Rational.valueOf("12 / 36"); assertNotNull(r); assertEquals(new Rational(OWLRealUtils.getCanonicalObject(12), OWLRealUtils.getCanonicalObject(36)), r); r = Rational.valueOf("-1 / 3"); assertNotNull(r); assertEquals(new Rational(OWLRealUtils.getCanonicalObject(-1), OWLRealUtils.getCanonicalObject(3)), r); } }