40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Der Chaos-Plan (mock/chaos.py) ist aus dem Startwert wiederholbar und deckt jede Störung ab.
|
|
|
|
python3 tests/chaos_plan_spec.py -v
|
|
"""
|
|
import os
|
|
import sys
|
|
import unittest
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "mock"))
|
|
|
|
import chaos
|
|
|
|
|
|
class Plan(unittest.TestCase):
|
|
def test_gleicher_startwert_gleicher_plan(self):
|
|
self.assertEqual(chaos.plan("chaos-1", 240), chaos.plan("chaos-1", 240))
|
|
|
|
def test_anderer_startwert_anderer_plan(self):
|
|
self.assertNotEqual(chaos.plan("chaos-1", 240), chaos.plan("chaos-2", 240))
|
|
|
|
def test_jede_art_kommt_vor_auch_bei_kurzer_dauer(self):
|
|
for startwert in ("a", "b", "c"):
|
|
for dauer in (30, 240):
|
|
self.assertEqual({s.art for s in chaos.plan(startwert, dauer)}, set(chaos.ARTEN))
|
|
|
|
def test_abstaende_und_anlauf(self):
|
|
p = chaos.plan("chaos-1", 600)
|
|
self.assertGreaterEqual(p[0].t, chaos.ANLAUF_S)
|
|
abstaende = [b.t - a.t for a, b in zip(p, p[1:])]
|
|
self.assertTrue(all(chaos.ABSTAND_S[0] - 0.1 <= x <= chaos.ABSTAND_S[1] + 0.1 for x in abstaende), abstaende)
|
|
|
|
def test_lange_dauer_fuellt_mit_weiteren_stoerungen(self):
|
|
self.assertGreater(len(chaos.plan("chaos-1", 600)), len(chaos.ARTEN))
|
|
self.assertLessEqual(chaos.plan("chaos-1", 600)[-1].t, 600 + chaos.ABSTAND_S[1])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|