Expose numeric trend segment formulas from native reconstruction models
This commit is contained in:
32
python/tests/test_plot_formula.py
Normal file
32
python/tests/test_plot_formula.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""Formula coefficients must reproduce the native reconstruction, not a refit."""
|
||||
import unittest
|
||||
from set_devices.signal_reconstruction import reconstruct
|
||||
from set_devices.plot_formula import linear_piece
|
||||
|
||||
|
||||
class PlotFormulaTests(unittest.TestCase):
|
||||
def test_all_methods_match_native_values_on_irregular_and_duplicate_knots(self):
|
||||
points = [(0, 2), (.3, 8), (.3, 4), (1.1, -3), (2, 7), (4, 1), (5, 2)]
|
||||
for method in ('linear', 'pchip', 'spline', 'polynomial'):
|
||||
result = reconstruct(points, method, 101, 3, with_model=True)
|
||||
for x, y in result.points:
|
||||
piece = next(piece for piece in result.pieces if piece.left <= x <= piece.right)
|
||||
self.assertAlmostEqual(y, piece.value(x), places=9)
|
||||
|
||||
def test_polynomial_model_with_fewer_output_samples_than_coefficients(self):
|
||||
points = [(i, 1 + i * .2 - i ** 2 * .03 + i ** 5 * .0001) for i in range(9)]
|
||||
result = reconstruct(points, 'polynomial', 2, 5, with_model=True)
|
||||
for x, y in points:
|
||||
self.assertAlmostEqual(y, result.pieces[0].value(x), places=9)
|
||||
|
||||
def test_source_line_and_formula_use_displayed_origin(self):
|
||||
piece = linear_piece([1000, 1100, 1200], [1, 3, 0], 1050)
|
||||
self.assertAlmostEqual(2, piece.value(1050))
|
||||
text = piece.text(1000, 'мс')
|
||||
self.assertIn('y = 1 +2·u', text)
|
||||
self.assertIn('0 ≤ x ≤ 100 мс', text)
|
||||
self.assertIsNone(linear_piece([0, 1, 2], [1, float('nan'), 3], .5))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user