예제 #1
0
파일: wrapper.py 프로젝트: lasernite/6fop
def run_test(input_data):
	running_time = time.time()

	# Demux to the correct function
	try:
		if input_data["function"] == "pair":
			result = lab.did_x_and_y_act_together(small_data, input_data["actor_1"], input_data["actor_2"])

		# Actors with a given bacon number
		elif input_data["function"] == "set":
			result = lab.get_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.get_bacon_path(large_data, input_data["actor_id"])

		running_time = time.time() - running_time

	except ValueError as e:
		return e.message

	except:
		return traceback.format_exc()

	return running_time, result
예제 #2
0
파일: wrapper.py 프로젝트: khuntermit/6.009
def run_test(input_data):
    running_time = time.time()

    # Demux to the correct function
    try:
        if input_data["function"] == "pair":
            result = lab.did_x_and_y_act_together(small_data,
                                                  input_data["actor_1"],
                                                  input_data["actor_2"])

        # Actors with a given bacon number
        elif input_data["function"] == "set":
            result = lab.get_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.get_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())
예제 #3
0
    def test_10(self):
        # Bacon path, small database, path does not exist
        actor_id = 2876669
        expected = None

        first_result = lab.get_bacon_path(self.db_small, actor_id)
        self.assertEqual(first_result, expected)

        second_result = lab.get_bacon_path(self.db_small, actor_id)
        self.assertEqual(second_result, expected)
예제 #4
0
 def test_14(self):
     # Bacon path, large database, length of 6 (7 actors, 6 movies)
     actor_id = 1345462
     len_expected = 6
     result = lab.get_bacon_path(self.db_large, actor_id)
     # here, we compute the result twice, to test for mutation of the db
     result = lab.get_bacon_path(self.db_large, actor_id)
     len_result = -1 if result is None else len(result) - 1
     self.assertTrue(valid_path(self.db_large, result))
     self.assertEqual(len_result, len_expected)
     self.assertEqual(result[0], 4724)
     self.assertEqual(result[-1], actor_id)
예제 #5
0
 def test_13(self):
     # Bacon path, large database, length of 4 (5 actors, 4 movies)
     actor_id = 197897
     len_expected = 4
     result = lab.get_bacon_path(self.db_large, actor_id)
     len_result = -1 if result is None else len(result) - 1
     self.assertTrue(valid_path(self.db_large, result))
     self.assertEqual(len_result, len_expected)
     self.assertEqual(result[0], 4724)
     self.assertEqual(result[-1], actor_id)
예제 #6
0
 def test_11(self):
     # Bacon path, small database, length of 3 (4 actors, 3 movies)
     actor_id = 46866
     len_expected = 3
     result = lab.get_bacon_path(self.db_small, actor_id)
     len_result = -1 if result is None else len(result) - 1
     self.assertTrue(valid_path(self.db_small, result))
     self.assertEqual(len_result, len_expected)
     self.assertEqual(result[0], 4724)
     self.assertEqual(result[-1], actor_id)
예제 #7
0
 def test_get_bacon_path(self):
     # Bacon path, lenght of 3
     actor_id = 46866
     len_expected = 3
     result = lab.get_bacon_path(self.data, actor_id)
     len_result = -1 if result is None else len(result) - 1
     self.assertTrue(valid_path(self.data, result))
     self.assertEqual(len_result, len_expected)
     self.assertEqual(result[0], 4724)
     self.assertEqual(result[-1], actor_id)
예제 #8
0
 def test_10(self):
     # Bacon path, large database, length of 4
     actor_id = 1345462
     len_expected = 6
     result = lab.get_bacon_path(self.db_large, actor_id)
     len_result = -1 if result is None else len(result) - 1
     self.assertTrue(valid_path(self.db_large, result))
     self.assertEqual(len_result, len_expected)
     self.assertEqual(result[0], 4724)
     self.assertEqual(result[-1], actor_id)
예제 #9
0
 def test_Bacon_path(self):
     self.assertEqual(lab.get_bacon_path(self.data, 46866),
                      [4724, 2876, 1640, 46866])
예제 #10
0
 def test_15(self):
     # Bacon path, large database, does not exist
     actor_id = 1204555
     expected = None
     result = lab.get_bacon_path(self.db_large, actor_id)
     self.assertEqual(result, expected)
예제 #11
0
파일: wrapper.py 프로젝트: khuntermit/6.009
def bacon_path(d):
    return lab.get_bacon_path(small_data, d["actor_name"])
예제 #12
0
파일: wrapper.py 프로젝트: lasernite/6fop
def bacon_path(d):
	return lab.get_bacon_path(small_data, d["actor_name"])