Unittests zu allen Elementen erstellt
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Unit-Tests für Kreisel (Refactored)
|
||||
"""
|
||||
import unittest
|
||||
import math
|
||||
|
||||
from .Kreisel import Kreisel, RADIUS, PIN_OFFSET, PIN_OFFSETS
|
||||
|
||||
|
||||
class TestKreiselModell(unittest.TestCase):
|
||||
"""Tests für das Kreisel Pydantic-Modell."""
|
||||
|
||||
def test_from_merkmale(self):
|
||||
merkmale = {
|
||||
"Höhe in m": "2,5", # Komma-Format
|
||||
"Abstand (Kreiselachse A - Kreiselachse) in Meter": "15",
|
||||
"Drehung": "90",
|
||||
"Drehrichtung": "UZS",
|
||||
"Kreiselart": "Pin",
|
||||
"Anzahl der Scanner": "1",
|
||||
"Anzahl der Separatoren": "0",
|
||||
}
|
||||
obj = Kreisel.from_merkmale("K-001", 1000.0, 2000.0, merkmale)
|
||||
self.assertEqual(obj.teileid, "K-001")
|
||||
self.assertEqual(obj.hoehe, 2500.0) # 2.5 * 1000
|
||||
self.assertEqual(obj.abstand, 15000.0) # 15 * 1000
|
||||
self.assertEqual(obj.drehung, 90.0)
|
||||
self.assertEqual(obj.drehrichtung, "UZS")
|
||||
self.assertEqual(obj.kreiselart, "Pin")
|
||||
|
||||
def test_halbabstand(self):
|
||||
obj = Kreisel(teileid="K", x=0, y=0, hoehe=0, abstand=10000)
|
||||
self.assertEqual(obj.halbabstand, 5000.0)
|
||||
|
||||
def test_pos1_pos2_bei_90_grad(self):
|
||||
obj = Kreisel(teileid="K", x=1000, y=1000, hoehe=500, abstand=2000, drehung=90)
|
||||
# Bei 90° → winkel_rad = radians(90) → cos=0, sin=1
|
||||
# pos1 = (x - halbabstand*cos, y - halbabstand*sin, z) = (1000-0, 1000-1000, 500)
|
||||
self.assertAlmostEqual(obj.pos1[0], 1000.0, places=3)
|
||||
self.assertAlmostEqual(obj.pos1[1], 0.0, places=3)
|
||||
# pos2 = (x + halbabstand*cos, y + halbabstand*sin, z) = (1000+0, 1000+1000, 500)
|
||||
self.assertAlmostEqual(obj.pos2[0], 1000.0, places=3)
|
||||
self.assertAlmostEqual(obj.pos2[1], 2000.0, places=3)
|
||||
|
||||
|
||||
class TestPinOffsets(unittest.TestCase):
|
||||
"""Tests für die PIN_OFFSETS Lookup-Tabelle."""
|
||||
|
||||
def test_alle_rotationen_vorhanden(self):
|
||||
for rotation in (0.0, 90.0, 180.0, 270.0):
|
||||
self.assertIn(rotation, PIN_OFFSETS)
|
||||
|
||||
def test_offset_laenge(self):
|
||||
# Jeder Eintrag muss 8 Werte haben (4 Punkte × 2 Koordinaten)
|
||||
for rotation, offsets in PIN_OFFSETS.items():
|
||||
self.assertEqual(len(offsets), 8, f"Rotation {rotation}: erwartet 8 Offsets")
|
||||
|
||||
def test_rotation_0_p1a_offset(self):
|
||||
# p1a bei 0°: (-(RADIUS+PIN_OFFSET), +PIN_OFFSET)
|
||||
offsets = PIN_OFFSETS[0.0]
|
||||
self.assertEqual(offsets[0], -(RADIUS + PIN_OFFSET))
|
||||
self.assertEqual(offsets[1], +PIN_OFFSET)
|
||||
|
||||
def test_rotation_90_p2b_offset(self):
|
||||
# p2b bei 90°: (-PIN_OFFSET, -(RADIUS-PIN_OFFSET))
|
||||
offsets = PIN_OFFSETS[90.0]
|
||||
self.assertEqual(offsets[6], -PIN_OFFSET)
|
||||
self.assertEqual(offsets[7], -(RADIUS - PIN_OFFSET))
|
||||
|
||||
def test_rotation_180_symmetrie_zu_0(self):
|
||||
# 180° ist X-Spiegelung von 0° mit Y-Inversion
|
||||
off_0 = PIN_OFFSETS[0.0]
|
||||
off_180 = PIN_OFFSETS[180.0]
|
||||
# p1a bei 0°: (-(R+O), +O) → p1a bei 180°: (+(R+O), -O)
|
||||
self.assertEqual(off_180[0], -off_0[0])
|
||||
self.assertEqual(off_180[1], -off_0[1])
|
||||
|
||||
|
||||
class TestKreiselKonstanten(unittest.TestCase):
|
||||
"""Tests für Kreisel-Konstanten."""
|
||||
|
||||
def test_radius_wert(self):
|
||||
self.assertEqual(RADIUS, 400)
|
||||
|
||||
def test_pin_offset_wert(self):
|
||||
self.assertEqual(PIN_OFFSET, 50)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user