Files
pokerfreak/tests/flopmenue_pool_spec.py
T

52 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Spec of messung/motor/temperatur/flopmenue_pool.py: the fold-curve fit and the GG control (pool := GG reproduces the image header).
python3 tests/flopmenue_pool_spec.py -v
The control needs one image under the flopmenue data folder and is skipped if none is there yet."""
import glob
import gzip
import math
import os
import sys
import unittest
_w = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(os.path.dirname(_w), "messung", "motor", "temperatur"))
import flopmenue_pool as F
KONTROLLE_TOL_BB = 2e-3 # f16 noise of the stored values
class Fit(unittest.TestCase):
def test_logistik_fit_findet_bekannte_kurve(self):
a, b = -0.3, 1.1
n = 1_000_000
punkte = [(s, round(n / (1 + math.exp(-(a + b * math.log(s))))), n) for s in (0.33, 0.55, 1.0, 1.6, 2.6, 4.5, 11.0)]
fa, fb = F.logistik_fit(punkte)
self.assertAlmostEqual(fa, a, places=3)
self.assertAlmostEqual(fb, b, places=3)
def test_pool_steigt_mit_der_groesse_und_allin_nimmt_die_allin_zeile(self):
ohne = {0.45: [33, 100], 0.85: [47, 100], 1.3: [60, 100]}
mit = {0.45: [1, 10], 99.0: [8, 10]}
p = F.Pool(ohne, mit, {0.45: 0.333, 0.85: 0.545, 1.3: 1.0})
self.assertLess(p.fold(0.33), p.fold(0.75))
self.assertLess(p.fold(0.75), p.fold(1.25))
self.assertEqual(p.fold(12.0, allin=True), 0.8)
class Kontrolle(unittest.TestCase):
def test_pool_gleich_gg_ergibt_den_wurzelwert_des_kopfes(self):
dateien = sorted(glob.glob(F.DATEN + "/bilder/BTN-BB/*/*.bin.gz"))[:6]
if not dateien:
self.skipTest("no images yet")
ranges = F.lagen_ranges()
for d in dateien:
bild = F.Bild(gzip.open(d).read(), ranges)
for u in (0, 1):
self.assertAlmostEqual(F.bewerte(bild, u, None), bild.kopf["werte_wurzel"][u], delta=KONTROLLE_TOL_BB, msg=d)
if __name__ == "__main__":
unittest.main()