diff options
author | Christopher L. Conway <christopherleeconway@gmail.com> | 2010-05-06 20:08:04 +0000 |
---|---|---|
committer | Christopher L. Conway <christopherleeconway@gmail.com> | 2010-05-06 20:08:04 +0000 |
commit | c52d38c2a134488c5212f21d963a1ae442206fc1 (patch) | |
tree | 3f97c1da41b1b16b7e85c77412831776c3312b37 /test | |
parent | a7e4f9c4af64e669db9df5cd13524b1ab3e47379 (diff) |
Adding tests for Rational::fromDecimal
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/Makefile.am | 3 | ||||
-rw-r--r-- | test/unit/util/bitvector_black.h | 4 | ||||
-rw-r--r-- | test/unit/util/rational_black.h | 48 |
3 files changed, 52 insertions, 3 deletions
diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 2ec5122f3..b3a8e12eb 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -27,7 +27,8 @@ UNIT_TESTS = \ util/exception_black \ util/integer_black \ util/integer_white \ - util/rational_white + util/rational_black \ + util/rational_white # Things that aren't tests but that tests rely on and need to # go into the distribution diff --git a/test/unit/util/bitvector_black.h b/test/unit/util/bitvector_black.h index f35107af0..08e1216f1 100644 --- a/test/unit/util/bitvector_black.h +++ b/test/unit/util/bitvector_black.h @@ -1,5 +1,5 @@ /********************* */ -/** integer_black.h +/** bitvector_black.h ** Original author: taking ** Major contributors: none ** Minor contributors (to current version): none @@ -10,7 +10,7 @@ ** 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> diff --git a/test/unit/util/rational_black.h b/test/unit/util/rational_black.h new file mode 100644 index 000000000..395a5099d --- /dev/null +++ b/test/unit/util/rational_black.h @@ -0,0 +1,48 @@ +/********************* */ +/** 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); + } + +}; |