def test_bacon_number_04(): # random graph, Bacon number with no people N = random.randint(5, 10) k = random.randint(4, 7) assert len( lab.actors_with_bacon_number(lab.transform_data(make_bacon_tree(N, k)), int(1e20))) == 0 assert len( lab.actors_with_bacon_number(lab.transform_data(make_bacon_tree(N, k)), int(1e20))) == 0
def test_07(self): # random graph, Bacon number with no people N = random.randint(5, 10) k = random.randint(4, 7) self.assertEqual( len(lab.actors_with_bacon_number(make_bacon_tree(N, k), int(1e20))), 0) self.assertEqual( len(lab.actors_with_bacon_number(make_bacon_tree(N, k), int(1e20))), 0)
def test_e(self): n = 3 expected = set() result = lab.actors_with_bacon_number(self.data, n) self.assertTrue(isinstance(result, set)) self.assertEqual(result, expected)
def run_test(input_data): running_time = time.time() # Demux to the correct function try: if input_data["function"] == "pair": result = lab.acted_together(small_data, input_data["actor_1"], input_data["actor_2"]) # Actors with a given bacon number elif input_data["function"] == "set": result = lab.actors_with_bacon_number(small_data, input_data["n"]) # Paths in a small database elif input_data["function"] == "path_small": result = lab.get_bacon_path(small_data, input_data["actor_id"]) # Paths in a large database elif input_data["function"] == "path": result = lab.bacon_path(large_data, input_data["actor_id"]) running_time = time.time() - running_time return (running_time, result) except Exception: return ('error', traceback.format_exc())
def test_tiny_bacon_number_2(): # Actors w/ Bacon number of 2 in tiny n = 2 expected = {1640} result = lab.actors_with_bacon_number(db_tiny, n) assert isinstance(result, set) assert result == expected
def test_bacon_number_03(): # random large Bacon number N = random.randint(50, 100) k = random.randint(7, 30) assert len( lab.actors_with_bacon_number(lab.transform_data(make_bacon_tree(N, k)), N)) == k
def test_tiny_bacon_number_1(): # Actors w/ Bacon number of 1 in tiny n = 1 expected = {1532, 2876} result = lab.actors_with_bacon_number(db_tiny, n) assert isinstance(result, set) assert result == expected
def test_tiny_bacon_number_0(): # Actors w/ Bacon number of 0 in tiny n = 0 expected = {4724} result = lab.actors_with_bacon_number(db_tiny, n) assert isinstance(result, set) assert result == expected
def test_tiny_bacon_number_3(): # Actors w/ Bacon number of 3 in tiny n = 3 expected = set() result = lab.actors_with_bacon_number(db_tiny, n) assert isinstance(result, set) assert result == expected
def test_bacon_number_01(): # Actors with Bacon number of 2 n = 2 expected = { 1640, 1811, 2115, 2283, 2561, 2878, 3085, 4025, 4252, 4765, 6541, 9827, 11317, 14104, 16927, 16935, 19225, 33668, 66785, 90659, 183201, 550521, 1059002, 1059003, 1059004, 1059005, 1059006, 1059007, 1232763 } first_result = lab.actors_with_bacon_number(db_small, n) assert isinstance(first_result, set) assert first_result == expected second_result = lab.actors_with_bacon_number(db_small, n) assert isinstance(second_result, set) assert second_result == expected
def test_c(self): n = 1 expected = {2876, 1532} result = lab.actors_with_bacon_number(self.data, n) self.assertTrue(isinstance(result, set)) self.assertEqual(result, expected)
def test_04(self): # Actors with Bacon number of 2 n = 2 expected = { 1640, 1811, 2115, 2283, 2561, 2878, 3085, 4025, 4252, 4765, 6541, 9827, 11317, 14104, 16927, 16935, 19225, 33668, 66785, 90659, 183201, 550521, 1059002, 1059003, 1059004, 1059005, 1059006, 1059007, 1232763 } first_result = lab.actors_with_bacon_number(self.data, n) self.assertTrue(isinstance(first_result, set)) self.assertEqual(first_result, expected) second_result = lab.actors_with_bacon_number(self.data, n) self.assertTrue(isinstance(second_result, set)) self.assertEqual(second_result, expected)
def test_bacon_number_02(): # Actors with Bacon number of 3 n = 3 expected = { 52, 1004, 1248, 2231, 2884, 4887, 8979, 10500, 12521, 14792, 14886, 15412, 16937, 17488, 19119, 19207, 19363, 20853, 25972, 27440, 37252, 37612, 38351, 44712, 46866, 46867, 48576, 60062, 75429, 83390, 85096, 93138, 94976, 109625, 113777, 122599, 126471, 136921, 141458, 141459, 141460, 141461, 141495, 146634, 168638, 314092, 349956, 558335, 572598, 572599, 572600, 572601, 572602, 572603, 583590, 931399, 933600, 1086299, 1086300, 1168416, 1184797, 1190297, 1190298, 1190299, 1190300 } first_result = lab.actors_with_bacon_number(db_small, n) assert isinstance(first_result, set) assert first_result == expected second_result = lab.actors_with_bacon_number(db_small, n) assert isinstance(second_result, set) assert second_result == expected
def test_02(self): result = lab.actors_with_bacon_number(self.data, 2) expected = {1640} self.assertEqual(result, expected)
def test_01(self): result = lab.actors_with_bacon_number(self.data, 1) expected = {1532, 2876} self.assertEqual(result, expected)
def test_00(self): result = lab.actors_with_bacon_number(self.data, 0) expected = {4724} self.assertEqual(result, expected)
def bacon_number(d): return list(lab.actors_with_bacon_number(small_data, d["n"]))
def test_02(self): self.assertTrue( set([2876, 1532]) == lab.actors_with_bacon_number(self.data, 1))
def test_tiny_bacon_number_02(): # Simple test, same actor assert lab.actors_with_bacon_number(db_tiny, 2) == {1640}
def test_tiny_bacon_number_1(): #Actors with a bacon number of 1 in Tiny expected = {2876, 1532} result = lab.actors_with_bacon_number(db_tiny, 1) assert isinstance(result, set) assert result == expected
def test_06(self): # random large Bacon number N = random.randint(50, 100) k = random.randint(7, 30) self.assertEqual( len(lab.actors_with_bacon_number(make_bacon_tree(N, k), N)), k)
def test_04(self): result = lab.actors_with_bacon_number(self.data, 4) expected = set() self.assertEqual(result, expected)
def test_03(self): self.assertTrue( set([4724]) == lab.actors_with_bacon_number(self.data, 0))
def test_tiny_bacon_number_01(): # Simple test, same actor assert lab.actors_with_bacon_number(db_tiny, 1) == {2876, 1532}
def cat(params): path = os.path.join(cur_dir, params.get('path')) with open(path, 'r') as f: return f.read() def load_pickle(params): path = os.path.join(cur_dir, params.get('path')) with open(path, 'rb') as f: return pickle.load(f) special_routes = { '/ls': ls, '/cat': cat, '/load_pickle': load_pickle, '/better_together': lambda d: lab.acted_together(small_data, d['actor_1'], d['actor_2']), '/bacon_number': lambda d: list(lab.actors_with_bacon_number(small_data, d['n'])), '/bacon_path': lambda d: lab.bacon_path(small_data, d['actor_name']), '/restart': lambda d: (importlib.reload(lab) and {'ok': True}) } def application(environ, start_response): path = environ.get('PATH_INFO', '/') or '/' params = parse_post(environ) print(f'requested {path}, params: {params}') if path in special_routes: type_ = 'application/json' status = '200 OK' body = json.dumps(special_routes[path](params)).encode('utf-8') else:
def test_04(self): self.assertTrue( set([1640]) == lab.actors_with_bacon_number(self.data, 2))
def test_tiny_bacon_number_03(): # Simple test, same actor assert lab.actors_with_bacon_number(db_tiny, 3) == set()
def test_05(self): self.assertTrue(set() == lab.actors_with_bacon_number(self.data, 3))
def test_tiny_bacon_number_00(): # Simple test, same actor assert lab.actors_with_bacon_number(db_tiny, 0) == {4724}