def flare_plan_num_items_is(self, name, want_num_items): got_num_items = \ self.fcs.fc_solve_user_INTERNAL_get_flares_plan_num_items( self.user ) ok(want_num_items == got_num_items, name + " - got_num_items.")
def by_depth_max_depth_of_depth_idx_is(self, name, depth_idx, want_num): got_num = self.fcs.fc_solve_user_INTERNAL_get_by_depth_tests_max_depth( self.user, depth_idx ) ok(want_num == got_num, name + " - max_depth_of_depth_idx_is for" + str(depth_idx) + ".")
def compile_flares_plan_ok(self, name, flares_plan_string): instance_list_index = c_int() error_string = c_char_p() myplan = None if flares_plan_string: myplan = bytes(flares_plan_string, 'UTF-8') ret_code = self.fcs.freecell_solver_user_set_flares_plan( self.user, c_char_p(myplan) ) # TEST:$compile_flares_plan_ok++; ok(ret_code == 0, name + " - set_string returned success") ret_code = self.fcs.fc_solve_user_INTERNAL_compile_all_flares_plans( self.user, byref(instance_list_index), byref(error_string) ) # TEST:$compile_flares_plan_ok++; ok(ret_code == 0, name + " - returned success.") # TEST:$compile_flares_plan_ok++; ok(instance_list_index.value == -1, name + " - instance_list_index returned -1.") # TEST:$compile_flares_plan_ok++; ok(error_string.value is None, name + " - error_string returned NULL.")
def flare_plan_item_is_run_indef(self, name, item_idx, flare_idx): # TEST:$flare_plan_item_is_run_indef++; ok(self._get_plan_type(item_idx) == b"RunIndef", name + " - right type") got_flare_idx = \ self.fcs.fc_solve_user_INTERNAL_get_flares_plan_item_flare_idx( self.user, item_idx ) # TEST:$flare_plan_item_is_run_indef++; ok(got_flare_idx == flare_idx, name + " - matching flare_idx")
def main(): M_91 = M_func(100, 11, 10) # TEST is_ok(M_91.calc(101), 91, "M[91](101) == 91") # TEST is_ok(M_91.calc(91), 91, "M[91](91) == 91") # TEST ok(M_91.calc_F() == [91], "calc_F") # TEST ok(M_91.calc_SF() == long(91), "calc_SF") # TEST eq_ok(S_func(10, 10).calc(), long(225), "S(10,10)") # TEST eq_ok(S_func(1000, 1000).calc(), long(208724467), "S(1000,1000)")
def test_resume_solution_with_flares(): testname = "-l ve on iterative limiting - " fcs = FC_Solve() step = 1000 hard_limit = 100000 limit = step # TEST*$input_cmd_line fcs.input_cmd_line("video-editing", ['-l', 'video-editing']) fcs.limit_iterations(limit) # MS deal No. 124 ret = fcs.solve_board( """7S AS 2C QS TH QD 7D 5D 8D 9D JH QH 5C JD 6D TD 5H 2S 6S TC KS TS 4S 3D 9C 3C KD 7C 6H 5S 9H 6C KC AH AC 4C 8S 2D QC JS 9S KH 8C 4D 7H 4H 2H 3S 8H AD 3H JC """ ) iters_count_ok = 1 while (ret == 5 and limit < hard_limit): if (fcs.get_num_times() != limit): iters_count_ok = 0 limit += step fcs.limit_iterations(limit) ret = fcs.resume_solution() # TEST ok(ret == 0, testname + "State was successfully solved.") # TEST ok(iters_count_ok == 1, testname + "Iters count was OK throughout the solution.")
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_resume_solution(): testname = "With RunIndef - " fcs = FC_Solve() limit = 10 fcs.limit_iterations(limit) ret = fcs.solve_board( """4C 2C 9C 8C QS 4S 2H 5H QH 3C AC 3H 4H QD QC 9S 6H 9H 3S KS 3D 5D 2S JC 5C JH 6D AS 2D KD TH TC TD 8D 7H JS KH TS KC 7C AH 5S 6S AD 8H JD 7S 6C 7D 4D 8S 9D """ ) iters_count_ok = 1 while (ret == 5): if (fcs.get_num_times() != limit): iters_count_ok = 0 limit += 10 fcs.limit_iterations(limit) ret = fcs.resume_solution() # TEST ok(ret == 0, testname + "State was successfully solved.") # TEST ok(iters_count_ok == 1, testname + "Iters count was OK throughout the solution.") return
def shlomif_main(args): plan(4) card1 = AbstractCard(1001, 0, 1, 2, 3001) # TEST ok(card1.color == 0, 'card1.color is sane.') # TEST ok(card1.rank == 2, 'card1.rank') card2 = AbstractCard(1001, 0, 3, 7, 3001) # TEST ok(card2.color == 1, 'card2.color is sane.') # TEST ok(card2.rank == 7, 'card2.rank')
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 shlomif_main(args): plan(3) rand = constructRandom('24') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok (got_s == '''4C 2C 9C 8C QS 4S 2H 5H QH 3C AC 3H 4H QD QC 9S 6H 9H 3S KS 3D 5D 2S JC 5C JH 6D AS 2D KD TH TC TD 8D 7H JS KH TS KC 7C AH 5S 6S AD 8H JD 7S 6C 7D 4D 8S 9D ''', 'Deal 24', ); rand = constructRandom('ms123456') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok (got_s == '''QD TC AS KC AH KH 6H 6D TD 8D TH 7C 2H 9C AC AD 5C 5H 8C 9H 9D JS 8S 4D 4C 2S 7D 3C 7H 7S 9S 2C JC 5S 5D 3S 3D 3H KD JH 6C QS 4S 2D KS TS JD QH 6S 4H QC 8H ''', 'Microsoft Deal 123456', ); rand = constructRandom('123456') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok (got_s == '''3D 6C AS TS QC 8D 4D 2D TC 4H JD TD 2H 5C 2C 8S AH KD KH 5S 7C 9C 8C QH 3C 5D 9S QD AC 9D 7H 6D KS JH 6H TH 8H QS 7D JC 4C 2S 3S 6S 5H 3H KC JS 9H 4S 7S AD ''', 'PySolFC deal No. 123456', );
def flare_plan_item_is_run(self, name, item_idx, flare_idx, iters_count): # TEST:$flare_plan_item_is_run++; ok(self._get_plan_type(item_idx) == b"Run", name + " - right type") got_flare_idx = \ self.fcs.fc_solve_user_INTERNAL_get_flares_plan_item_flare_idx( self.user, item_idx ) # TEST:$flare_plan_item_is_run++; ok(got_flare_idx == flare_idx, name + " - matching flare_idx") got_iters_count = \ self.fcs.fc_solve_user_INTERNAL_get_flares_plan_item_iters_count( self.user, item_idx ) # TEST:$flare_plan_item_is_run++; ok(got_iters_count == iters_count, name + " - matching iters_count")
def test_num_states_in_collection_after_unsolved(): testname = "NumStatesInCol-After-unsolved - " tags_str = os.getenv('FCS_TEST_TAGS') if not tags_str: tags_str = '' if re.search(r'\bfc_only\b', tags_str): for idx in range(0, 3): ok(True, 'skipping because not-freecell test on a freecell build', skip='fc_only') return fcs = FC_Solve() # TEST*$input_cmd_line fcs.input_cmd_line("bakers_game", ['-g', 'bakers_game']) # MS-Freeceel board No. 10 fcs.solve_board( """5S KD JC TS 9D KH 8D 5H 2S 9H 7H TD AD 6D 6H QD 6C TC AH 8S TH 6S 2D 7C QC QS 7D 3H 5D AS 7S KC 3D AC 4D 9C QH 4H 4C 5C 2H 3S 8H 9S JS 4S JH JD 3C KS 2C 8C """ ) # TEST ok(fcs.get_num_times() == 3436, testname + "Get num times is OK.") # TEST ok(fcs.get_num_states_in_col() == 3436, testname + "Num-states-in-collection is OK.") return
def eq_ok(have, want, blurb): ret = ok(have == want, blurb) if (not ret): diag("(have = '%s', want = '%s')" % (have, want)) return ret
def test_board_l(idx, want_string): buf = (b"x" * 500) fc_solve_get_board_l(c_longlong(idx), c_char_p(buf)) ok(buf[0:buf.find(b"\0")] == bytes(want_string, 'UTF-8'), ("long board %d was generated fine" % (idx)))
def shlomif_main(args): plan(8) rand = constructRandom('24') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok (got_s == '''4C 2C 9C 8C QS 4S 2H 5H QH 3C AC 3H 4H QD QC 9S 6H 9H 3S KS 3D 5D 2S JC 5C JH 6D AS 2D KD TH TC TD 8D 7H JS KH TS KC 7C AH 5S 6S AD 8H JD 7S 6C 7D 4D 8S 9D ''', 'Deal 24', ); rand = constructRandom('ms123456') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok (got_s == '''QD TC AS KC AH KH 6H 6D TD 8D TH 7C 2H 9C AC AD 5C 5H 8C 9H 9D JS 8S 4D 4C 2S 7D 3C 7H 7S 9S 2C JC 5S 5D 3S 3D 3H KD JH 6C QS 4S 2D KS TS JD QH 6S 4H QC 8H ''', 'Microsoft Deal 123456', ); rand = constructRandom('123456') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok (got_s == '''3D 6C AS TS QC 8D 4D 2D TC 4H JD TD 2H 5C 2C 8S AH KD KH 5S 7C 9C 8C QH 3C 5D 9S QD AC 9D 7H 6D KS JH 6H TH 8H QS 7D JC 4C 2S 3S 6S 5H 3H KC JS 9H 4S 7S AD ''', 'PySolFC deal No. 123456', ); rand = constructRandom('ms3000000000') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok (got_s == '''8D TS JS TD JH JD JC 4D QS TH AD 4S TC 3C 9H KH QH 4C 5C KD AS 9D 5D 8S 4H KS 6S 9S 6H 2S 7H 3D KC 2C 9C 7C QC 7S QD 7D 6C 3H 8H AC 6D 3S 8C AH 2H 5H 2D 5S ''', 'Microsoft Deal #3E9 - long seed.', ); rand = constructRandom('ms6000000000') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok (got_s == '''2D 2C QS 8D KD 8C 4C 3D AH 2H 4H TS 6H QD 4D JS AD 6S JH JC JD KH 3H KS AS TC 5D AC TD 7C 9C 7H 3C 3S QH 9H 9D 5S 7S 6C 5C 5H 2S KC 9S 4S 6D QC 8S TH 7D 8H ''', 'Microsoft Deal #6E9 - extra long seed.', ); inp = 'ms12345678' got = random__long2str(random__str2long(inp)) # TEST ok (got == inp, 'long2str ms roundtrip.') inp = '246007891097' got = random__long2str(random__str2long(inp)) # TEST ok (got == inp, 'long2str PySolFC roundtrip.') proto_inp = '246007891097' inp = random__str2long(proto_inp) got = random__str2long(random__long2str(inp)) # TEST ok (got == inp, 'str2long PySolFC roundtrip.')
def test_num_states_in_collection_after_recycle(): testname = "NumStatesInCol-After-Recycle - " fcs = FC_Solve() # MS-Freeceel board No. 24. fcs.solve_board( """4C 2C 9C 8C QS 4S 2H 5H QH 3C AC 3H 4H QD QC 9S 6H 9H 3S KS 3D 5D 2S JC 5C JH 6D AS 2D KD TH TC TD 8D 7H JS KH TS KC 7C AH 5S 6S AD 8H JD 7S 6C 7D 4D 8S 9D """ ) # TEST ok(fcs.get_num_times() == 137, testname + "Get num times is OK.") # TEST ok(fcs.get_num_states_in_col() == 191, testname + "Num-states-in-collection is OK.") fcs.recycle() # TEST ok(fcs.get_num_times() == 0, testname + "Get num times immediately after recycle.") # TEST ok(fcs.get_num_states_in_col() == 0, testname + "Num-states-in-collection immediately after recycle.") # MS-Freeceel board No. 24. fcs.solve_board( """4C 2C 9C 8C QS 4S 2H 5H QH 3C AC 3H 4H QD QC 9S 6H 9H 3S KS 3D 5D 2S JC 5C JH 6D AS 2D KD TH TC TD 8D 7H JS KH TS KC 7C AH 5S 6S AD 8H JD 7S 6C 7D 4D 8S 9D """ ) # TEST ok(fcs.get_num_times() == 137, testname + "Get num times after recycle.") # TEST ok(fcs.get_num_states_in_col() == 191, testname + "Num-states-in-collection after recycle.") return
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))
def shlomif_main(args): plan(8) rand = constructRandom('24') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok( got_s == '''4C 2C 9C 8C QS 4S 2H 5H QH 3C AC 3H 4H QD QC 9S 6H 9H 3S KS 3D 5D 2S JC 5C JH 6D AS 2D KD TH TC TD 8D 7H JS KH TS KC 7C AH 5S 6S AD 8H JD 7S 6C 7D 4D 8S 9D ''', 'Deal 24', ) rand = constructRandom('ms123456') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok( got_s == '''QD TC AS KC AH KH 6H 6D TD 8D TH 7C 2H 9C AC AD 5C 5H 8C 9H 9D JS 8S 4D 4C 2S 7D 3C 7H 7S 9S 2C JC 5S 5D 3S 3D 3H KD JH 6C QS 4S 2D KS TS JD QH 6S 4H QC 8H ''', 'Microsoft Deal 123456', ) rand = constructRandom('123456') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok( got_s == '''3D 6C AS TS QC 8D 4D 2D TC 4H JD TD 2H 5C 2C 8S AH KD KH 5S 7C 9C 8C QH 3C 5D 9S QD AC 9D 7H 6D KS JH 6H TH 8H QS 7D JC 4C 2S 3S 6S 5H 3H KC JS 9H 4S 7S AD ''', 'PySolFC deal No. 123456', ) rand = constructRandom('ms3000000000') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok( got_s == '''8D TS JS TD JH JD JC 4D QS TH AD 4S TC 3C 9H KH QH 4C 5C KD AS 9D 5D 8S 4H KS 6S 9S 6H 2S 7H 3D KC 2C 9C 7C QC 7S QD 7D 6C 3H 8H AC 6D 3S 8C AH 2H 5H 2D 5S ''', 'Microsoft Deal #3E9 - long seed.', ) rand = constructRandom('ms6000000000') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok( got_s == '''2D 2C QS 8D KD 8C 4C 3D AH 2H 4H TS 6H QD 4D JS AD 6S JH JC JD KH 3H KS AS TC 5D AC TD 7C 9C 7H 3C 3S QH 9H 9D 5S 7S 6C 5C 5H 2S KC 9S 4S 6D QC 8S TH 7D 8H ''', 'Microsoft Deal #6E9 - extra long seed.', ) inp = 'ms12345678' got = random__long2str(random__str2long(inp)) # TEST ok(got == inp, 'long2str ms roundtrip.') inp = '246007891097' got = random__long2str(random__str2long(inp)) # TEST ok(got == inp, 'long2str PySolFC roundtrip.') proto_inp = '246007891097' inp = random__str2long(proto_inp) got = random__str2long(random__long2str(inp)) # TEST ok(got == inp, 'str2long PySolFC roundtrip.')
schema_names = test_schemata.keys() schema_names.sort() for schema_name in schema_names: rx = Rx.Factory({"register_core_types": True}) schema_test_spec = test_schemata[schema_name] if schema_test_spec.get("composedtype", False): try: rx.learn_type(schema_test_spec['composedtype']['uri'], schema_test_spec['composedtype']['schema']) except Rx.Error, e: if schema_test_spec['composedtype'].get("invalid", False): ok(1, "BAD COMPOSED TYPE: schemata %s" % schema_name) continue else: raise if schema_test_spec['composedtype'].get("invalid", False): ok(0, "BAD COMPOSED TYPE: schemata %s" % schema_name) if schema_test_spec['composedtype'].get("prefix", False): rx.add_prefix(schema_test_spec['composedtype']['prefix'][0], schema_test_spec['composedtype']['prefix'][1]) try: schema = rx.make_schema(schema_test_spec["schema"]) except Rx.Error, e: if schema_test_spec.get("invalid", False):
def flare_plan_item_is_checkpoint(self, name, item_idx): # TEST:$flare_plan_item_is_checkpoint++; ok(self._get_plan_type(item_idx) == b"CP", name + " - right type")
def num_by_depth_tests_order_is(self, name, want_num): got_num = self.fcs.fc_solve_user_INTERNAL_get_num_by_depth_tests_order( self.user ) ok(want_num == got_num, name + " - by_depth_tests_order.")