def mytest(input_text, want_out, msg): global py_prog process = subprocess.Popen( ['python3', py_prog, '-'], shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE ) process.stdin.write(bytes(input_text, 'utf_8')) process.stdin.close() got_out = process.stdout.read().decode('utf-8') if not ok(_normalize_lf(got_out) == _normalize_lf(want_out), msg): diag("Received [[[%s]]]" % (got_out))
def test_befs_weights(self, name, string, weights): # TEST:$test_befs=$test_befs+$set_befs; self._set_befs_weights(name, string) for idx in range(0, self.NUM_BEFS_WEIGHTS): top = bottom = weights[idx] # floating-point values. if (top != int(top) + 0.0): top = top + 1e-6 bottom = bottom - 1e-6 have = self.get_befs_weight(self.user, idx) # TEST:$test_befs=$test_befs+$num_befs_weights; if (not ok((bottom <= have) and (have <= top), name + " - Testing Weight No. " + str(idx))): diag("Should be: [" + str(bottom) + "," + str(top) + "] ; " + "Is: " + str(have))
def __init__(self): self.fcs = CDLL("../libfreecell-solver." + ("dll" if (platform.system() == 'Windows') else "so")) self.user_alloc = self.fcs.freecell_solver_user_alloc self.user_alloc.restype = c_void_p self.u_get_num_times = self.fcs.freecell_solver_user_get_num_times_long self.u_get_num_times.restype = c_long prefix = 'freecell_solver_user' func = 'get_num_states_in_collection_long' self.get_num_states = self.fcs[prefix + '_' + func] self.get_num_states.restype = c_long self.user = c_void_p(self.user_alloc()) diag("[Gnoom] self.user = <%s>" % self.user) self.get_befs_weight = self.fcs.fc_solve_user_INTERNAL_get_befs_weight self.get_befs_weight.restype = c_double
def input_cmd_line(self, name, cmd_line_args): last_arg = c_int() error_string = c_char_p() known_params = c_char_p(None) opened_files_dir = create_string_buffer(32001) diag("opened_files_dir = <%s>" % opened_files_dir) if False: # (platform.system() == 'Windows'): import sys sys.exit(1) cmd_line_args_tuple = tuple(cmd_line_args) prefix = 'freecell_solver_user_cmd_line' func = 'parse_args_with_file_nesting_count' self.fcs[prefix + '_' + func]( self.user, # instance len(cmd_line_args), # argc ((c_char_p * len(cmd_line_args))( *tuple(bytes(s, 'UTF-8') for s in cmd_line_args_tuple) )), # argv 0, # start_arg byref(known_params), # known_params None, # callback None, # callback_context byref(error_string), # error_string byref(last_arg), # last_arg c_int(-1), # file_nesting_count opened_files_dir ) # TEST:$input_cmd_line++; is_ok(last_arg.value, len(cmd_line_args), name + " - assign weights - processed two arguments")
def eq_ok(have, want, blurb): ret = ok(have == want, blurb) if (not ret): diag("(have = '%s', want = '%s')" % (have, want)) return ret
def check_sum(n, p, val): ret = pascal_sum(n, p) if not ok(ret == val, "pascal_sum(%d,%d)" % (n, p)): diag("got = %d ; expected = %d" % (ret, val))