]> www.ginac.de Git - ginac.git/blob - check/exam_relational.cpp
Finalize 1.8.1 release.
[ginac.git] / check / exam_relational.cpp
1 /** @file exam_relational.cpp
2  *
3  *  Small test for the relational objects and their conversion to bool. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2021 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #include "ginac.h"
24 using namespace GiNaC;
25
26 #include <iostream>
27 using namespace std;
28
29 // Elementary relations should fall back to numeric comparisons.
30 static unsigned exam_relational_elementary()
31 {
32         unsigned result = 0;
33         ex one = 1, two = 2;
34
35         if (one == two) {
36                 clog << "'" << one << " == " << two << "' was converted to true." << endl;
37                 result += 1;
38         }
39         if (!(one != two)) {
40                 clog << "'" << one << " != " << two << "' was not converted to true." << endl;
41                 result += 1;
42         }
43         if (!(one < two)) {
44                 clog << "'" << one << " < " << two << "' was not converted to true." << endl;
45                 result += 1;
46         }
47         if (!(one <= two)) {
48                 clog << "'" << one << " <= " << two << "' was not converted to true." << endl;
49                 result += 1;
50         }
51         if (one > two) {
52                 clog << "'" << one << " > " << two << "' was converted to true." << endl;
53                 result += 1;
54         }
55         if (one >= two) {
56                 clog << "'" << one << " >= " << two << "' was converted to true." << endl;
57                 result += 1;
58         }
59
60         return result;
61 }
62
63 // These should fall back to looking up info flags.
64 static unsigned exam_relational_possymbol()
65 {
66         unsigned result = 0;
67         possymbol p("p");
68
69         if (p == 0) {
70                 clog << "for positive p, 'p == 0' was converted to true." << endl;
71                 result += 1;
72         }
73         if (!(p != 0)) {
74                 clog << "for positive p, 'p != 0' was not converted to true." << endl;
75                 result += 1;
76         }
77         if (p < 0) {
78                 clog << "for positive p, 'p < 0' was converted to true." << endl;
79                 result += 1;
80         }
81         if (p <= 0) {
82                 clog << "for positive p, 'p <= 0' was converted to true." << endl;
83                 result += 1;
84         }
85         if (!(p > 0)) {
86                 clog << "for positive p, 'p > 0' was not converted to true." << endl;
87                 result += 1;
88         }
89         if (!(p >= 0)) {
90                 clog << "for positive p, 'p >= 0' was not converted to true." << endl;
91                 result += 1;
92         }
93
94         return result;
95 }
96
97 // Very simple arithmetic should be supported, too.
98 static unsigned exam_relational_arith()
99 {
100         unsigned result = 0;
101         possymbol p("p");
102
103         if (!(p + 2 > p + 1)) {
104                 clog << "for positive p, 'p + 2 > p + 1' was not converted to true." << endl;
105                 result += 1;
106         }
107         if (!(p > -p)) {
108                 clog << "for positive p, 'p > -p' was not converted to true." << endl;
109                 result += 1;
110         }
111         if (!(2*p > p)) {
112                 clog << "for positive p, '2*p > p' was not converted to true." << endl;
113                 result += 1;
114         }
115
116         return result;
117 }
118
119 unsigned exam_relational()
120 {
121         unsigned result = 0;
122
123         cout << "examining relational objects" << flush;
124
125         result += exam_relational_elementary(); cout << '.' << flush;
126         result += exam_relational_possymbol(); cout << '.' << flush;
127         result += exam_relational_arith(); cout << '.' << flush;
128
129         return result;
130 }
131
132 int main(int argc, char** argv)
133 {
134         return exam_relational();
135 }