|
10 | 10 |
|
11 | 11 | REPORT_STEP_SECONDS = 3600 # Example1 |
12 | 12 |
|
| 13 | + |
| 14 | +def cdd(t, r): |
| 15 | + import math |
| 16 | + |
| 17 | + if t == r: |
| 18 | + return 10.0 |
| 19 | + |
| 20 | + tmp = abs(t - r) |
| 21 | + if tmp < 1.0e-7: |
| 22 | + tmp = 1.0e-7 |
| 23 | + elif tmp > 2.0: |
| 24 | + tmp = 1.0 |
| 25 | + |
| 26 | + tmp = -math.log10(tmp) |
| 27 | + if tmp < 0.0: |
| 28 | + tmp = 0.0 |
| 29 | + |
| 30 | + return tmp |
| 31 | + |
| 32 | +def check_cdd_float(test: list[float], ref: list[float], cdd_tol: int) -> bool: |
| 33 | + """ |
| 34 | + Checks minimum correct decimal digits between two float sequences. Fails if lengths differ. |
| 35 | + """ |
| 36 | + import math |
| 37 | + |
| 38 | + if len(test) != len(ref): |
| 39 | + return False |
| 40 | + |
| 41 | + min_cdd = 10.0 |
| 42 | + |
| 43 | + for t, r in zip(test, ref): |
| 44 | + tmp = cdd(t, r) |
| 45 | + |
| 46 | + if tmp < min_cdd: |
| 47 | + min_cdd = tmp |
| 48 | + |
| 49 | + return math.floor(min_cdd) >= cdd_tol |
| 50 | + |
| 51 | + |
13 | 52 | def _curr_dt(): |
14 | 53 | y, m, d, hh, mm, ss = solver.simulation_get_current_datetime() |
15 | 54 | return datetime(y, m, d, hh, mm, ss) |
@@ -81,16 +120,15 @@ def test_compare_aligned_series(): |
81 | 120 | ) |
82 | 121 |
|
83 | 122 | # values should match within tolerance |
84 | | - import numpy as np |
85 | | - |
86 | | - solver_vals = np.array([v for _, v in s]) |
87 | | - output_vals = np.array([v for _, v in o]) |
| 123 | + solver_vals = [v for _, v in s] |
| 124 | + output_vals = [v for _, v in o] |
88 | 125 |
|
89 | | - assert np.allclose(solver_vals, output_vals, rtol=1e-6, atol=1e-9), ( |
| 126 | + assert check_cdd_float(solver_vals, output_vals, 1), ( |
90 | 127 | "Solver and output values differ. " |
91 | 128 | "See zipped output for details:\n" + |
92 | 129 | "\n".join( |
93 | | - f"{t1.strftime('%Y-%m-%d %H:%M:%S')} | {v1:.6f} || {t2.strftime('%Y-%m-%d %H:%M:%S')} | {v2:.6f} | diff={v1-v2:.2e}" |
| 130 | + f"{t1.strftime('%Y-%m-%d %H:%M:%S')} | {v1:.6f} || {t2.strftime('%Y-%m-%d %H:%M:%S')} | {v2:.6f} | cdd={cdd(v1, v2):.2f}" |
94 | 131 | for (t1, v1), (t2, v2) in list(zip(s, o))[:10] |
95 | 132 | ) |
96 | 133 | ) |
| 134 | + |
0 commit comments