1 /* Test mp*_class assignment operators.
3 Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
36 // operator=(const mpz_class &)
39 b = a; ASSERT_ALWAYS(b == 123);
42 // template <class T, class U> operator=(const __gmp_expr<T, U> &)
43 // not tested here, see t-unary.cc, t-binary.cc
45 // operator=(signed char)
49 b = a; ASSERT_ALWAYS(b == -127);
52 // operator=(unsigned char)
54 unsigned char a = 255;
56 b = a; ASSERT_ALWAYS(b == 255);
59 // either signed or unsigned char, machine dependent
62 a = 'A'; ASSERT_ALWAYS(a == 65);
66 a = 'z'; ASSERT_ALWAYS(a == 122);
69 // operator=(signed int)
73 b = a; ASSERT_ALWAYS(b == 0);
78 b = a; ASSERT_ALWAYS(b == -123);
83 b = a; ASSERT_ALWAYS(b == 32767);
86 // operator=(unsigned int)
88 unsigned int a = 65535u;
90 b = a; ASSERT_ALWAYS(b == 65535u);
93 // operator=(signed short int)
95 signed short int a = -12345;
97 b = a; ASSERT_ALWAYS(b == -12345);
100 // operator=(unsigned short int)
102 unsigned short int a = 54321u;
104 b = a; ASSERT_ALWAYS(b == 54321u);
107 // operator=(signed long int)
109 signed long int a = -1234567890L;
111 b = a; ASSERT_ALWAYS(b == -1234567890L);
114 // operator=(unsigned long int)
116 unsigned long int a = 3456789012UL;
118 b = a; ASSERT_ALWAYS(b == 3456789012UL);
125 b = a; ASSERT_ALWAYS(b == 123);
132 b = a; ASSERT_ALWAYS(b == 0);
137 b = a; ASSERT_ALWAYS(b == -12);
142 b = a; ASSERT_ALWAYS(b == 6789);
147 b = a; ASSERT_ALWAYS(b == 0);
150 // operator=(long double)
151 // currently not implemented
153 // operator=(const char *)
155 const char *a = "1234567890";
157 b = a; ASSERT_ALWAYS(b == 1234567890L);
160 // operator=(const std::string &)
162 string a("1234567890");
164 b = a; ASSERT_ALWAYS(b == 1234567890L);
167 // operator=(const char *) with invalid
170 const char *a = "abc";
173 ASSERT_ALWAYS (0); /* should not be reached */
174 } catch (invalid_argument) {
178 // operator=(const std::string &) with invalid
184 ASSERT_ALWAYS (0); /* should not be reached */
185 } catch (invalid_argument) {
193 // operator=(const mpq_class &)
195 mpq_class a(1, 2), b;
196 b = a; ASSERT_ALWAYS(b == 0.5);
199 // template <class T, class U> operator=(const __gmp_expr<T, U> &)
200 // not tested here, see t-unary.cc, t-binary.cc
202 // operator=(signed char)
204 signed char a = -127;
206 b = a; ASSERT_ALWAYS(b == -127);
209 // operator=(unsigned char)
211 unsigned char a = 255;
213 b = a; ASSERT_ALWAYS(b == 255);
216 // either signed or unsigned char, machine dependent
219 a = 'A'; ASSERT_ALWAYS(a == 65);
223 a = 'z'; ASSERT_ALWAYS(a == 122);
226 // operator=(signed int)
230 b = a; ASSERT_ALWAYS(b == 0);
235 b = a; ASSERT_ALWAYS(b == -123);
238 signed int a = 32767;
240 b = a; ASSERT_ALWAYS(b == 32767);
243 // operator=(unsigned int)
245 unsigned int a = 65535u;
247 b = a; ASSERT_ALWAYS(b == 65535u);
250 // operator=(signed short int)
252 signed short int a = -12345;
254 b = a; ASSERT_ALWAYS(b == -12345);
257 // operator=(unsigned short int)
259 unsigned short int a = 54321u;
261 b = a; ASSERT_ALWAYS(b == 54321u);
264 // operator=(signed long int)
266 signed long int a = -1234567890L;
268 b = a; ASSERT_ALWAYS(b == -1234567890L);
271 // operator=(unsigned long int)
273 unsigned long int a = 3456789012UL;
275 b = a; ASSERT_ALWAYS(b == 3456789012UL);
282 b = a; ASSERT_ALWAYS(b == 123);
289 b = a; ASSERT_ALWAYS(b == 0);
294 b = a; ASSERT_ALWAYS(b == -12.375);
299 b = a; ASSERT_ALWAYS(b == 6789);
304 b = a; ASSERT_ALWAYS(b == 0.9375);
307 // operator=(long double)
308 // currently not implemented
310 // operator=(const char *)
312 const char *a = "1234567890";
314 b = a; ASSERT_ALWAYS(b == 1234567890L);
317 // operator=(const std::string &)
319 string a("1234567890");
321 b = a; ASSERT_ALWAYS(b == 1234567890L);
324 // operator=(const char *) with invalid
327 const char *a = "abc";
330 ASSERT_ALWAYS (0); /* should not be reached */
331 } catch (invalid_argument) {
335 // operator=(const std::string &) with invalid
341 ASSERT_ALWAYS (0); /* should not be reached */
342 } catch (invalid_argument) {
350 // operator=(const mpf_class &)
353 b = a; ASSERT_ALWAYS(b == 123);
356 // template <class T, class U> operator=(const __gmp_expr<T, U> &)
357 // not tested here, see t-unary.cc, t-binary.cc
359 // operator=(signed char)
361 signed char a = -127;
363 b = a; ASSERT_ALWAYS(b == -127);
366 // operator=(unsigned char)
368 unsigned char a = 255;
370 b = a; ASSERT_ALWAYS(b == 255);
373 // either signed or unsigned char, machine dependent
376 a = 'A'; ASSERT_ALWAYS(a == 65);
380 a = 'z'; ASSERT_ALWAYS(a == 122);
383 // operator=(signed int)
387 b = a; ASSERT_ALWAYS(b == 0);
392 b = a; ASSERT_ALWAYS(b == -123);
395 signed int a = 32767;
397 b = a; ASSERT_ALWAYS(b == 32767);
400 // operator=(unsigned int)
402 unsigned int a = 65535u;
404 b = a; ASSERT_ALWAYS(b == 65535u);
407 // operator=(signed short int)
409 signed short int a = -12345;
411 b = a; ASSERT_ALWAYS(b == -12345);
414 // operator=(unsigned short int)
416 unsigned short int a = 54321u;
418 b = a; ASSERT_ALWAYS(b == 54321u);
421 // operator=(signed long int)
423 signed long int a = -1234567890L;
425 b = a; ASSERT_ALWAYS(b == -1234567890L);
428 // operator=(unsigned long int)
430 unsigned long int a = 3456789012UL;
432 b = a; ASSERT_ALWAYS(b == 3456789012UL);
439 b = a; ASSERT_ALWAYS(b == 123);
446 b = a; ASSERT_ALWAYS(b == 0);
451 b = a; ASSERT_ALWAYS(b == -12.375);
456 b = a; ASSERT_ALWAYS(b == 6789);
461 b = a; ASSERT_ALWAYS(b == 0.9375);
464 // operator=(long double)
465 // currently not implemented
467 // operator=(const char *)
469 const char *a = "1234567890";
471 b = a; ASSERT_ALWAYS(b == 1234567890L);
474 // operator=(const std::string &)
476 string a("1234567890");
478 b = a; ASSERT_ALWAYS(b == 1234567890L);
481 // operator=(const char *) with invalid
484 const char *a = "abc";
487 ASSERT_ALWAYS (0); /* should not be reached */
488 } catch (invalid_argument) {
492 // operator=(const std::string &) with invalid
498 ASSERT_ALWAYS (0); /* should not be reached */
499 } catch (invalid_argument) {