def test_add_vertex(self): self.assertEqual(True, self.graph.is_vertex(self.movie)) self.assertEqual(True, self.graph.is_vertex(self.actor)) self.assertEqual( True, self.graph.is_vertex(Actor(str(4), 4, 'https://' + str(4)))) self.assertEqual(False, self.graph.is_vertex(Actor("hi", 32, 'https:?')))
def test_from_dict(self): actor = Actor("h", 3, 4) actor = actor.from_dict({ "name": "Test1", "age": 24, "total_gross": 45 }) self.assertEqual(self.actor1, actor)
def test_delete_vertex(self): self.graph.delete_vertex(self.movie) neighbor = Actor(str(1), 1, 'https://' + str(1)) self.assertEqual(False, self.graph.is_vertex(self.movie)) self.assertEqual(False, self.graph.is_edge(neighbor, self.movie)) self.graph.add_vertex(self.movie) for i in range(10): self.graph.add_edge(self.movie, Actor(str(i), i, 'https://' + str(i)), 0)
def test_from_json(self): self.assertEqual(5, len(self.graph.get_actors_with({}))) self.assertEqual(4, len(self.graph.get_movies_with({}))) for i in range(1, 5): assert self.graph.is_vertex(Actor("actor" + str(i), i, i)) assert self.graph.is_vertex( Movie("movie" + str(i), i, i, "http://movie" + str(i))) assert self.graph.is_edge(self.actor1, self.movie1) assert not self.graph.is_edge(Actor("actor3", 3, 3), Movie("movie4", 4, 4, "http://movie4"))
class ActorTest(unittest.TestCase): def setUp(self): self.actor1 = Actor("Test1", 24, 45) self.actor2 = Actor("Test2", 32, 55) def test_init(self): self.assertEqual("Test1", self.actor1.name) self.assertEqual(24, self.actor1.age) self.assertEqual(45, self.actor1.total_gross) def test_eq(self): self.assertEqual(Actor("Test1", 24, 45), self.actor1) self.assertNotEqual(self.actor1, self.actor2) def test_to_dict(self): self.assertEqual( { "json_class": "Actor", "name": "Test1", "age": 24, "total_gross": 45 }, self.actor1.to_dict()) def test_from_dict(self): actor = Actor("h", 3, 4) actor = actor.from_dict({ "name": "Test1", "age": 24, "total_gross": 45 }) self.assertEqual(self.actor1, actor)
def test_get_all_with(self): def f(x): return isinstance(x, Actor) actors = [Actor(str(i), i, 'https://' + str(i)) for i in range(10)] actors.append(self.actor) self.assertEqual(set(actors), set(self.graph.get_all_with(f)))
def setUp(self): self.graph = ActorMovieGraph() self.graph.from_json( '/Users/jearbear154/Desktop/School/F17*/242/Assignment2.1/src/tests/test.json' ) self.actor1 = Actor("actor1", 1, 1) self.movie1 = Movie("movie1", 1, 1, "http://movie1")
def from_json(self, file): f = open(file, 'r') movie_actor_list = json.load(f) f.close() for actor in movie_actor_list[0].values(): self.add_vertex( Actor(actor["name"], actor["age"], actor["total_gross"])) for movie in movie_actor_list[1].values(): self.add_vertex( Movie(movie["name"], movie["box_office"], movie["year"], movie["wiki_page"])) for actor in movie_actor_list[0].values(): # make actor->movie edges for movie in actor["movies"]: u = self.get_actors_with({"name": actor['name']}) v = self.get_movies_with({"name": movie}) if u != [] and v != []: self.add_edge(u[0], v[0], 0) for movie in movie_actor_list[1].values(): # make movie->actor edges for actor in movie["actors"]: u = self.get_movies_with({"name": movie['name']}) v = self.get_actors_with({"name": actor}) if u != [] and v != []: self.add_edge(u[0], v[0], 0)
def test_add_edge(self): for i in range(10): self.assertEqual( True, self.graph.is_edge(self.movie, Actor(str(i), i, 'https://' + str(i)))) self.assertEqual( True, self.graph.is_edge( self.actor, Movie(str(i), i, i * 100, 'https://' + str(i)))) self.assertEqual( True, self.graph.is_edge( Actor(str(i), i, 'https://' + str(i)), Movie(str(i), i, i * 100, 'https://' + str(i)))) self.assertEqual(False, self.graph.is_edge(self.movie, self.actor))
def test_get_neighbors(self): self.assertEqual( set([ Movie(str(i), i, i * 100, 'https://' + str(i)) for i in range(10) ]), self.graph.get_neighbors(self.actor)) self.assertEqual( set([Actor(str(i), i, 'https://' + str(i)) for i in range(10)]), self.graph.get_neighbors(self.movie))
def setUp(self): self.movie = Movie("Movie", 100000, 1980, 'https://Testing') self.actor = Actor("Actor", 24, 'https://MoreTesting') self.graph = Graph() self.graph.add_vertex(self.movie) self.graph.add_vertex(self.actor) for i in range(10): self.graph.add_vertex(Actor(str(i), i, 'https://' + str(i))) for i in range(10): self.graph.add_vertex( Movie(str(i), i, i * 100, 'https://' + str(i))) for i in range(10): self.graph.add_edge(self.movie, Actor(str(i), i, 'https://' + str(i)), 0) self.graph.add_edge(self.actor, Movie(str(i), i, i * 100, 'https://' + str(i)), 0) self.graph.add_edge(Actor(str(i), i, 'https://' + str(i)), Movie(str(i), i, i * 100, 'https://' + str(i)), 0)
def test_make_actor(self): self.app.post('/actors', data=flask.json.dumps({"name": "actor6", "age": 6, "total_gross": 6}), content_type="application/json") assert am_graph.is_vertex(Actor("actor6", 6, 6))
def setUp(self): self.actor1 = Actor("Test1", 24, 45) self.actor2 = Actor("Test2", 32, 55)
def test_eq(self): self.assertEqual(Actor("Test1", 24, 45), self.actor1) self.assertNotEqual(self.actor1, self.actor2)
def test_get_weight(self): self.assertEqual( 0, self.graph.get_weight(self.movie, Actor(str(1), 1, 'https://' + str(1))))
def make_actor(): actor = Actor(request.json.get('name'), request.json.get('age'), request.json.get('total_gross')) am_graph.add_vertex(actor) return make_response(jsonify(parser.actors_to_dict()), 201)