MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / test

Function test

code/mathematics/tridiagonal.test.cpp:2–33  ·  view source on GitHub ↗

Field testing: Timus 1047 */

Source from the content-addressed store, hash-verified

1/* Field testing: Timus 1047 */
2void test() {
3 long double eps = 1e-5;
4 rep(it,0,5000) {
5 int n = rng() % min(it+1, 4999) + 1;
6 vector<long double> cX(n);
7 rep(i,0,n) {
8 A[i] = randdouble(-1000, 1000);
9 B[i] = randdouble(-1000, 1000);
10 C[i] = randdouble(-1000, 1000);
11 cX[i] = randdouble(-1000, 1000);
12 A[i] = round(A[i]*10000)/10000;
13 B[i] = round(B[i]*10000)/10000;
14 C[i] = round(C[i]*10000)/10000;
15 cX[i] = round(cX[i]*10000)/10000;
16 }
17 A[0] = 0.0;
18 C[n-1] = 0.0;
19 if (n == 1) {
20 D[0] = B[0] * cX[0];
21 } else {
22 D[0] = B[0] * cX[0] + C[0] * cX[1];
23 D[n-1] = A[n-1] * cX[n-2] + B[n-1] * cX[n-1];
24 rep(i,1,n-1) {
25 D[i] = A[i] * cX[i-1] + B[i] * cX[i] + C[i] * cX[i+1];
26 }
27 }
28 solve(n);
29 rep(i,0,n) {
30 assert_true(abs(X[i] - cX[i]) < eps);
31 }
32 }
33}
34// vim: cc=60 ts=2 sts=2 sw=2:

Callers

nothing calls this directly

Calls 3

randdoubleFunction · 0.85
solveFunction · 0.85
assert_trueFunction · 0.85

Tested by

no test coverage detected