summaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
authorMorgan Deters <mdeters@gmail.com>2012-08-14 20:08:29 +0000
committerMorgan Deters <mdeters@gmail.com>2012-08-14 20:08:29 +0000
commitd8fd737fb9ca867f53a287de1c4a87f16a6834f7 (patch)
tree4f1e4195a97162e0888fcf9c18c1a4d13f422f2f /test/unit
parent87dbe20de92232279cf1d48ebfe7113194985208 (diff)
Fixes to integer wrapper classes:
* more uniform interface between the CLN and GMP wrappers * support base inference (base == 0) on parsing strings with the CLN wrapper; this was a difference from the GMP wrapper (resolves bug #372)
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/util/integer_black.h20
-rw-r--r--test/unit/util/subrange_bound_white.h4
2 files changed, 22 insertions, 2 deletions
diff --git a/test/unit/util/integer_black.h b/test/unit/util/integer_black.h
index 06be9e57d..a2641e118 100644
--- a/test/unit/util/integer_black.h
+++ b/test/unit/util/integer_black.h
@@ -283,6 +283,26 @@ public:
TS_ASSERT_EQUALS(res, large.toString());
}
+ void testBaseInference() {
+ TS_ASSERT_EQUALS(Integer("0xa", 0), 10);
+ TS_ASSERT_EQUALS(Integer("0xff", 0), 255);
+ TS_ASSERT_EQUALS(Integer("011", 0), 9);
+ TS_ASSERT_EQUALS(Integer("0b1010", 0), 10);
+ TS_ASSERT_EQUALS(Integer("-1", 0), -1);
+ TS_ASSERT_EQUALS(Integer("42", 0), 42);
+ }
+
+ void testParseErrors() {
+ TS_ASSERT_THROWS(Integer("abracadabra"), std::invalid_argument);
+ TS_ASSERT_THROWS(Integer("+-1"), std::invalid_argument);
+ TS_ASSERT_THROWS(Integer("-+1"), std::invalid_argument);
+ TS_ASSERT_THROWS(Integer("5i"), std::invalid_argument);
+ TS_ASSERT_THROWS(Integer("10xyz"), std::invalid_argument);
+ TS_ASSERT_THROWS(Integer("0xff", 10), std::invalid_argument);
+ TS_ASSERT_THROWS(Integer("#x5", 0), std::invalid_argument);
+ TS_ASSERT_THROWS(Integer("0b123", 0), std::invalid_argument);
+ }
+
void testPow() {
TS_ASSERT_EQUALS( Integer(1), Integer(1).pow(0) );
TS_ASSERT_EQUALS( Integer(1), Integer(5).pow(0) );
diff --git a/test/unit/util/subrange_bound_white.h b/test/unit/util/subrange_bound_white.h
index d7587d679..762c43809 100644
--- a/test/unit/util/subrange_bound_white.h
+++ b/test/unit/util/subrange_bound_white.h
@@ -39,7 +39,7 @@ public:
}
void testZero() {
- SubrangeBound b1(0), b2(string("0")), b3(Integer("1"));
+ SubrangeBound b1(0), b2(Integer("0")), b3(Integer("1"));
TS_ASSERT( b1.hasBound() && b2.hasBound() && b3.hasBound() );
TS_ASSERT( b1.getBound() == 0 && b2.getBound() == 0 && b3.getBound() == 1 );
TS_ASSERT( b1 == b2 ); TS_ASSERT( b2 == b1 );
@@ -57,7 +57,7 @@ public:
}
void testOne() {
- SubrangeBound b(string("1"));
+ SubrangeBound b(Integer("1"));
TS_ASSERT( b.hasBound() );
TS_ASSERT( b.getBound() == 1 );
ss.str(""); ss << b;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback