|
| 1 | +* test the functionality of the series package |
| 2 | +* https://github.com/a-maier/series |
| 3 | +#ifndef `TEST' |
| 4 | + #message Use -D TEST=XXX |
| 5 | + #terminate |
| 6 | +#else |
| 7 | + #include `NAME_' # `TEST' |
| 8 | +#endif |
| 9 | +.end |
| 10 | + |
| 11 | +*--#[ series : |
| 12 | +#- |
| 13 | +#define CUT "5" |
| 14 | +#define TESTS "15" |
| 15 | +#define FAIL "0" |
| 16 | + |
| 17 | +off stats; |
| 18 | +off warnings; |
| 19 | +#include- series.h |
| 20 | +S ep,c,d0,...,d`CUT'; |
| 21 | +CF pow; |
| 22 | +L foo=c*ep^-2+<d0*ep^0>+...+<d`CUT'*ep^`CUT'>; |
| 23 | +
|
| 24 | +#message Test1: Inversion |
| 25 | +#call series(ep,{`CUT'+2}) |
| 26 | +#call invert(foo,bar) |
| 27 | +L [0]=foo*bar-1; |
| 28 | +if(count(ep,1)>`CUT')discard; |
| 29 | +.sort |
| 30 | +drop [0]; |
| 31 | +#if termsin([0])>0 |
| 32 | + #message FAILED |
| 33 | + #redefine FAIL "{`FAIL'+1}" |
| 34 | + #else |
| 35 | + #message passed |
| 36 | +#endif |
| 37 | +
|
| 38 | +#message Test2: Exponentiation & Logarithm |
| 39 | +#call series(ep,`CUT') |
| 40 | +#call exp(foo,bar) |
| 41 | +#call log(bar,bar) |
| 42 | +L [0]=bar-foo |
| 43 | +; |
| 44 | +id 1/exp(c?)=exp(-c); |
| 45 | +repeat id exp(d0?)*exp(d1?)=exp(d0+d1); |
| 46 | +id exp(0)=1; |
| 47 | +id log(exp(c?))=c; |
| 48 | +.sort |
| 49 | +drop [0]; |
| 50 | +#if termsin([0])>0 |
| 51 | + #message FAILED |
| 52 | + #redefine FAIL "{`FAIL'+1}" |
| 53 | + #else |
| 54 | + #message passed |
| 55 | +#endif |
| 56 | +
|
| 57 | +#message Test3: Power |
| 58 | +L [-2]=-2; |
| 59 | +L [-1/2]=-1/2; |
| 60 | +#call series(ep,{`CUT'+2}) |
| 61 | +#call power(foo,[-2],bar) |
| 62 | +#call power(bar,[-1/2],bar2) |
| 63 | +drop bar; |
| 64 | +skip; |
| 65 | +nskip bar2; |
| 66 | +id 1/exp(c?)=exp(-c); |
| 67 | +repeat id exp(d0?)*exp(d1?)=exp(d0+d1); |
| 68 | +id exp(0)=1; |
| 69 | +argument exp; |
| 70 | + id log(exp(c?))=c; |
| 71 | +endargument; |
| 72 | +id exp(log(c?))=c; |
| 73 | +if(count(ep,1)>`CUT')discard; |
| 74 | +.sort |
| 75 | +drop bar2,[-2],[-1/2]; |
| 76 | +L [0]=foo-bar2; |
| 77 | +.sort |
| 78 | +#if termsin([0])>0 |
| 79 | + #message FAILED |
| 80 | + #redefine FAIL "{`FAIL'+1}" |
| 81 | + #else |
| 82 | + #message passed |
| 83 | +#endif |
| 84 | +
|
| 85 | +#call init({2*{`CUT'+2}}) |
| 86 | +
|
| 87 | +#message Test4: inverse function |
| 88 | +.sort |
| 89 | +cf den; |
| 90 | +skip foo; |
| 91 | +L [0]=foo*den(foo)-1; |
| 92 | +#call expand(den) |
| 93 | +.sort |
| 94 | +drop [0]; |
| 95 | +#if termsin([0])>0 |
| 96 | + #message FAILED |
| 97 | + #redefine FAIL "{`FAIL'+1}" |
| 98 | + #else |
| 99 | + #message passed |
| 100 | +#endif |
| 101 | +
|
| 102 | +#message Test5: exponential & logarithm function |
| 103 | +.sort |
| 104 | +cf exp,log; |
| 105 | +skip foo; |
| 106 | +L [0]=exp(log(foo))-foo; |
| 107 | +argument exp; |
| 108 | + #call expand(log) |
| 109 | +endargument; |
| 110 | +#call expand(exp) |
| 111 | +id exp(log(c?))=c; |
| 112 | +.sort |
| 113 | +drop [0]; |
| 114 | +#if termsin([0])>0 |
| 115 | + #message FAILED |
| 116 | + #redefine FAIL "{`FAIL'+1}" |
| 117 | + #else |
| 118 | + #message passed |
| 119 | +#endif |
| 120 | +
|
| 121 | +#message Test6: power function |
| 122 | +.sort |
| 123 | +cf power; |
| 124 | +skip foo; |
| 125 | +L [0]=power(power(foo,-2),-1/2)-foo; |
| 126 | +argument power; |
| 127 | + #call expand(power) |
| 128 | +endargument; |
| 129 | +argument power; |
| 130 | + id exp( - 2*log(ep^-2*c))=(ep^-2*c)^-2; |
| 131 | +endargument; |
| 132 | +#call expand(power) |
| 133 | +id exp( - 1/2*log(ep^4*c^-2))=ep^-2*c; |
| 134 | +.sort |
| 135 | +drop [0]; |
| 136 | +#if termsin([0])>0 |
| 137 | + #message FAILED |
| 138 | + #redefine FAIL "{`FAIL'+1}" |
| 139 | + #else |
| 140 | + #message passed |
| 141 | +#endif |
| 142 | +
|
| 143 | +#message Test7: local expansion variable |
| 144 | +.sort |
| 145 | +s x; |
| 146 | +cf den; |
| 147 | +skip foo; |
| 148 | +l [0x] = 1-(1-x)*den(1-x); |
| 149 | +l [0ep] = 1-(1-ep)*den(1-ep); |
| 150 | +#call expand(den,x,{`CUT'-1}) |
| 151 | +#call expand(den) |
| 152 | +.sort |
| 153 | +drop [0x],[0ep]; |
| 154 | +#if (termsin([0x])>0) || (termsin([0ep])>0) |
| 155 | + #message FAILED |
| 156 | + #redefine FAIL "{`FAIL'+1}" |
| 157 | + #else |
| 158 | + #message passed |
| 159 | +#endif |
| 160 | + |
| 161 | +#message Test8: products of denominators |
| 162 | +.sort |
| 163 | +cf den; |
| 164 | +skip foo; |
| 165 | +L [0]=den(foo)*den(foo)-den(foo*foo); |
| 166 | +#call expand(den) |
| 167 | +.sort |
| 168 | +drop [0]; |
| 169 | +#if termsin([0])>0 |
| 170 | + #message FAILED |
| 171 | + #redefine FAIL "{`FAIL'+1}" |
| 172 | + #else |
| 173 | + #message passed |
| 174 | +#endif |
| 175 | + |
| 176 | +#message Test9: products of exponentials |
| 177 | +.sort |
| 178 | +cf exp; |
| 179 | +skip foo; |
| 180 | +L [0]= exp(foo)*exp(-foo) - 1; |
| 181 | +#call expand(exp) |
| 182 | +.sort |
| 183 | +drop [0]; |
| 184 | +#if termsin([0])>0 |
| 185 | + #message FAILED |
| 186 | + #redefine FAIL "{`FAIL'+1}" |
| 187 | + #else |
| 188 | + #message passed |
| 189 | +#endif |
| 190 | + |
| 191 | +#message Test10: products of logarithms |
| 192 | +.sort |
| 193 | +cf log; |
| 194 | +skip foo; |
| 195 | +L [0]= log(1+c*x)*log(1+d0*x) - c*d0*x^2; |
| 196 | +#call expand(log,x,2) |
| 197 | +#call expand(log,x,2) |
| 198 | +id log(1) = 0; |
| 199 | +.sort |
| 200 | +drop [0]; |
| 201 | +#if termsin([0])>0 |
| 202 | + #message FAILED |
| 203 | + #redefine FAIL "{`FAIL'+1}" |
| 204 | + #else |
| 205 | + #message passed |
| 206 | +#endif |
| 207 | + |
| 208 | +#message Test11: products of powers |
| 209 | +.sort |
| 210 | +cf pow; |
| 211 | +skip foo; |
| 212 | +L [0]= 1 - pow(foo,foo)*pow(foo,-foo); |
| 213 | +#call expand(pow) |
| 214 | +.sort |
| 215 | +drop [0]; |
| 216 | +#if termsin([0])>0 |
| 217 | + #message FAILED |
| 218 | + #redefine FAIL "{`FAIL'+1}" |
| 219 | + #else |
| 220 | + #message passed |
| 221 | +#endif |
| 222 | + |
| 223 | +#message Test12: products of Gamma functions |
| 224 | +.sort |
| 225 | +cf Gamma; |
| 226 | +skip foo; |
| 227 | +L [0]= 1 - Gamma(1+c*x)*Gamma(1-c*x); |
| 228 | +#call expand(Gamma,x,1) |
| 229 | +#call expand(Gamma,x,1) |
| 230 | +id Gamma(1) = 1; |
| 231 | +.sort |
| 232 | +drop [0]; |
| 233 | +#if termsin([0])>0 |
| 234 | + #message FAILED |
| 235 | + #redefine FAIL "{`FAIL'+1}" |
| 236 | + #else |
| 237 | + #message passed |
| 238 | +#endif |
| 239 | + |
| 240 | +#message Test13: multiple denominators with poles |
| 241 | +.sort |
| 242 | +skip foo; |
| 243 | +L [0]= x*den(x)^2 - 1/x; |
| 244 | +#call expand(den,x,-1) |
| 245 | +.sort |
| 246 | +drop [0]; |
| 247 | +#if termsin([0])>0 |
| 248 | + #message FAILED |
| 249 | + #redefine FAIL "{`FAIL'+1}" |
| 250 | + #else |
| 251 | + #message passed |
| 252 | +#endif |
| 253 | + |
| 254 | +#message Test14: nontrivial normalisation |
| 255 | +.sort |
| 256 | +s A,a,c; |
| 257 | +skip foo; |
| 258 | +L [0] = ( |
| 259 | + + den(A - a + c*x^2)* den(A + a + c*x^2) |
| 260 | + + den( - a + A)^2*den(a + A)*c*x^2 |
| 261 | + - den( - a + A)*den(a + A) |
| 262 | + + den( - a + A)*den(a + A)^2*c*x^2 |
| 263 | +); |
| 264 | +#call expand(den,x,2) |
| 265 | +.sort |
| 266 | +drop [0]; |
| 267 | +#if termsin([0])>0 |
| 268 | + #message FAILED |
| 269 | + #redefine FAIL "{`FAIL'+1}" |
| 270 | + #else |
| 271 | + #message passed |
| 272 | +#endif |
| 273 | + |
| 274 | +#message Test15: nontrivial normalisation |
| 275 | +.sort |
| 276 | +skip foo; |
| 277 | +L [0] = ( |
| 278 | + + den(1 + c*x^2*den(A - a))* den(1 + c*x^2*den(A + a)) |
| 279 | + - 1 + c*x^2*(den(A - a) + den(A + a)) |
| 280 | +); |
| 281 | +#call expand(den,x,2) |
| 282 | +print+s; |
| 283 | +.sort |
| 284 | +drop [0]; |
| 285 | +#if termsin([0])>0 |
| 286 | + #message FAILED |
| 287 | + #redefine FAIL "{`FAIL'+1}" |
| 288 | + #else |
| 289 | + #message passed |
| 290 | +#endif |
| 291 | + |
| 292 | + |
| 293 | +#if `FAIL'==0 |
| 294 | + #message All tests passed |
| 295 | + #else |
| 296 | + #message Failed `FAIL'/`TESTS' tests |
| 297 | + #terminate 1 |
| 298 | +#endif |
| 299 | +.end |
| 300 | +assert succeeded? |
| 301 | +*--#] series : |
0 commit comments