Files
coding-bench/tasks/D/d-11/check/check_task.py

143 lines
5.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Checkliste für d-11 (Sonnensystem). Alle Punkte stehen im Aufgabentext (prompt.md)."""
import sys
from webcheck import Checklist, Session, distance
PLANETS = ["merkur", "venus", "erde", "mars", "jupiter", "saturn", "uranus", "neptun"]
SEL = lambda p: f'[data-planet="{p}"]' # noqa: E731
cl = Checklist()
with Session() as s:
if not s.open():
cl.add("index.html vorhanden", False, "Datei /work/index.html fehlt", weight=2)
cl.finish()
sys.exit(0)
page = s.page
s.wait(1.0)
s.screenshot()
cl.add("lädt ohne JavaScript-Fehler", not s.errors, "; ".join(s.errors[:2]), weight=2)
def sun_ok():
b = page.locator("#sun").first.bounding_box()
return (b is not None and b["width"] > 10 and b["height"] > 10), "#sun fehlt oder zu klein"
cl.guard("Sonne (#sun) sichtbar", sun_ok)
def eight():
found = page.eval_on_selector_all("[data-planet]", "els => els.map(e => e.getAttribute('data-planet'))")
return sorted(set(found)) == sorted(PLANETS) and len(found) == 8, f"gefunden: {sorted(found)}"
cl.guard("acht Planeten mit data-planet", eight)
def positions():
return {p: s.center(SEL(p)) for p in PLANETS}
p0 = {}
sun0 = None
def visible():
global p0, sun0
p0 = positions()
sun0 = s.center("#sun")
vw, vh = s.size["width"], s.size["height"]
bad = [p for p, c in p0.items() if c is None or not (0 <= c[0] <= vw and 0 <= c[1] <= vh)]
return not bad and sun0 is not None, f"nicht im Bild: {bad}"
cl.guard("alle Planeten und die Sonne liegen im Bild", visible)
def apart():
pts = [c for c in p0.values() if c]
close = [(i, j) for i in range(len(pts)) for j in range(i + 1, len(pts)) if distance(pts[i], pts[j]) < 4]
return not close, "Planeten liegen übereinander"
cl.guard("Planeten liegen nicht übereinander", apart)
def order():
s.wait(0.7)
p1 = positions()
ds = []
for p in PLANETS:
a, b = p0.get(p), p1.get(p)
if not a or not b or not sun0:
return False, "Position fehlt"
ds.append((distance(a, sun0) + distance(b, sun0)) / 2)
ok = all(ds[i] + 1 < ds[i + 1] for i in range(len(ds) - 1))
return ok, "Abstände zur Sonne: " + ", ".join(str(round(d)) for d in ds)
cl.guard("Bahnen liegen von innen nach außen in Planeten-Reihenfolge", order)
def moving():
a = positions()
s.wait(1.5)
b = positions()
moved = [p for p in PLANETS if a[p] and b[p] and distance(a[p], b[p]) > 3]
return len(moved) >= 6, f"es bewegen sich nur {moved}"
cl.guard("Planeten bewegen sich von selbst (mindestens 6)", moving)
def circular():
d = []
for _ in range(4):
c, sc = s.center(SEL("erde")), s.center("#sun")
d.append(distance(c, sc))
s.wait(0.5)
return max(d) / max(min(d), 1) < 1.3, f"Abstand schwankt: {[round(x) for x in d]}"
cl.guard("Erde kreist in gleichmäßigem Abstand um die Sonne", circular)
def click_info(planet, word):
def run():
loc = page.locator(SEL(planet)).first
try:
loc.click(force=True, timeout=3000)
except Exception: # noqa: BLE001 - bewegtes Ziel: Klick-Ereignis direkt auslösen
loc.dispatch_event("click")
s.wait(0.2)
text = page.locator("#info").first.inner_text(timeout=2000)
if word not in text.lower():
loc.dispatch_event("click")
s.wait(0.2)
text = page.locator("#info").first.inner_text(timeout=2000)
return (word in text.lower() and len(text.strip()) >= len(word) + 8), f"#info: {text[:60]!r}"
return run
for planet, word in (("erde", "erde"), ("mars", "mars"), ("saturn", "saturn")):
cl.guard(f"Klick auf {planet} zeigt Name und mehr in #info", click_info(planet, word))
def pause():
page.locator("#pause").first.click(timeout=3000)
s.wait(0.3)
a = positions()
s.wait(1.0)
b = positions()
still = all(distance(a[p], b[p]) < 1.5 for p in PLANETS if a[p] and b[p])
return still, "Planeten bewegen sich trotz Pause"
cl.guard("Pause hält alle Planeten an", pause)
def resume():
page.locator("#pause").first.click(timeout=3000)
s.wait(0.3)
a = positions()
s.wait(1.5)
b = positions()
moved = [p for p in PLANETS if a[p] and b[p] and distance(a[p], b[p]) > 3]
return len(moved) >= 4, "Bewegung läuft nach dem zweiten Klick nicht weiter"
cl.guard("zweiter Klick setzt die Bewegung fort", resume)
cl.add("kein Zugriff aufs Netz", not s.blocked, f"versucht: {s.blocked[:2]}")
def fits():
w, h, iw, ih = page.evaluate(
"[document.documentElement.scrollWidth, document.documentElement.scrollHeight, innerWidth, innerHeight]"
)
return w <= iw + 1 and h <= ih + 1, f"Seite {w}x{h} in Fenster {iw}x{ih}"
cl.guard("passt in 1280×800 ohne Scrollen", fits)
cl.finish()