test_gen.py
1.7 kB · python · 59 lines
1import hashlib2import json34from mrlypy import gen5from mrlypy.core import Rng6from mrlypy.gen import build, name, variation7from mrlypy.math import two89DEFAULT_TILE = {10 "groups": ["General", "Fractal", "Magic", "Special", "Mosaic"],11 "catalog": "Classics",12 "min_size": 3,13 "max_size": 9,14 "parity": "Odds",15 "invert": None,16}1718DEFAULT_VARIATION = {19 "tile": DEFAULT_TILE,20 "paint": {"editions": None, "primaries": None, "target": None},21 "files": [(1, 1), (3, 3), (5, 5)],22}232425def test_name_recipe(row):26 r = row("gen::name::Tile::recipe")27 recipe = name.Tile.from_json(r["in"]["name"]).recipe()28 assert recipe.to_dict() == r["out"]["recipe"]29 folded = name.Tile.of(recipe)30 assert folded.to_json() == r["out"]["json"]31 assert folded.to_id() == r["out"]["id"]323334def test_draw_create(row):35 r = row("gen::draw::create")36 tile = build.create_2d(DEFAULT_TILE, Rng(r["in"]["seed"]))37 assert name.Tile.of(tile).to_json() == r["out"]383940def test_build_2d(row):41 r = row("gen::build::build_2d")42 recipe = name.Tile.from_json(r["in"]["tile"]["in"]["name"]).recipe()43 assert json.loads(two.to_json(build.build_2d(recipe))) == r["out"]444546def test_variation_create(row):47 r = row("gen::variation::create")48 made = variation.create(DEFAULT_VARIATION, Rng(r["in"]["seed"]))49 assert made.key == r["out"]["key"]50 assert str(made.seed) == r["out"]["seed"]51 assert made.edition == r["out"]["edition"]52 assert name.Tile.of(made.tile).to_json() == r["out"]["tile"]535455def test_background(row):56 r = row("gen::background")57 i = r["in"]58 png = gen.background(i["seed"], i["width"], i["height"])59 assert hashlib.sha256(png).hexdigest() == r["out"]