chadtmiller.com/fractal-garden
ASCII fractals rendered in CI: each preset is a view, every check draws them all
0
0
"""Each preset is well formed: the shape garden.py reads."""
import json
import pathlib
import sys
KINDS = {"mandelbrot", "julia"}
def problems(preset):
if preset.get("kind", "mandelbrot") not in KINDS:
yield f"kind is one of {sorted(KINDS)}"
center = preset.get("center")
if not (isinstance(center, list) and len(center) == 2):
yield "center is [x, y]"
if not (isinstance(preset.get("span"), (int, float)) and preset["span"] > 0):
yield "span is a number above 0"
if not (isinstance(preset.get("palette"), str) and len(preset["palette"]) >= 2):
yield "palette is at least two characters"
if preset.get("kind") == "julia" and not isinstance(preset.get("c"), list):
yield "a julia set names its c, as [re, im]"
bad = 0
for path in sorted(pathlib.Path("presets").glob("*.json")):
try:
found = list(problems(json.loads(path.read_text())))
except json.JSONDecodeError as e:
found = [f"not JSON: {e}"]
for p in found:
print(f"{path}: {p}")
bad += 1
if not found:
print(f"{path}: ok")
sys.exit(1 if bad else 0)