#! /usr/bin/python3 # Test program for module {move} # Last edited on 2021-05-31 14:20:45 by jstolfi import move_hp import move import move_example import move_parms import path import block import block_example import hacks import job_parms import rn import sys from math import sqrt, sin, cos, floor, ceil, inf, nan, pi parms = job_parms.slow() mp_fill = move_parms.make_for_fillings(parms) mp_cont = move_parms.make_for_contours(parms) mp_jump = move_parms.make_for_jumps(parms) wd_fill = move_parms.width(mp_fill) wd_cont = move_parms.width(mp_cont) def test_static(): sys.stderr.write("--- testing {process_input_data,input_paths,clear_input_data} ---\n") # Some blocks: BCS = block_example.misc_E(mp_fill, mp_jump) # Some moves that are not in the blocks: pa = (15,15) qa = (18,16) mva = move.make(pa, qa, mp_fill) pb = (15,15) qb = (18,16) mvb = move.make(pb, qb, mp_fill) # Preprocess the blocks: sys.stderr.write(" ... {move_hp.preprocess_input_data} ...\n") move_hp.preprocess_input_data(BCS) # Get all the moves of all blocks: sys.stderr.write(" ... collecting moves of blocks ...\n") MVS = [] for ibc in range(len(BCS)): bc = BCS[ibc] MVS += list(block.moves(bc)) MVS += [ mva, mvb, ] sys.stderr.write(" total %d moves\n" % len(MVS)) # Test the cached path occurrence data: sys.stderr.write(" ... checking {move_hp.input_paths} ...\n") for mv in MVS: for omv in mv, move.rev(mv): move.show(sys.stderr, omv, 0, 0) L = move_hp.input_paths(omv) nL = 0 if L == None else len(L) sys.stderr.write("(%d)\n" % nL) ibc_exp = block.find_block_with_move(BCS, omv) # Expected block index. if move.is_jump(mv) or mv == mva or mv == mvb: assert L == None else: assert ibc_exp != None assert type(L) is list or type(L) is tuple bc_exp = BCS[ibc_exp] # Get the first choice where {mv} occurs: ich_exp = block.find_choice_with_move(bc_exp, omv) assert ich_exp != None oph_exp = block.choice(bc_exp, ich_exp) imv_exp = path.find_move(oph_exp, omv) # Check the items of {L}: found_it = False # True if {ich_exp,imv_exp} appeared in {L}: for oph, imv in L: if oph == oph_exp and imv == imv_exp: found_it = True assert imv == path.find_move(oph, omv) # Clear the cached data: move_hp.clear_input_data(BCS) # Check that data is cleared: for mv in MVS: L = move_hp.input_paths(mv) assert L == None return # ---------------------------------------------------------------------- def test_dynamic(): sys.stderr.write("--- testing {intialize_state} ---\n") BCS, OPHS, TRS, JMS = block_example.misc_A(mp_fill, mp_jump) # Initialize the state: move_hp.initialize_state(BCS) # No dynamic attributes on moves; nothing to check. return # ---------------------------------------------------------------------- # Run the tests: test_static() test_dynamic()