** See the file COPYING in the top-level source directory for licensing
** information.
**
- ** A multiprecision rational constant.
- ** This stores the rational as a pair of multiprecision integers,
- ** one for the numerator and one for the denominator.
- ** The number is always stored so that the gcd of the numerator and denominator
- ** is 1. (This is referred to as referred to as canonical form in GMP's
- ** literature.) A consquence is that that the numerator and denominator may be
- ** different than the values used to construct the Rational.
+ ** Multi-precision rational constants.
**/
#include "cvc4_public.h"
namespace CVC4 {
+/**
+ ** A multi-precision rational constant.
+ ** This stores the rational as a pair of multi-precision integers,
+ ** one for the numerator and one for the denominator.
+ ** The number is always stored so that the gcd of the numerator and denominator
+ ** is 1. (This is referred to as referred to as canonical form in GMP's
+ ** literature.) A consequence is that that the numerator and denominator may be
+ ** different than the values used to construct the Rational.
+ **
+ ** NOTE: The correct way to create a Rational from an int is to use one of the
+ ** int numerator/int denominator constructors with the denominator 1. Trying
+ ** to construct a Rational with a single int, e.g., Rational(0), will put you
+ ** in danger of invoking the char* constructor, from whence you will segfault.
+ **/
+
class Rational {
private:
/**
/********************* */
-/** integer_black.h
+/** bitvector_black.h
** Original author: taking
** Major contributors: none
** Minor contributors (to current version): none
** See the file COPYING in the top-level source directory for licensing
** information.
**
- ** Black box testing of CVC4::Integer.
+ ** Black box testing of CVC4::BitVector.
**/
#include <cxxtest/TestSuite.h>
--- /dev/null
+/********************* */
+/** rational_black.h
+ ** Original author: cconway
+ ** Major contributors: none
+ ** Minor contributors (to current version): none
+ ** This file is part of the CVC4 prototype.
+ ** Copyright (c) 2009, 2010 The Analysis of Computer Systems Group (ACSys)
+ ** Courant Institute of Mathematical Sciences
+ ** New York University
+ ** See the file COPYING in the top-level source directory for licensing
+ ** information.
+ **
+ ** Black box testing of CVC4::Rational.
+ **/
+
+#include <cxxtest/TestSuite.h>
+#include <sstream>
+
+#include "util/rational.h"
+
+using namespace CVC4;
+using namespace std;
+
+const char* canReduce = "4547897890548754897897897897890789078907890/54878902347890234";
+
+class RationalBlack : public CxxTest::TestSuite {
+public:
+
+ void testFromDecimal() {
+ TS_ASSERT_EQUALS( Rational(0,1), Rational::fromDecimal("0") );
+ TS_ASSERT_EQUALS( Rational(1,1), Rational::fromDecimal("1") );
+ TS_ASSERT_EQUALS( Rational(-1,1), Rational::fromDecimal("-1") );
+ TS_ASSERT_EQUALS( Rational(3,2), Rational::fromDecimal("1.5") );
+ TS_ASSERT_EQUALS( Rational(-3,2), Rational::fromDecimal("-1.5") );
+ TS_ASSERT_EQUALS( Rational(7,10), Rational::fromDecimal(".7") );
+ TS_ASSERT_EQUALS( Rational(-7,10), Rational::fromDecimal("-.7") );
+ TS_ASSERT_EQUALS( Rational(5,1), Rational::fromDecimal("5.") );
+ TS_ASSERT_EQUALS( Rational(-5,1), Rational::fromDecimal("-5.") );
+ TS_ASSERT_EQUALS( Rational(12345,100), Rational::fromDecimal("123.45") );
+
+ TS_ASSERT_THROWS( Rational::fromDecimal("1.2.3");, const std::invalid_argument& );
+ TS_ASSERT_THROWS( Rational::fromDecimal("1.2/3");, const std::invalid_argument& );
+ TS_ASSERT_THROWS( Rational::fromDecimal("Hello, world!");, const std::invalid_argument& );
+
+ Rational(1);
+ }
+
+};