/
tests.cpp
214 lines (147 loc) · 3.3 KB
/
tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
#include "roots.h"
#include "poly.h"
#include "parser.h"
#include "expr.h"
#include "tests.h"
using namespace std;
void test_unit_1()
{
char buf[4096];
int code = 0;
Poly5 f(5);
Poly5 g(5);
Poly5 f1(5);
Poly5 f2(5);
Poly5 f3(5);
fstream tstfile("test.data");
while (! tstfile.eof()) {
tstfile.getline(buf, 4096);
//cout << buf << endl;
if (buf[0] == 'L') {
code = atoi(buf + 1);
tstfile.getline(buf, 4096);
if (tstfile.eof()) {
break;
}
}
if (code == 1) {
f.read(buf);
}
if( code == 2) {
g.read(buf);
}
if (code == 3) { // f + g
f1.read(buf);
//cout << "f1 = " << f1 << endl;
Poly5 f1c = f1;
Poly5 fc = f;
fc.add(g);
f1c.mul(Poly5(-1,0,0, 5));
f1c.add(fc);
cout << "f11 = " << f1c << endl;
}
if (code == 4) { // f * g
f2.read(buf);
Poly5 f2c = f2;
Poly5 fc = f;
fc.mul(g);
f2c.mul(Poly5(-1,0,0, 5));
f2c.add(fc);
cout << "f21 = " << f2c << endl;
}
if (code == 5) { // f^3 + g^2
f3.read(buf);
Poly5 f3c = f3;
Poly5 fc = f;
fc.pow(3);
Poly5 gc = g;
gc.pow(2);
fc.add(gc);
fc.mul(Poly5(-1,0,0, 5));
fc.add(f3c);
cout << "fc = " << fc << endl;
}
code = 0;
}
cout << "press key." << endl;
getchar();
}
void test_unit_2()
{
Poly5 p4(5);
Poly5 p5(5);
Poly5 p6(5);
p4.read("(x+y)^5*z^2*a^3*b^4");
Poly4 p14(4);
Poly3 p13(3);
Poly2 p12(2);
Poly1 p11(1);
p4.eval_last(1, p14);
p14.eval_last(1, p13);
p13.eval_last(1, p12);
p12.eval_last(1, p11);
cout << "(x+1)^5 = " << p11 << endl;
p4 = Poly5(0,0,0, 5);
int ret = p4.read("x^3 + y^5 + z^4");
cout << "ret = " << ret << endl;
cout << "x^3 + y^5 + z^4 " << p4 << endl;
cout << "press key." << endl;
getchar();
p4 = Poly5(0,0,0, 5);
ret = p4.read("(a+b)*(x+y)");
cout << "ret = " << ret << endl;
cout << "(a+b)*(x+y) = " << p4 << endl;
cout << "press key." << endl;
getchar();
ret = p5.read(
"-6*x*y*z -3*x^2 -6*x*y -6*x*z -3*y^2 -6 * y * z -3 * z^2 -3 * x^2 * y -3 * x^2 *z"
"-3 * x* y^2 -3 * x * z^2 -3 * y^2 *z - 3 * y * z^2 - 3 * x -3 * y - 3 * z"
"");
cout << "ret = " << ret << endl;
cout << "clebsch cubic 1 = " << p5 << endl;
getchar();
p6 = Poly5(0,0,0, 5);
ret = p6.read("x^3+y^3+z^3 + 1 + (-1)*(x+y+z+1)^3");
cout << "clebsch cubic 2 = " << p6 << endl;
p6.mul(Poly5(-1,0,0, 5));
p6.add(p5);
cout << "difference = " << p6 << endl;
getchar();
p6.read("x + a*y + b*z");
cout << "x + a * y + b * z = " << p6 << endl;
double substmat[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
p6.subst_mat(3, substmat);
cout << "p6 substituted = " << p6 << endl;
getchar();
}
void test_unit_3(std::string line)
{
cout << "Test Lexer:" << endl;
lexer_test_fun(line);
cout << "Press key." << endl;
getchar();
cout << "Test Parser:" << endl;
parser_test_fun(line);
cout << "Press key." << endl;
getchar();
}
void test_unit(std::string line)
{
if (1)
{
test_expr_1(line);
cout << "Press key" << endl;
getchar();
}
test_unit_3(line);
test_unit_1();
test_unit_2();
cout << "test root_list" << endl;
test_root_list();
cout << "press key." << endl;
getchar();
}