def is_valid_body(term): """Whether a term is a valid body of a definition. Valid terms: * must be closed (no free IVARs) * must be normal * must have ABS only at the top level * cannot be TOP or BOT. """ assert isinstance(term, Term) if not is_closed(term): log_error('Not closed: {}'.format(term)) return False if not bohm.is_normal(term): log_error('Not normal: {}'.format(term)) return False # TODO Decide whether TOP and BOT should be allowed as bodies. # if term is TOP or term is BOT: # log_error('Disallowed: {}'.format(term)) # return False if is_join(term): return all(is_valid_body(part) for part in bohm.iter_join(term)) while is_abs(term): term = term[1] if not is_abs_free(term): log_error('ABS in inner term: {}'.format(term)) return False return True
def test_try_compute_step_runs(term): for step in xrange(5): with xfail_if_not_implemented(): result = bohm.try_compute_step(term) if is_normal(term): assert result is None return else: assert isinstance(result, Term)
def test_try_compute_step_runs(code): for step in xrange(5): with xfail_if_not_implemented(): result = try_compute_step(code) if is_normal(code): assert result is None return else: assert is_code(result)
def test_linear_is_normal(term): hypothesis.assume(is_linear(term)) assert is_normal(term)
def test_is_normal(term, expected_try_compute_step): expected = (expected_try_compute_step is None) assert is_normal(term) is expected
def test_linear_is_normal(code): hypothesis.assume(is_linear(code)) assert is_normal(code)