import random from faker import Faker from commands import Test NUM_USERS = 1000 USERS_PATH = "users.db" CHECKER_PATH = "checker/input/" fake = Faker('ro_RO') Faker.seed(420) users = [] def generate_users(): for _ in range(NUM_USERS): name = fake.name().split()[0] name = name.replace('ș', 's') name = name.replace('ă', 'a') name = name.replace('ț', 't') name = name.replace('â', 'a') name = name.replace('Ș', 'S') if name not in users: users.append(name) with open(USERS_PATH, "w") as f: f.write(f"{len(users)}\n") f.write("\n".join(users)) def test_dist(difficult = False, test = None): commands = [] test = Test(users) if test is None else test nameFirst = None name2 = None for _ in range(3 * (5 if difficult else 1)): string, name1, name2 = test.generate_add(name1=name2) if nameFirst is None: nameFirst = name1 commands.append(string) commands.append(test.generate_distance(nameFirst, name2)[0]) for _ in range(3 * (5 if difficult else 1)): string, _, _ = test.generate_add(name1=nameFirst) commands.append(string) for _ in range(5 * (2 if difficult else 1)): string, _, name2 = test.generate_distance(nameFirst) commands.append(string) if not difficult: return commands nameFirst = None name2 = None for _ in range(10): string, name1, name2 = test.generate_add(name1=name2) if nameFirst is None: nameFirst = name1 commands.append(string) commands.append(test.generate_distance(nameFirst, name2)[0]) nameSecond = name2 name2 = nameFirst for _ in range(3): string, name1, name2 = test.generate_add(name1=name2) if nameFirst is None: nameFirst = name1 commands.append(string) string, name1, name2 = test.generate_add(name1=name2, name2=nameSecond) commands.append(string) commands.append(test.generate_distance(nameFirst, nameSecond)[0]) commands.append(test.generate_remove(name1, name2)[0]) commands.append(test.generate_distance(nameFirst, nameSecond)[0]) return commands def test_suggestions(difficult = False, test = None): commands = [] test = Test(users) if test is None else test string, name1, name2 = test.generate_add() nameStarting = name1 nameFirst = name2 commands.append(string) for _ in range(5): string, name1, name2 = test.generate_add(name1=nameFirst) commands.append(string) commands.append(test.generate_suggestions(nameStarting)[0]) if not difficult: return commands for _ in range(5): string, name1, name2 = test.generate_add(name1=nameFirst) commands.append(string) for _ in range(10): string, name1, name2 = test.generate_add(useExisting=True) commands.append(string) for _ in range(5): string, _ = test.generate_suggestions() commands.append(string) return commands def test_common(difficult = False, test = None): commands = [] test = Test(users) if test is None else test string, name1, name2 = test.generate_add() nameFirst = name2 commands.append(string) for _ in range(5): string, name1, name2 = test.generate_add(name1=nameFirst) commands.append(string) name2 = None for _ in range(3): string, name1, name2 = test.generate_add(name2=name2, useExisting=True) commands.append(string) commands.append(test.generate_common(name1=nameFirst, name2=name2)[0]) if not difficult: return commands for _ in range(5): string, name1, name2 = test.generate_add() commands.append(string) for _ in range(10): string, name1, name2 = test.generate_add(useExisting=True) commands.append(string) for _ in range(5): string, _, _ = test.generate_common() commands.append(string) return commands def test_popular(difficult = False, test = None): commands = [] names = [] test = Test(users) if test is None else test string, name1, name2 = test.generate_add() nameFirst = name2 commands.append(string) for _ in range(test.get_random(3, 10)): string, name1, name2 = test.generate_add(name1=nameFirst) if nameFirst is None: nameFirst = name1 commands.append(string) commands.append(test.generate_friends(nameFirst)[0]) names.append(nameFirst) nameFirst = None for _ in range(test.get_random(3, 10)): string, name1, name2 = test.generate_add(name1=nameFirst) if nameFirst is None: nameFirst = name1 commands.append(string) commands.append(test.generate_friends(nameFirst)[0]) names.append(nameFirst) nameFirst = None for _ in range(test.get_random(3, 10)): string, name1, name2 = test.generate_add(name1=nameFirst) if nameFirst is None: nameFirst = name1 commands.append(string) commands.append(test.generate_friends(nameFirst)[0]) names.append(nameFirst) commands.append(test.generate_add(name1=names[0], name2=names[1])[0]) for name in names: commands.append(test.generate_popular(name1=name)[0]) if not difficult: return commands names.clear() for _ in range(5): string, name1, name2 = test.generate_add() commands.append(string) nameFirst = None for _ in range(3): string, name1, name2 = test.generate_add(name1=nameFirst) if nameFirst is None: nameFirst = name1 commands.append(string) commands.append(test.generate_friends(nameFirst)[0]) names.append(nameFirst) nameFirst = None for _ in range(3): string, name1, name2 = test.generate_add(name1=nameFirst) if nameFirst is None: nameFirst = name1 commands.append(string) commands.append(test.generate_friends(nameFirst)[0]) names.append(nameFirst) commands.append(test.generate_add(names[0], names[1])[0]) for name in names: commands.append(test.generate_friends(name1=name)[0]) for name in names: commands.append(test.generate_popular(name1=name)[0]) for _ in range(5): commands.append(test.generate_popular()[0]) return commands def test_create(difficult = False, test = None): commands = [] test = Test(users) if test is None else test for _ in range(5 * (2 if difficult else 1)): commands.append(test.generate_create()) for _ in range(10 * (2 if difficult else 1)): commands.append(test.generate_repost(isRepost=test.get_random(1, 3) == 2)) commands.append("get-reposts 10 12") commands.extend(test.generate_show(num=5 * (2 if difficult else 1), with_reposts=difficult)) return commands def test_lca(difficult = False, test = None): commands = [] test = Test(users) if test is None else test for _ in range(5 * (2 if difficult else 1)): commands.append(test.generate_create()) for _ in range(10 * (2 if difficult else 1)): commands.append(test.generate_repost(isRepost=False)) for _ in range(10 * (2 if difficult else 1)): commands.append(test.generate_repost(isRepost=True)) for _ in range(5 * (2 if difficult else 1)): commands.append(test.generate_lca()) return commands def test_like(difficult = False, test = None): commands = [] test = Test(users) if test is None else test for _ in range(5 * (2 if difficult else 1)): commands.append(test.generate_create()) for _ in range(5 * (2 if difficult else 1)): commands.append(test.generate_repost(isRepost=test.get_random(1, 3) == 2)) for _ in range(10 * (4 if difficult else 1)): commands.append(test.generate_like(isRepost=test.get_random(1, 3) == 2)) commands.extend(test.generate_get_like(num=5 * (2 if difficult else 1), with_reposts=difficult)) return commands def test_ratio(difficult = False, test = None): commands = [] test = Test(users) if test is None else test for _ in range(5 * (2 if difficult else 1)): commands.append(test.generate_create()) for _ in range(5 * (2 if difficult else 1)): commands.append(test.generate_repost(isRepost=test.get_random(1, 3) == 2)) for _ in range(10 * (4 if difficult else 1)): commands.append(test.generate_like(isRepost=test.get_random(1, 3) == 2)) for _ in range(10): commands.append(test.generate_like(id=3, isRepost=test.get_random(1, 4) == 2)) for _ in range(10* (3 if difficult else 1)): commands.append(test.generate_like(id=4, isRepost=True)) commands.extend(test.generate_get_like(num=5 * (2 if difficult else 1), with_reposts=difficult)) commands.append(f"ratio 3") commands.append(f"ratio 4") commands.append(f"ratio 1") if difficult: commands.append(f"ratio 7") commands.append(f"ratio 8") return commands def test_feed(difficult = False, test = None): commands = [] test = Test(users) if test is None else test name = None for _ in range(5 * (2 if difficult else 1)): string, name, _ = test.generate_add(name1=name) commands.append(string) for _ in range(5 * (2 if difficult else 1)): commands.append(test.generate_create(useExisting=True)) for _ in range(5 * (2 if difficult else 1)): commands.append(test.generate_repost(useExisting=True, isRepost=test.get_random(1, 3) == 2)) commands.append(test.generate_feed(name=name, size=10 * (2 if difficult else 1))) if difficult: for _ in range(4): commands.append(test.generate_feed(size=5 * (2 if difficult else 1))) return commands def test_profile(difficult = False, test = None): commands = [] test = Test(users) if test is None else test name = None for _ in range(5 * (2 if difficult else 1)): string, name, _ = test.generate_add(name1=name) commands.append(string) for _ in range(5 * (2 if difficult else 1)): commands.append(test.generate_create(useExisting=True)) for _ in range(5 * (2 if difficult else 1)): commands.append(test.generate_repost(useExisting=True, isRepost=test.get_random(1, 3) == 2)) commands.append(test.generate_profile(name=name)) if difficult: test.generate_profile() for _ in range(3): commands.append(test.generate_profile()) return commands def test_reposts(difficult = False, test = None): commands = [] test = Test(users) if test is None else test name = None for _ in range(10 * (2 if difficult else 1)): string, name, _ = test.generate_add(name2=name) commands.append(string) for _ in range(1 * (2 if difficult else 1)): commands.append(test.generate_create(name=name, useExisting=True)) for _ in range(5 * (2 if difficult else 1)): commands.append(test.generate_repost(useExisting=True, isRepost=test.get_random(1, 3) == 2)) for _ in range(2): commands.append(test.generate_friend_repost()) if difficult: for _ in range(4): commands.append(test.generate_friend_repost()) return commands def test_clique(difficult = False, test = None): commands = [] test = Test(users) if test is None else test for _ in range(3): string, name1, _ = test.generate_add() commands.append(string) for _ in range(3 * (3 if difficult else 1)): commands.append(test.generate_clique(size=test.get_random(3, 7 * (2 if difficult else 1)))[0]) return commands def generate_tests(tests, name): # for i, test in enumerate(tests): # with open(f"{CHECKER_PATH}{i * 2:02}-{name}.in", "w") as f: # comm = test(False) # f.write("\n".join(comm)) # with open(f"{CHECKER_PATH}{i * 2 + 1:02}-{name}.in", "w") as f: # comm = test(True) # f.write("\n".join(comm)) for i in range(2): comms = [] test_obj = Test(users) if name == "feed": tests = tests_friends + tests_posts + tests_feed random.shuffle(tests) for test in tests: comms.extend(test(i != 0, test_obj)) with open(f"{CHECKER_PATH}{i + 8:02}-{name}.in", "w") as f: f.write("\n".join(comms)) tests_friends = [test_dist, test_suggestions, test_common, test_popular] tests_posts = [test_create, test_lca, test_like, test_ratio] tests_feed = [test_feed, test_profile, test_reposts, test_clique] add_number = [] generate_users() # generate_tests(tests_friends, "friends") generate_tests(tests_posts, "posts") generate_tests(tests_feed, "feed")