;; ============================================================ ;; test_foerderer.lsp - Automatischer Integrationstest fuer VarioFoerderer ;; ;; Liest Testfaelle aus tests/testdata/foerderer_tests.json. ;; Speichert: ;; - tests/output/foerderer_results.json (Ergebnisse) ;; ;; Voraussetzungen: ;; - SSG_LIB geladen (VarioFoerderer.lsp, ssg_core.lsp) ;; - Umgebungsvariable DXFMAKRO gesetzt ;; ;; Aufruf in BricsCAD: ;; (load (strcat (getenv "DXFMAKRO") "/tests/test_foerderer.lsp")) ;; TEST_FOERDERER ;; ============================================================ ;; --- Ergebnis eines Testfalls als JSON-String erzeugen --- (defun foerderer:test-result-json (test-id richtung deltaL deltaH status winkel L_GF L_VF / json) (setq json (strcat " {\n" " \"test_id\": \"" test-id "\",\n" " \"richtung\": \"" richtung "\",\n" " \"deltaL\": " (rtos deltaL 2 0) ",\n" " \"deltaH\": " (rtos deltaH 2 0) ",\n" " \"status\": \"" status "\"")) (if winkel (setq json (strcat json ",\n" " \"winkel\": " (itoa winkel) ",\n" " \"L_GF\": " (rtos L_GF 2 1) ",\n" " \"L_VF\": " (rtos L_VF 2 1))) ) (setq json (strcat json "\n }")) json ) ;; --- JSON-Export der Foerderer-Testergebnisse --- (defun foerderer:export-results (tests-out-dir / out-json f first) (if (null *foerderer-test-results*) (princ "\n Keine Foerderer-Ergebnisse vorhanden.") (progn (vl-mkdir tests-out-dir) (setq out-json (strcat tests-out-dir "/foerderer_results.json")) (setq f (open out-json "w")) (if f (progn (write-line "[" f) (setq first T) (foreach r *foerderer-test-results* (if (not first) (write-line "," f)) (write-line r f) (setq first nil) ) (write-line "]" f) (close f) (princ (strcat "\n Ergebnisse: " out-json)) ) (princ (strcat "\n FEHLER: Kann " out-json " nicht schreiben!")) ) ) ) ) ;; --- Einen VF-Testblock bauen und lastEnt hinter dessen SEQEND schieben --- (defun foerderer:baue-block (startpunkt vf-nummer hoehe-von hoehe-bis deltaH deltaL richtung best-winkel L_GF1 L_GF2 L_VF lastEnt / sub-ent) (variofoerderer-einfuegen deltaL deltaH richtung best-winkel L_GF1 L_GF2 L_VF startpunkt "links" 0.0) (vf-block-erstellen "standard" "links" vf-nummer 0 hoehe-von hoehe-bis deltaH deltaL L_VF L_GF1 L_GF2 richtung best-winkel startpunkt lastEnt 0.0) ;; lastEnt hinter den SEQEND des VF-Blocks schieben. ;; Ohne diesen Schritt wuerde entnext vom INSERT-Entity ;; in die ATTRIB-Kette des gerade erstellten VF-Blocks ;; springen und diese beim naechsten _.-BLOCK-Aufruf ;; in den neuen Block verschieben (Datenverlust). (setq lastEnt (entlast)) (setq sub-ent (entnext lastEnt)) (while (and sub-ent (not (equal (cdr (assoc 0 (entget sub-ent))) "SEQEND"))) (setq lastEnt sub-ent) (setq sub-ent (entnext lastEnt))) (if sub-ent (setq lastEnt sub-ent)) lastEnt ) ;; ============================================================ ;; C:TEST_FOERDERER - Hauptbefehl ;; ============================================================ (defun c:TEST_FOERDERER ( / json-datei testdaten cfg tests eintrag test-id richtung deltaL deltaH ergebnis best-winkel L_GF L_VF horizontal-info y-offset y-abstand idx blk-nummer anz-gebaut anz-nicht-gebaut results-list startpunkt hoehe-von hoehe-bis lastEnt sub-typ) ;; Bibliothek initialisieren (laedt Block-Library und extrahiert Masse) (if (not *lib-initialized*) (init-bibliothek) ) (ssg-start "TEST_FOERDERER" '(("OSMODE") ("CECOLOR") ("ATTREQ") ("ATTDIA"))) (setvar "OSMODE" 0) (setvar "ATTREQ" 0) (setvar "ATTDIA" 0) ;; Testdaten aus JSON laden (setq json-datei (strcat (getenv "DXFMAKRO") "\\tests\\testdata\\foerderer_tests.json")) (setq testdaten (ssg-load-json json-datei)) (if (null testdaten) (progn (alert (strcat "Testdaten nicht gefunden:\n" json-datei)) (ssg-end) (exit) ) ) ;; Konfiguration aus erstem Eintrag (ohne test_id) (setq cfg (car testdaten)) (setq y-abstand (ssg-val cfg "y_abstand")) (if (or (null y-abstand) (= y-abstand 0)) (setq y-abstand 800)) ;; Nur Eintraege mit test_id sind Testfaelle (setq tests (vl-remove-if-not '(lambda (e) (ssg-val e "test_id")) testdaten)) (setq y-offset 0) (setq idx 0) (setq blk-nummer 0) (setq results-list '()) (setq anz-gebaut 0) (setq anz-nicht-gebaut 0) (princ "\n") (princ "\n================================================================") (princ "\n TEST_FOERDERER - Variofoerderer Integrationstest") (princ "\n================================================================") (princ (strcat "\n Testdaten: " json-datei)) (princ (strcat "\n Testfaelle: " (itoa (length tests)))) (princ (strcat "\n Y-Abstand: " (rtos y-abstand 2 0) " mm")) (princ "\n================================================================") ;; ========================================================== ;; Alle Testfaelle aus JSON ausfuehren ;; ========================================================== (foreach eintrag tests (setq test-id (ssg-val eintrag "test_id")) (setq richtung (ssg-val eintrag "richtung")) (setq deltaL (float (ssg-val eintrag "deltaL"))) (setq deltaH (float (ssg-val eintrag "deltaH"))) (setq idx (1+ idx)) ;; Geometrisch unmoeglich: Ab mit deltaH=0 (if (and (= richtung "Ab") (< deltaH 1)) (progn (setq anz-nicht-gebaut (1+ anz-nicht-gebaut)) (princ (strcat "\n " (itoa idx) ". " test-id " -> GEOMETRISCH_UNMOEGLICH")) (setq results-list (cons (foerderer:test-result-json test-id richtung deltaL deltaH "GEOMETRISCH_UNMOEGLICH" nil nil nil) results-list)) ) (progn (setq ergebnis (berechne-alle-winkel deltaL deltaH richtung nil)) (setq best-winkel (car ergebnis)) (setq L_GF (cadr ergebnis)) (setq L_VF (caddr ergebnis)) (if (and best-winkel L_GF L_VF (> L_GF 0) (> L_VF 0)) (progn (setq anz-gebaut (1+ anz-gebaut)) (princ (strcat "\n " (itoa idx) ". " test-id " -> GEBAUT " (itoa best-winkel) " Grad L_GF=" (rtos L_GF 2 1) " L_VF=" (rtos L_VF 2 1))) (setq startpunkt (list 0 y-offset 0)) (setq blk-nummer (1+ blk-nummer)) (setq hoehe-von 0) (setq hoehe-bis (if (= richtung "Auf") deltaH (- deltaH))) ;; Wie c:VarioFoerderer: Attribut-Entities/SEQEND des vorherigen ;; VF_N-Blocks ueberspringen, sonst rutschen sie in den naechsten ;; Block hinein (Blockerstellung faengt sonst am falschen Entity an). (setq lastEnt (vf-lastent-ohne-attribute)) (setq lastEnt (foerderer:baue-block startpunkt blk-nummer hoehe-von hoehe-bis deltaH deltaL richtung best-winkel (/ L_GF 2.0) (/ L_GF 2.0) L_VF lastEnt)) (setq results-list (cons (foerderer:test-result-json test-id richtung deltaL deltaH "GEBAUT" best-winkel L_GF L_VF) results-list)) ) (progn (setq anz-nicht-gebaut (1+ anz-nicht-gebaut)) (princ (strcat "\n " (itoa idx) ". " test-id " -> NICHT_GEBAUT")) (setq results-list (cons (foerderer:test-result-json test-id richtung deltaL deltaH "NICHT_GEBAUT" nil nil nil) results-list)) ) ) ;; Zusaetzlich: Horizontale Variofoerderer-Mittelsektion (0 Grad) ;; pruefen und als eigenen Testfall bauen, falls bei richtung="Ab" ;; geometrisch moeglich (analog Schritt 5b in c:VarioFoerderer). (if (= richtung "Ab") (progn (setq horizontal-info (berechne-horizontale-mitte deltaL deltaH "Ab")) (if (and horizontal-info (caddr horizontal-info)) (progn (setq anz-gebaut (1+ anz-gebaut)) (princ (strcat "\n " (itoa idx) ". " test-id " -> GEBAUT (Horizontale Variofoerderer 0" (chr 176) ") L_GF=" (rtos (car horizontal-info) 2 1) " L_VF=" (rtos (cadr horizontal-info) 2 1))) (setq y-offset (- y-offset y-abstand)) (setq startpunkt (list 0 y-offset 0)) (setq blk-nummer (1+ blk-nummer)) (setq hoehe-von 0) (setq hoehe-bis (- deltaH)) (setq lastEnt (vf-lastent-ohne-attribute)) (setq lastEnt (foerderer:baue-block startpunkt blk-nummer hoehe-von hoehe-bis deltaH deltaL "Ab" 0 (/ (car horizontal-info) 2.0) (/ (car horizontal-info) 2.0) (cadr horizontal-info) lastEnt)) (setq results-list (cons (foerderer:test-result-json (strcat test-id "_HORIZONTAL") richtung deltaL deltaH "GEBAUT" 0 (car horizontal-info) (cadr horizontal-info)) results-list)) ) ) ) ) ) ) (setq y-offset (- y-offset y-abstand)) ) ;; ========================================================== ;; Zusammenfassung ;; ========================================================== (princ "\n================================================================") (princ (strcat "\n Ergebnis: " (itoa anz-gebaut) " GEBAUT, " (itoa anz-nicht-gebaut) " NICHT_GEBAUT")) (princ "\n================================================================") ;; Ergebnisse in globaler Variable speichern (setq *foerderer-test-results* (reverse results-list)) (ssg-end) (princ "\n================================================================") (princ "\n TEST_FOERDERER abgeschlossen.") (princ "\n================================================================") (princ) )