1 /********************* */
2 /*! \file integer_black.h
4 ** Original author: taking
5 ** Major contributors: none
6 ** Minor contributors (to current version): cconway, mdeters
7 ** This file is part of the CVC4 prototype.
8 ** Copyright (c) 2009, 2010 The Analysis of Computer Systems Group (ACSys)
9 ** Courant Institute of Mathematical Sciences
10 ** New York University
11 ** See the file COPYING in the top-level source directory for licensing
12 ** information.\endverbatim
14 ** \brief Black box testing of CVC4::Integer.
16 ** Black box testing of CVC4::Integer.
19 #include <cxxtest/TestSuite.h>
22 #include "util/integer.h"
27 const char* largeVal
= "4547897890548754897897897897890789078907890";
29 class IntegerBlack
: public CxxTest::TestSuite
{
34 void testConstructors() {
36 TS_ASSERT_EQUALS(z0
.getLong(), 1);
39 TS_ASSERT_EQUALS(z1
.getLong(), 0);
42 TS_ASSERT_EQUALS(z2
.getLong(), -1);
45 TS_ASSERT_EQUALS(z3
.getUnsignedLong(), 0x890UL
);
48 TS_ASSERT_EQUALS(z4
.getLong(), 0);
50 Integer
z5("7896890");
51 TS_ASSERT_EQUALS(z5
.getUnsignedLong(), 7896890ul);
54 TS_ASSERT_EQUALS(z5
.getUnsignedLong(), 7896890ul);
55 TS_ASSERT_EQUALS(z6
.getUnsignedLong(), 7896890ul);
58 string
bigValue("1536729");
60 TS_ASSERT_EQUALS(z7
.getUnsignedLong(), 1536729ul);
63 void testCompareAgainstZero(){
65 TS_ASSERT_THROWS_NOTHING(z
== 0;);
66 TS_ASSERT_EQUALS(z
,0);
69 void testOperatorAssign(){
74 TS_ASSERT_EQUALS(x
.getUnsignedLong(), 0ul);
75 TS_ASSERT_EQUALS(y
.getUnsignedLong(), 79ul);
76 TS_ASSERT_EQUALS(z
.getUnsignedLong(), 45789ul);
80 TS_ASSERT_EQUALS(x
.getUnsignedLong(), 45789ul);
81 TS_ASSERT_EQUALS(y
.getUnsignedLong(), 45789ul);
82 TS_ASSERT_EQUALS(z
.getUnsignedLong(), 45789ul);
88 TS_ASSERT_EQUALS(a
.getUnsignedLong(), 2ul);
89 TS_ASSERT_EQUALS(y
.getUnsignedLong(), 2ul);
90 TS_ASSERT_EQUALS(x
.getUnsignedLong(), 45789ul);
91 TS_ASSERT_EQUALS(z
.getUnsignedLong(), 45789ul);
94 void testOperatorEquals(){
122 void testOperatorNotEquals(){
150 void testOperatorSubtract(){
156 Integer act0
= x
- x
;
157 Integer act1
= x
- y
;
158 Integer act2
= x
- z
;
164 Integer act3
= y
- x
;
165 Integer act4
= y
- y
;
166 Integer act5
= y
- z
;
172 Integer act6
= z
- x
;
173 Integer act7
= z
- y
;
174 Integer act8
= z
- z
;
181 TS_ASSERT_EQUALS(act0
, exp0
);
182 TS_ASSERT_EQUALS(act1
, exp1
);
183 TS_ASSERT_EQUALS(act2
, exp2
);
184 TS_ASSERT_EQUALS(act3
, exp3
);
185 TS_ASSERT_EQUALS(act4
, exp4
);
186 TS_ASSERT_EQUALS(act5
, exp5
);
187 TS_ASSERT_EQUALS(act6
, exp6
);
188 TS_ASSERT_EQUALS(act7
, exp7
);
189 TS_ASSERT_EQUALS(act8
, exp8
);
191 void testOperatorAdd(){
197 Integer act0
= x
+ x
;
198 Integer act1
= x
+ y
;
199 Integer act2
= x
+ z
;
205 Integer act3
= y
+ x
;
206 Integer act4
= y
+ y
;
207 Integer act5
= y
+ z
;
213 Integer act6
= z
+ x
;
214 Integer act7
= z
+ y
;
215 Integer act8
= z
+ z
;
222 TS_ASSERT_EQUALS(act0
, exp0
);
223 TS_ASSERT_EQUALS(act1
, exp1
);
224 TS_ASSERT_EQUALS(act2
, exp2
);
225 TS_ASSERT_EQUALS(act3
, exp3
);
226 TS_ASSERT_EQUALS(act4
, exp4
);
227 TS_ASSERT_EQUALS(act5
, exp5
);
228 TS_ASSERT_EQUALS(act6
, exp6
);
229 TS_ASSERT_EQUALS(act7
, exp7
);
230 TS_ASSERT_EQUALS(act8
, exp8
);
233 void testOperatorMult(){
239 Integer act0
= x
* x
;
240 Integer act1
= x
* y
;
241 Integer act2
= x
* z
;
247 Integer act3
= y
* x
;
248 Integer act4
= y
* y
;
249 Integer act5
= y
* z
;
255 Integer act6
= z
* x
;
256 Integer act7
= z
* y
;
257 Integer act8
= z
* z
;
264 TS_ASSERT_EQUALS(act0
, exp0
);
265 TS_ASSERT_EQUALS(act1
, exp1
);
266 TS_ASSERT_EQUALS(act2
, exp2
);
267 TS_ASSERT_EQUALS(act3
, exp3
);
268 TS_ASSERT_EQUALS(act4
, exp4
);
269 TS_ASSERT_EQUALS(act5
, exp5
);
270 TS_ASSERT_EQUALS(act6
, exp6
);
271 TS_ASSERT_EQUALS(act7
, exp7
);
272 TS_ASSERT_EQUALS(act8
, exp8
);
276 void testToStringStuff(){
278 Integer
large (largeVal
);
280 string res
= ss
.str();
282 TS_ASSERT_EQUALS(res
, large
.toString());
286 TS_ASSERT_EQUALS( Integer(1), Integer(1).pow(0) );
287 TS_ASSERT_EQUALS( Integer(1), Integer(5).pow(0) );
288 TS_ASSERT_EQUALS( Integer(1), Integer(-1).pow(0) );
289 TS_ASSERT_EQUALS( Integer(0), Integer(0).pow(1) );
290 TS_ASSERT_EQUALS( Integer(5), Integer(5).pow(1) );
291 TS_ASSERT_EQUALS( Integer(-5), Integer(-5).pow(1) );
292 TS_ASSERT_EQUALS( Integer(16), Integer(2).pow(4) );
293 TS_ASSERT_EQUALS( Integer(16), Integer(-2).pow(4) );
294 TS_ASSERT_EQUALS( Integer(1000), Integer(10).pow(3) );
295 TS_ASSERT_EQUALS( Integer(-1000), Integer(-10).pow(3) );