Files
kabellaengen/lib/getpositions_test.py
T

108 lines
3.1 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Test für die check_rack_z_coordinates Funktion
"""
import sys
from pathlib import Path
# Füge lib zum Path hinzu
sys.path.insert(0, str(Path(__file__).parent))
from getpositions import check_rack_z_coordinates
from error_collector import ErrorCollector
def test_no_deviation():
"""Test mit Racks ohne starke Abweichung (< 2000mm)"""
print("Test 1: Keine starke Abweichung (< 2000mm)")
racks = {
'Rack_1': [[100.0, 200.0, 0.0], [150.0, 200.0, 0.0]],
'Rack_2': [[200.0, 300.0, 500.0], [250.0, 300.0, 500.0]],
'Rack_3': [[300.0, 400.0, 1000.0], [350.0, 400.0, 1000.0]]
}
error_collector = ErrorCollector()
check_rack_z_coordinates(racks, error_collector)
warnings = error_collector.warnings
if warnings:
print(f" FEHLER: Warnung wurde ausgegeben, obwohl keine erwartet: {warnings}")
else:
print(" OK: Keine Warnung (erwartet)")
print()
def test_with_deviation():
"""Test mit Racks mit starker Abweichung (> 2000mm)"""
print("Test 2: Starke Abweichung (> 2000mm)")
racks = {
'Rack_1': [[100.0, 200.0, 0.0], [150.0, 200.0, 0.0]],
'Rack_2': [[200.0, 300.0, 50000.0], [250.0, 300.0, 50000.0]], # 50m Höhe!
'Rack_3': [[300.0, 400.0, 100.0], [350.0, 400.0, 100.0]]
}
error_collector = ErrorCollector()
check_rack_z_coordinates(racks, error_collector)
warnings = error_collector.warnings
if warnings:
print(f" OK: Warnung wurde ausgegeben (erwartet): {warnings}")
else:
print(" FEHLER: Keine Warnung, aber eine war erwartet!")
print()
def test_exactly_2000mm():
"""Test mit genau 2000mm Abweichung (Grenzfall)"""
print("Test 3: Genau 2000mm Abweichung (Grenzfall)")
racks = {
'Rack_1': [[100.0, 200.0, 0.0], [150.0, 200.0, 0.0]],
'Rack_2': [[200.0, 300.0, 2000.0], [250.0, 300.0, 2000.0]],
}
error_collector = ErrorCollector()
check_rack_z_coordinates(racks, error_collector)
warnings = error_collector.warnings
if warnings:
print(f" Warnung wurde ausgegeben: {warnings}")
else:
print(" Keine Warnung (Grenzfall, hängt von > oder >= ab)")
print()
def test_dict_format():
"""Test mit Dictionary-Format für Koordinaten"""
print("Test 4: Dictionary-Format für Koordinaten")
racks = {
'Rack_1': [{'x': 100.0, 'y': 200.0, 'z': 0.0}, {'x': 150.0, 'y': 200.0, 'z': 0.0}],
'Rack_2': [{'x': 200.0, 'y': 300.0, 'z': 50000.0}, {'x': 250.0, 'y': 300.0, 'z': 50000.0}],
}
error_collector = ErrorCollector()
check_rack_z_coordinates(racks, error_collector)
warnings = error_collector.warnings
if warnings:
print(f" OK: Warnung wurde ausgegeben (erwartet): {warnings}")
else:
print(" FEHLER: Keine Warnung, aber eine war erwartet!")
print()
if __name__ == '__main__':
print("="*80)
print("Tests für check_rack_z_coordinates")
print("="*80)
print()
test_no_deviation()
test_with_deviation()
test_exactly_2000mm()
test_dict_format()
print("="*80)
print("Tests abgeschlossen")
print("="*80)