|
Last change
on this file since 47 was
29,
checked in by landauf, 17 years ago
|
|
updated boost from 1_33_1 to 1_34_1
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | # Copyright David Abrahams 2004. Distributed under the Boost |
|---|
| 2 | # Software License, Version 1.0. (See accompanying |
|---|
| 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 4 | ''' |
|---|
| 5 | >>> from operators_ext import * |
|---|
| 6 | |
|---|
| 7 | Check __nonzero__ support |
|---|
| 8 | |
|---|
| 9 | >>> assert X(2) |
|---|
| 10 | >>> assert not X(0) |
|---|
| 11 | |
|---|
| 12 | ---- |
|---|
| 13 | |
|---|
| 14 | >>> x = X(42) |
|---|
| 15 | >>> x.value() |
|---|
| 16 | 42 |
|---|
| 17 | >>> y = x - X(5) |
|---|
| 18 | >>> y.value() |
|---|
| 19 | 37 |
|---|
| 20 | >>> y = x - 4 |
|---|
| 21 | >>> y.value() |
|---|
| 22 | 38 |
|---|
| 23 | >>> y = 3 - x |
|---|
| 24 | >>> y.value() |
|---|
| 25 | -39 |
|---|
| 26 | >>> (-y).value() |
|---|
| 27 | 39 |
|---|
| 28 | |
|---|
| 29 | >>> (x + y).value() |
|---|
| 30 | 3 |
|---|
| 31 | |
|---|
| 32 | >>> abs(y).value() |
|---|
| 33 | 39 |
|---|
| 34 | |
|---|
| 35 | >>> x < 10 |
|---|
| 36 | 0 |
|---|
| 37 | >>> x < 43 |
|---|
| 38 | 1 |
|---|
| 39 | |
|---|
| 40 | >>> 10 < x |
|---|
| 41 | 1 |
|---|
| 42 | >>> 43 < x |
|---|
| 43 | 0 |
|---|
| 44 | |
|---|
| 45 | >>> x < y |
|---|
| 46 | 0 |
|---|
| 47 | >>> y < x |
|---|
| 48 | 1 |
|---|
| 49 | |
|---|
| 50 | ------ |
|---|
| 51 | >>> x > 10 |
|---|
| 52 | 1 |
|---|
| 53 | >>> x > 43 |
|---|
| 54 | 0 |
|---|
| 55 | |
|---|
| 56 | >>> 10 > x |
|---|
| 57 | 0 |
|---|
| 58 | >>> 43 > x |
|---|
| 59 | 1 |
|---|
| 60 | |
|---|
| 61 | >>> x > y |
|---|
| 62 | 1 |
|---|
| 63 | >>> y > x |
|---|
| 64 | 0 |
|---|
| 65 | |
|---|
| 66 | >>> y = x - 5 |
|---|
| 67 | >>> x -= y |
|---|
| 68 | >>> x.value() |
|---|
| 69 | 5 |
|---|
| 70 | >>> str(x) |
|---|
| 71 | '5' |
|---|
| 72 | |
|---|
| 73 | >>> z = Z(10) |
|---|
| 74 | >>> int(z) |
|---|
| 75 | 10 |
|---|
| 76 | >>> float(z) |
|---|
| 77 | 10.0 |
|---|
| 78 | >>> complex(z) |
|---|
| 79 | (10+0j) |
|---|
| 80 | |
|---|
| 81 | >>> pow(2,x) |
|---|
| 82 | 32 |
|---|
| 83 | >>> pow(x,2).value() |
|---|
| 84 | 25 |
|---|
| 85 | >>> pow(X(2),x).value() |
|---|
| 86 | 32 |
|---|
| 87 | ''' |
|---|
| 88 | |
|---|
| 89 | def run(args = None): |
|---|
| 90 | import sys |
|---|
| 91 | import doctest |
|---|
| 92 | |
|---|
| 93 | if args is not None: |
|---|
| 94 | sys.argv = args |
|---|
| 95 | return doctest.testmod(sys.modules.get(__name__)) |
|---|
| 96 | |
|---|
| 97 | if __name__ == '__main__': |
|---|
| 98 | print "running..." |
|---|
| 99 | import sys |
|---|
| 100 | status = run()[0] |
|---|
| 101 | if (status == 0): print "Done." |
|---|
| 102 | sys.exit(status) |
|---|
Note: See
TracBrowser
for help on using the repository browser.